Genentech / psborrow2

psborrow2: Bayesian Dynamic Borrowing Simulation Study and Analysis
https://genentech.github.io/psborrow2/
Other
16 stars 2 forks source link

Rows of NA in data simulation #293

Closed mattsecrest closed 5 months ago

mattsecrest commented 5 months ago

Behavior A bunch of rows of NA in data simulation.

Reprex

devtools::load_all()
my_baseline <- create_baseline_object(
   n_trt_int = 50, 
   n_ctrl_int = 50,
   n_ctrl_ext = 50,
   covariates = baseline_covariates(
      names = c("age", "score"),
      means_int = c(55, 5),
      means_ext = c(55, 20),
      covariance_int = covariance_matrix(diag = c(5, 1)),
      covariance_ext = covariance_matrix(diag = c(2,1))
   )
)

my_data_sim <- create_data_simulation(
   baseline = my_baseline,
   coefficients =  c(age = 0.0001, score = 1.1),
   event_dist = create_event_dist(dist = "exponential", lambdas = 1/50)
) |>
   set_cut_off(
      internal = cut_off_after_first(time = 60),
      external = cut_off_after_events(n = 100)
   )

set.seed(123)
df <- generate(my_data_sim, n = 1)@data_list[[1]][[1]] |>
 as.data.frame()

df |>
   dplyr::count(trt)
  trt  n
1   0 50
2   1 50
3  NA 50

Possible issue

cut_off_after_events I think is causing this. When the above is replaced with the below, it works:

   set_cut_off(
      internal = cut_off_after_first(time = 60),
      external = cut_off_after_first(time = 60),
   )