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

Numerical reproducibility issues #420

Closed
tobiasmuetze opened this issue Aug 22, 2024 · 3 comments
Closed

Numerical reproducibility issues #420

tobiasmuetze opened this issue Aug 22, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@tobiasmuetze
Copy link

Describe the bug
We are experiencing reproducibility issues when method_bayes() is used even when all the conditions for reproducibility outlined in the stan manual are fulfilled.
Our understanding is that the cause for this is the starting value for the MCMC are the REML parameter estimates that are obtained using the R package mmrm. We have observed that the model files from the R package mmrm are not numerically reproducible; see corresponding mmrm issue.
We have reproduced this issue on rbmi versions 1.2.3 and 1.2.6. We haven't observed this issue in v1.1.3, i.e., prior to the switch to the R package mmrm.
This is joint work with @luwidmer and @bailliem.

To Reproduce

We have used the code from the vignette to generate the issue.

library(rbmi)
library(tidyverse)

data("antidepressant_data")
dat <- antidepressant_data

# Use expand_locf to add rows corresponding to visits with missing outcomes to the dataset
dat <- expand_locf(
  dat,
  PATIENT = levels(dat$PATIENT), # expand by PATIENT and VISIT 
  VISIT = levels(dat$VISIT),
  vars = c("BASVAL", "THERAPY"), # fill with LOCF BASVAL and THERAPY
  group = c("PATIENT"),
  order = c("PATIENT", "VISIT")
)

# create data_ice and set the imputation strategy to JR for
# each patient with at least one missing observation
dat_ice <- dat %>% 
  arrange(PATIENT, VISIT) %>% 
  filter(is.na(CHANGE)) %>% 
  group_by(PATIENT) %>% 
  slice(1) %>%
  ungroup() %>% 
  select(PATIENT, VISIT) %>% 
  mutate(strategy = "JR")

vars <- set_vars(
  outcome = "CHANGE",
  visit = "VISIT",
  subjid = "PATIENT",
  group = "THERAPY",
  covariates = c("BASVAL*VISIT", "THERAPY*VISIT")
)

# Define which imputation method to use (here: Bayesian multiple imputation with 150 imputed datsets) 
method <- method_bayes(
  burn_in = 200,
  burn_between = 5,
  n_samples = 150,
  seed = 675442751
)

# Create samples for the imputation parameters by running the draws() function
seed <- 987
set.seed(seed)
# seed <- NULL
drawObj <- draws(
  data = dat,
  data_ice = dat_ice,
  vars = vars,
  method = method,
  quiet = TRUE
)

imputeObj <- impute(
  drawObj,
  references = c("DRUG" = "PLACEBO", 
                 "PLACEBO" = "PLACEBO")
)
imputeObj



anaObj <- analyse(
  imputations = imputeObj,
  fun = ancova,
  vars = set_vars(
    subjid = "PATIENT",
    outcome = "CHANGE",
    visit = "VISIT",
    group = "THERAPY",
    covariates = c("BASVAL")
  )
)

poolObj <- pool(
  anaObj, 
  conf.level = 0.95, 
  alternative = "two.sided"
)

Environment:

  • Platform: x86_64-pc-linux-gnu (64-bit)
  • R version 4.3.1
  • rbmi version 1.2.3
@tobiasmuetze tobiasmuetze added the bug Something isn't working label Aug 22, 2024
@gowerc
Copy link
Collaborator

gowerc commented Sep 27, 2024

Just to say from our prior conversation that we are pretty confident this is due to the mmrm upstream issue. Once openpharma/mmrm#472 and openpharma/mmrm#462 are resolved this should be fixed.

@gowerc
Copy link
Collaborator

gowerc commented Oct 8, 2024

@tobiasmuetze - Given the up stream fix thats been applied to mmrm I was planning on closing this. Please let me know if you have any outstanding concerns / issues

@gowerc
Copy link
Collaborator

gowerc commented Oct 11, 2024

Please feel free to re-open if this comes up again 😄

@gowerc gowerc closed this as completed Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants