ronkeizer / vpc

R library to create visual predictive checks (VPC)
Other
36 stars 20 forks source link

Generating pred_corr vpc fails #96

Closed SybrandZielhuis closed 5 months ago

SybrandZielhuis commented 6 months ago

Hi,

I'm trying to generate a prediction corrected vpc but I keep getting the same error:

Error in dplyr::group_by(): ! Must group by variables found in .data. ✖ Column sim is not found.

Backtrace: ▆

  1. ├─vpc::vpc(...)
  2. ├─vpc:::vpc.default(...)
  3. │ └─base::do.call(...)
  4. ├─vpc (local) <fn>(...)
  5. │ └─vpc:::calc_vpc_continuous(...)
  6. │ └─sim %>% dplyr::group_by(strat, sim, bin) %>% ...
  7. ├─dplyr::summarise(...)
  8. ├─dplyr::group_by(., strat, sim, bin)
  9. └─dplyr:::group_by.data.frame(., strat, sim, bin)
    1. └─dplyr::group_by_prepare(.data, ..., .add = .add, error_call = current_env())
    2. └─rlang::abort(bullets, call = error_call)

This is the code I used: vpc(sim = sim2, obs = obs, sim_cols = list(dv = "DV", sim = "REP"), obs_cols = list(dv = "DV"), show = list(obs_dv = TRUE, obs_ci = TRUE, pi_as_area = FALSE, sim_median_ci = TRUE, pi = FALSE), log_y = FALSE, xlab = "Time (hours)", # Label of the x-axis ylab = "Concentration (ng/ml)", # Label of the y-axis title = "VPC of a single administration of 20 mg of lenvatinib ", scales = "free", pi = c(0.05, 0.95), # prediction interval simulated data to show ci = c(0.05, 0.95), n_bins = "auto", pred_corr = TRUE, pred_corr_lower_bnd = 0, smooth = FALSE, verbose = FALSE )

Sim2 and obs are the following:

head(obs) ID MDV TIME DV PRED 1 1 1 0.0 0.000 0.00 2 1 0 0.5 59.068 159.26 3 1 0 1.0 91.238 237.15 4 1 0 2.0 110.390 273.85 5 1 0 4.0 86.097 212.98 6 1 0 8.0 35.691 105.85 head(sim2) ID MDV TIME DV PRED REP 1 1 1 0 0 0 1 2 1 0 0.5 173. 159. 1 3 1 0 1 314. 237. 1 4 1 0 2 854. 274. 1 5 1 0 4 505. 213. 1 6 1 0 8 95.9 106. 1

Does anyone know what I am doing wrong?

Kind regards, Sybrand

roninsightrx commented 5 months ago

hi Sybrand, thanks for posting the issue. This behavior was due to a bug in the code for pred-correction. I've just made a fix that should address this, and merged it into the master branch. Please re-install package from Github (remotes::install_github("ronkeizer/vpc")) and try again. best, Ron