Skip to main content

Cumulative-incidence visual predictive check for competing risks

Description

Simulates the observed design n_sim times and returns, per stratum, the observed Aalen-Johansen cumulative incidence of every cause and the observed all-cause Kaplan-Meier curve, each beside the pointwise band of the same curve over the replicates. Every time-to-event (TTE) endpoint of the model is a cause. Everything is computed by ferx-core (vpc_cif(), ferx-core #1887); this function only carries the result into R. It never refits.

Usage

ferx_vpc_cif(
  model,
  data = NULL,
  n_sim = 200L,
  seed = 42L,
  fit = NULL,
  strata = NULL,
  by_dose = FALSE,
  censoring = c("observed", "horizon"),
  horizon = NULL,
  probs = c(0.05, 0.5, 0.95),
  grid = "auto",
  selection = c("all", "fit")
)

Arguments

  • model: Path to a .ferx model file whose [event_model] endpoints are the competing causes.
  • data: Path to a NONMEM-format CSV, or a data.frame, holding the observed records: per subject one row on every cause’s CMT, at the same time, DV = 1 on the cause that occurred (if any) and DV = 0 on the others. When omitted, the data fit was fitted to, otherwise the model file’s [data] block.
  • n_sim: Number of simulated replicates; at least 20 for the default probs.
  • seed: Random seed for the replicates and the censoring draws.
  • fit: Optional ferx_fit result. When given, the replicates are simulated at the fitted parameters, as in [ferx_simulate](ferx_simulate.qmd); otherwise at the model file’s initial values.
  • strata: NULL (one stratum, "all") or the name of a covariate: subjects are grouped by its exact value at their first record.
  • by_dose: TRUE to stratify by the amount of each subject’s first dose instead (0 for a subject with no dose). Cannot be combined with strata.
  • censoring: "observed" (default) or "horizon"; see the section above.
  • horizon: The time the replicates are simulated to. NULL (default) is the latest time recorded on a cause.
  • probs: Three band probabilities, strictly increasing inside (0, 1): the lower bound, the middle line and the upper bound.
  • grid: The times the bands are evaluated at: "auto" (0, the stratum’s observed all-cause times and 101 evenly spaced points up to H), "all_steps" (also every step of every replicate curve), or a numeric vector of times.
  • selection: Which records of data are read, when fit is given:
  • "all": (default) every record in data, whatever data selection the fit was made with - what this function has always done.
  • "fit": the data as fit read them: the fit’s own data selection (fit$reader_settings: the model file’s [data_selection] and any ferx_fit(ignore =, accept =, ignore_ids =)), applied to every record it removed, doses included, and the fit’s skip of a record with an empty DV. On the fit’s own model and data (its files; for the model also a file whose bytes still hash to fit$model_hash, such as the original of a fit reloaded with [ferx_load_fit](ferx_load_fit.qmd)) the rows are the ones the fit was scored on: the continuous (Gaussian) observation rows of a simulation or prediction are fit$sdtab’s, in order, and a survival prediction or a VPC covers the fit’s subjects. They are checked against fit$population_fingerprint, so a data file edited since the fit is refused with code E_POPULATION_MISMATCH. On another model file only the fit’s selection is replayed, and on another data file nothing is checked. Needs fit.A fit made before the selection was recorded is refused under "fit" when its fit$exclusions show a clause its model file does not state. For a simulation the two are different runs, not one and a filter of it: with the same seed, removing records moves the random stream, so "fit" is not "all" with some rows dropped.

Why not one Kaplan-Meier VPC per cause

One minus the Kaplan-Meier curve of one cause, with the other causes as censorings, is not that cause’s cumulative incidence: it estimates the incidence in a world without the other causes, and overstates it. And the all-cause curve cannot see a model that swaps the causes’ rates while keeping their sum; the cumulative incidences can. So [ferx_vpc_tte](ferx_vpc_tte.qmd) refuses a model with several TTE endpoints unless cmt names one, and this function draws all of them.

The data

Every TTE endpoint must be single-event. A subject with any cause record needs exactly one record on every cause, all at the same time (its first event or its censoring), with at most one of them an event (DV = 1); the other causes are DV = 0 there. That is the layout of ferx_example("tte_competing_risks"). The simulator competes only the causes a subject has records on, so a subject with fewer would be simulated under fewer causes than the data imply. A model with one TTE endpoint is accepted: its cumulative incidence is one minus the Kaplan-Meier curve of [ferx_vpc_tte](ferx_vpc_tte.qmd).

The curves and the bands

The observed curves match survival::survfit’s multi-state fit (Surv(time, factor(status)) with the censoring as the first level) row for row: surv is the all-cause Kaplan-Meier curve, and each cif_<cmt> column the probability of having had that cause by time. At every time the observed cumulative incidences and surv add up to 1, but the band medians (or limits) of the causes and of the survival need not: each band is pointwise, over the replicates still under follow-up at that time, as in [ferx_vpc_tte](ferx_vpc_tte.qmd).

Censoring in the replicates

As in [ferx_vpc_tte](ferx_vpc_tte.qmd), on the all-cause time: under censoring = "observed" a subject observed censored on every cause keeps its own time, and a subject with an event draws a censoring time from its stratum’s reverse Kaplan-Meier curve given that it exceeds the event time; a replicate’s first event past its censoring time becomes a censoring there. "horizon" censors every replicate at H only. The observed records are read on [0, H] only.

What it refuses

An input the curves would be wrong on is an R error of class ferx_engine_error with e$code == "E_VPC_TTE_INPUT": a model without a TTE endpoint; a repeated-events endpoint (use [ferx_vpc_tte](ferx_vpc_tte.qmd), which draws its RTTE VPC); a subject with records on some causes but not on all, more than one record on a cause, cause records at different times, or events on two causes; left truncation; an interval-censored record; a duplicated subject id; no record on any cause; and the band, grid and stratification inputs [ferx_vpc_tte](ferx_vpc_tte.qmd) refuses.

Seealso

[plot.ferx_vpc_cif](plot.ferx_vpc_cif.qmd), [ferx_vpc_tte](ferx_vpc_tte.qmd), [ferx_predict_survival](ferx_predict_survival.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](ferx_vpc.qmd), [ferx_vpc_kmmc](ferx_vpc_kmmc.qmd), [ferx_vpc_tte](ferx_vpc_tte.qmd)

Concept

simulation

Value

An object of class ferx_vpc_cif, a list with:

  • observed: The observed curves, one row per row of each stratum’s all-cause Kaplan-Meier curve: STRATUM, time, n_risk, n_event (of any cause), n_censor, surv (all-cause survival), then per cause cif_<cmt> (its cumulative incidence just after time) and n_event_<cmt> (its events at time), in cmts order.
  • band: The causes’ bands, one row per cause per grid time per stratum: STRATUM, cmt, time, obs (the observed cumulative incidence at time; NA past the observed curve’s last time), lo, med, hi (the band at probs; NA where too few replicates are still under follow-up) and n_used, the number of replicate curves defined there.
  • survival_band: The all-cause survival band, laid out as band without cmt.
  • strata: One row per stratum, as in [ferx_vpc_tte](ferx_vpc_tte.qmd).
  • cmts: The causes’ compartments, ascending.
  • horizon, n_sim, probs, censoring: The horizon H the replicates were simulated to, and the settings used.
  • warnings: The simulator’s diagnostics and the data reader’s, also raised as an R warning.

Examples

ex <- ferx_example("tte_competing_risks")
cv <- ferx_vpc_cif(ex$model, ex$data, n_sim = 50L, seed = 1L)
cv
head(cv$observed)
plot(cv)
plot(cv, survival = TRUE)