Skip to main content

Visual predictive check of a fit’s continuous observations

Description

Simulates n_sim replicates of the fit’s design at its estimates and hands them, with the fit’s own observations, to vpc::vpc(). With pred_corr = TRUE the result is a prediction-corrected VPC (pcVPC). Binning, the prediction intervals and the plot are the vpcpackage’s; ferx_vpc() only decides which rows go in.

Usage

ferx_vpc(
  fit,
  n_sim = 200L,
  seed = 42L,
  pred_corr = FALSE,
  cmt = NULL,
  stratify = NULL,
  lloq = NULL,
  uloq = NULL,
  horizon = NULL,
  idv = "TIME",
  ...
)

Arguments

  • fit: A ferx_fit from [ferx_fit](ferx_fit.qmd)() or [ferx_load_fit](ferx_load_fit.qmd)(). Its model and data files are re-read for the simulation.
  • n_sim: Number of simulated replicates.
  • seed: Random seed for the simulation (a non-negative integer).
  • pred_corr: TRUE for a prediction-corrected VPC.
  • cmt: The continuous endpoint’s compartment. Required when the fit has more than one, unless stratify includes "CMT", which shows every continuous endpoint, one stratum each.
  • stratify: Optional character vector of data columns to stratify by (read from the fit’s data file, observation records), or "CMT". Passed to vpc::vpc().
  • lloq, uloq: Lower / upper limit of quantification; at most one. With both NULL, each is taken from the fit’s CENS = 1 / CENS = -1 rows.
  • horizon: Administrative horizon for the simulation; required by a joint PK-TTE model (see [ferx_simulate](ferx_simulate.qmd)()).
  • idv: The x axis: the name of a numeric column of fit$sdtab, such as "TIME" (the default), "TAD" or "TAFD". Not "ID", "DV" or "PRED", nor a stratify column.
  • ...: Further arguments to vpc::vpc(), for example bins, n_bins, pi, ci, log_y, pred_corr_lower_bnd, xlab or vpcdb = TRUE. The arguments ferx_vpc() builds itself (sim, obs, sim_cols, obs_cols, psn_folder, software) are refused.

Details

The observations are the continuous (Gaussian) rows of fit$sdtab: the records the fit used, after any [data_selection] block and with its PRED. The simulation ([ferx_simulate](ferx_simulate.qmd)(..., fit = fit)) covers the whole data file, so each replicate is matched to those observations by compartment, subject, time and, for repeated times, the order within them - never by position. Simulated records the fit did not use (for example the rows a [data_selection]``ignore rule dropped) are left out, and every simulated row carries the PRED of the observation it matches, which is what the pcVPC needs. If a replicate does not match every observation exactly once the call is refused. Censoring. An observation with CENS = 1 (below the LLOQ) or CENS = -1 (above the ULOQ) carries the limit, not a measurement, in DV; ferx_vpc() hands it to vpc as a value past the limit (lloq - |lloq| - 1, so -1 for a positive LLOQ, and uloq + |uloq| + 1), which vpccounts as censored in the observed percentiles and does not plot. (Not as NA: vpc 1.3.5 and later remove a missing value instead of counting it.) lloq defaults to the DV of the CENS = 1 rows and uloq to that of the CENS = -1 rows; vpc takes one limit, so several values are refused unless you pass lloq = / uloq =. It also takes only one of the two, and counts every censored observation past that one limit. So a fit censored on both sides is refused, as is a limit on the other side from the fit’s censoring (uloq = on a fit with CENS = 1 rows, or lloq = with CENS = -1 rows). vpc draws the limit. A prediction-corrected VPC with a limit needs vpc 1.2.9 or later; older versions censor the simulated values at it and then fail on them, so with those it is refused and pred_corr = FALSE is the way to show such a fit. Time after dose.idv picks the x axis: any numeric column of fit$sdtab, such as "TAD" (time after the most recent dose, steady-state aware) or "TAFD" (time after the first dose). A simulated row takes the value of the observation it matches, so the observed and simulated rows sit at the same x. Against TAD, vpc bins every dose together; when those doses differ (first dose and steady state, or several dose levels) use pred_corr = TRUE, or stratify = "OCC" for one panel per occasion. An observation with no value (TAD is NaN before a subject’s first dose) has no place on the axis: it is left out of the observed and the simulated rows, with a warning of class ferx_vpc_idv_dropped. The sdtab’s TAD counts a dose at the observation’s own time as the most recent one, whatever the record order, so a pre-dose sample at a dose time reads TAD 0, or just below it (ferx-core #3422). Several endpoints. A fit with more than one continuous endpoint (CMT values in fit$sdtab) needs cmt =. A time-to-event endpoint has its own VPC, [ferx_vpc_tte](ferx_vpc_tte.qmd)(); a joint PK-TTE fit’s simulation needs horizon =, even though only the continuous endpoint is shown here.

Seealso

[ferx_simulate](ferx_simulate.qmd), [ferx_vpc_tte](ferx_vpc_tte.qmd), [ferx_contrast_vpc](ferx_contrast_vpc.qmd)Other simulation: [ferx_calc_npde](ferx_calc_npde.qmd), [ferx_contrast_vpc](ferx_contrast_vpc.qmd), [ferx_predict](ferx_predict.qmd), [ferx_predict_survival](ferx_predict_survival.qmd), [ferx_sim_parameters](ferx_sim_parameters.qmd), [ferx_simulate](ferx_simulate.qmd), [ferx_simulate_adaptive](ferx_simulate_adaptive.qmd), [ferx_simulate_with_uncertainty](ferx_simulate_with_uncertainty.qmd), [ferx_vpc_cif](ferx_vpc_cif.qmd), [ferx_vpc_kmmc](ferx_vpc_kmmc.qmd), [ferx_vpc_tte](ferx_vpc_tte.qmd)

Concept

simulation

Value

What vpc::vpc() returns: a ggplot object, or with vpcdb = TRUE its data (obs and sim with vpc’s column names, the idv column - TIME by default - as idv).

Examples

if (requireNamespace("vpc", quietly = TRUE)) {
  ex <- ferx_example("warfarin")
  fit <- ferx_fit(ex$model, ex$data, verbose = FALSE)
  ferx_vpc(fit, n_sim = 100)
  ferx_vpc(fit, n_sim = 100, pred_corr = TRUE)

  # Multiple doses: against time after dose, one panel per occasion
  ex <- ferx_example("warfarin_iov")
  fit <- ferx_fit(ex$model, ex$data, verbose = FALSE)
  ferx_vpc(fit, n_sim = 100, idv = "TAD", stratify = "OCC")
}