-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test file for
func_MCMC_graph_cpp()
(#11)
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |