Skip to content

Commit

Permalink
Added test file for func_MCMC_graph_cpp() (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
wleoncio committed Jun 21, 2024
1 parent aa484f6 commit 7042b5c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/testthat/test-func_MCMC_graph_cpp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Load the example dataset
dataset <- list(
"X" = simData[[1]]$X,
"t" = simData[[1]]$time,
"di" = simData[[1]]$status
)

# Run a Bayesian Cox model

## Initial value: null model without covariates
initial <- list("gamma.ini" = rep(0, ncol(dataset$X)))

# Prior parameters
hyperparPooled <- list(
"c0" = 2, # prior of baseline hazard
"tau" = 0.0375, # sd (spike) for coefficient prior
"cb" = 20, # sd (slab) for coefficient prior
"pi.ga" = 0.02, # prior variable selection probability for standard Cox models
"a" = -4, # hyperparameter in MRF prior
"b" = 0.1, # hyperparameter in MRF prior
"G" = simData$G, # hyperparameter in MRF prior
"lambda" = 3,
"nu0" = 0.05,
"nu1" = 5
)

# Run a 'Pooled' Bayesian Cox model with graphical learning

set.seed(3346141)
BayesSurvive_wrap <- function(use_cpp = FALSE) {
BayesSurvive(
survObj = list(dataset), model.type = "Pooled", MRF.G = FALSE,
hyperpar = hyperparPooled, initial = initial, nIter = 3,
verbose = TRUE, cpp = use_cpp
)
}
fit_R <- BayesSurvive_wrap(use_cpp = FALSE)
fit_C <- BayesSurvive_wrap(use_cpp = TRUE)

0 comments on commit 7042b5c

Please sign in to comment.