Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating an example of BayesSurvive(MRF.G = FALSE) #13

Closed
wleoncio opened this issue Jun 12, 2024 · 5 comments · Fixed by #15
Closed

Creating an example of BayesSurvive(MRF.G = FALSE) #13

wleoncio opened this issue Jun 12, 2024 · 5 comments · Fixed by #15

Comments

@wleoncio
Copy link
Member

wleoncio commented Jun 12, 2024

For #11, I am trying to create an example that triggers func_MCMC_graph(). I've slightly adapted the example for BayesSurvive() as follows:

library("BayesSurvive")
set.seed(123)

# Load the example dataset
data("simData", package = "BayesSurvive")

dataset <- list(
  "X" = simData[[1]]$X,
  "t" = simData[[1]]$time,
  "di" = simData[[1]]$status
)

# Initial value: null model without covariates
initial <- list("gamma.ini" = rep(0, ncol(dataset$X)))
# Hyperparameters
hyperparPooled <- list(
  "c0"     = 2, # prior of baseline hazard
  "tau"    = 0.0375, # sd (spike) for coefficient prior
  "cb"     = 20, # sd (spike) 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
)

# run Bayesian Cox with graph-structured priors
fit <- BayesSurvive(
  survObj = dataset, hyperpar = hyperparPooled, MRF.G = FALSE,
  initial = initial, nIter = 100
)

This creates an "operator invalid for atomic vectors" error on https://github.com/ocbe-uio/BayesSurvive/blob/7ee9d98aaaa5db2556a95c0bf2b53168f8f973bb/R/BayesSurvive.R#L143C1-L143C60 because survObj is, in this case, not a nested list.

This should be straightforward to fix (e.g. by using survObj$X in this particular case), but perhaps this is not a bug and I am just using the wrong dataset. What would you suggest?

@zhizuio
Copy link
Collaborator

zhizuio commented Jun 12, 2024

There is one example in README similar to your case, i.e. "Run a 'Pooled' Bayesian Cox model with graphical learning". There, I specified survObj as a list and added a few more hyperparameters in hyperpar.

I know this is a bit confusing, since I wanted to include quite many methods together via the combinations of 2 arguments i.e. model.type and MRF.G . Note that model.type has only two valid options (model.type="Sub-struct" seems redundant, maybe not? I need to check). Therefore, there should at least 4 combinations for 4 methods, which are the 4 examples in README.

MRF.G = FALSE enables graphical learning for a Markov random field prior (no specified sort of true graph). This requires survObj to be a nested list suitable for one homogeneous group (a list of only one component with model.type= 'Pooled') AND multiple groups (a list of multiple components with model.type= 'CoxBVSSL') of individuals.

MRF.G = TRUE disables graphical learning for a Markov random field prior, instead specifying sort of true graph. The simplest case will be for homogeneous individuals (i.e. no groups of individuals), and then model.type= 'Pooled' and survObj is NOT a nested list. If individuals are divided into multiple groups (of course survObj should be a nested list), we also need to specify a list of multiple true graphs for the hyperparameter hyperpar$G and specify model.type= 'CoxBVSSL'.

Probably we need a better idea to re-structure the combinations of arguments for many methods. As I mentioned, we also wanted to include another method implemented in the R package psbcSpeedUp:-)

@zhizuio
Copy link
Collaborator

zhizuio commented Jun 12, 2024

I have just checked and thought a bit carefully. model.type="Sub-struct" is not redundant! func_MCMC_graph() has two big for-loops. If func_MCMC_graph() is triggered by MRF.G = FALSE, the 1st for-loop inside will be run. If the 2nd for-loop in func_MCMC_graph() is not triggered, it will be model.type="Sub-struct"; otherwise it will be model.type="CoxBVSSL".

Sorry for the confusing structures!

@wleoncio
Copy link
Member Author

Thanks for the clarification! Looks to me like there's no need to modify the code for this, but I wanna get those examples from the README and turn them into unit tests to keep me on track while I work on #11. Sounds good?

@zhizuio
Copy link
Collaborator

zhizuio commented Jun 13, 2024 via email

wleoncio added a commit that referenced this issue Jun 14, 2024
wleoncio added a commit that referenced this issue Jun 20, 2024
wleoncio added a commit that referenced this issue Jun 20, 2024
wleoncio added a commit that referenced this issue Jun 20, 2024
@wleoncio wleoncio changed the title Creating an example of BayesSurvive(MRF.G = TRUE) Creating an example of BayesSurvive(MRF.G = FALSE) Jun 20, 2024
@wleoncio
Copy link
Member Author

85e59f1 says it solves the issue, but that's because I messed up and thought I needed MRF.G = TRUE, but it actually needs to be FALSE for func_MCMC_graph() to be called. So I'll need to work a little bit more on that README.md file before I can issue a PR for this one and then continue working on #11.

wleoncio added a commit that referenced this issue Jun 20, 2024
This is necessary for `func_MCMC_graph()` to be called and work on #11 to continue.
wleoncio added a commit that referenced this issue Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants