Kaplan-Meier mean covariate VPC for a time-to-event model
Description
Checks whether a single-event time-to-event (TTE) model captures how a baseline covariate drives the hazard (Hooker and Karlsson, PAGE 21 (2012) Abstr 2564). At every step of the Kaplan-Meier curve it takes the mean of the covariate over the subjects still at risk, in the data and in each of n_sim replicates of the observed design, and returns the observed curve beside the pointwise band of the replicate curves, per stratum. Everything is computed by ferx-core (vpc_kmmc(), ferx-core #1886); this function only carries the result into R. It never refits.
Usage
ferx_vpc_kmmc(
model,
data = NULL,
covariate,
level = NULL,
min_at_risk = 10L,
n_sim = 200L,
seed = 42L,
fit = NULL,
strata = NULL,
by_dose = FALSE,
censoring = c("observed", "horizon"),
cmt = NULL,
horizon = NULL,
probs = c(0.05, 0.5, 0.95),
grid = "auto",
selection = c("all", "fit")
)Arguments
model: Path to a .ferx model file with an[event_model]endpoint.data: Path to a NONMEM-format CSV, or a data.frame, holding the observed TTE records (DV = 1event,DV = 0right-censored), one per subject on the endpoint. When omitted, the datafitwas fitted to, otherwise the model file’s[data]block.covariate: The baseline covariate whose at-risk mean is taken: each subject’s first non-missing value.level:NULL(default) for the arithmetic mean (for a 0/1 covariate, the share coded 1), or one value: the curve is then the share of at-risk subjects at exactly that value, for a multi-level code whose mean means nothing.min_at_risk: A curve is undefined where fewer subjects than this are at risk; applied to the observed curve and to each replicate on its own.n_sim: Number of simulated replicates; at least 20 for the defaultprobs.seed: Random seed for the replicates and the censoring draws.fit: Optionalferx_fitresult. 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:TRUEto stratify by the amount of each subject’s first dose instead (0 for a subject with no dose). Cannot be combined withstrata.censoring:"observed"(default) or"horizon"; see the section above.cmt: The TTE endpoint’s compartment. Required when the model has more than one TTE endpoint;NULLtakes the only one.horizon: The time the replicates are simulated to.NULL(default) is the latest time recorded on the endpoint.probs: Three band probabilities, strictly increasing inside (0, 1): the lower bound, the middle line and the upper bound.grid: The times the band is evaluated at:"auto"(0, the stratum’s observed times and 101 evenly spaced points up toH),"all_steps"(also every step of every replicate curve: exact step ribbons, on a large grid), or a numeric vector of times.selection: Which records ofdataare read, whenfitis given:"all": (default) every record indata, whatever data selection the fit was made with - what this function has always done."fit": the data asfitread them: the fit’s own data selection (fit$reader_settings: the model file’s[data_selection]and anyferx_fit(ignore =, accept =, ignore_ids =)), applied to every record it removed, doses included, and the fit’s skip of a record with an emptyDV. On the fit’s own model and data (its files; for the model also a file whose bytes still hash tofit$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 arefit$sdtab’s, in order, and a survival prediction or a VPC covers the fit’s subjects. They are checked againstfit$population_fingerprint, so a data file edited since the fit is refused with codeE_POPULATION_MISMATCH. On another model file only the fit’s selection is replayed, and on another data file nothing is checked. Needsfit.A fit made before the selection was recorded is refused under"fit"when itsfit$exclusionsshow 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 sameseed, removing records moves the random stream, so"fit"is not"all"with some rows dropped.
Reading it
A covariate that raises the hazard makes its at-risk mean drift as the high-hazard subjects leave the risk set. A model that lacks the effect drifts too little, and the observed curve leaves the band. Every replicate keeps the data’s covariates, so the curves differ only in who stays at risk: at time 0 the observed value and the whole band are the population mean, and the signal is the gap that opens later.
Censoring in the replicates
Under censoring = "observed" every replicate subject draws its censoring time from its own stratum’s reverse Kaplan-Meier censoring distribution, unconditionally. Unlike [ferx_vpc_tte](ferx_vpc_tte.qmd), a subject observed censored does not keep its own time: censored subjects are selected for a low hazard, so keeping their times would remove the same covariate values at the same times in every replicate as in the data, and the band would hug the observed curve. The draw assumes censoring is independent of the covariate within a stratum, so stratify on what drives dropout. The observed records are read on [0, H] only.
What it refuses
Every input [ferx_vpc_tte](ferx_vpc_tte.qmd) refuses, as an R error of class ferx_engine_error with e$code == "E_VPC_TTE_INPUT", and also: a repeated-events endpoint (use [ferx_vpc_tte](ferx_vpc_tte.qmd), which draws its RTTE VPC); a subject on the endpoint that lacks the covariate or whose baseline value is missing; a level no such subject has; and stratifying on the covariate itself. A covariate that changes within a subject uses each subject’s first value, with a W_VPC_KMMC_TIME_VARYING_COVARIATE warning.
Seealso
[plot.ferx_vpc_kmmc](plot.ferx_vpc_kmmc.qmd), [ferx_vpc_tte](ferx_vpc_tte.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_cif](ferx_vpc_cif.qmd), [ferx_vpc_tte](ferx_vpc_tte.qmd)
Concept
simulation
Value
An object of class ferx_vpc_kmmc, a list with:
observed: The observed curve, one row per row of each stratum’s Kaplan-Meier curve:STRATUM,time,n_risk,n_event,n_censorandmean, the covariate’s mean (or share atlevel) over then_risksubjects at risk attime(event or censoring time \(\ge\)time). The curve is left-continuous: a row’s value holds from the previous row’s time up to and including its own.band: The replicate band, one row per grid time per stratum:STRATUM,time,obs(the observed curve attime;NAwhere fewer thanmin_at_risksubjects are at risk),lo,med,hiandn_used.strata: One row per stratum, as in[ferx_vpc_tte](ferx_vpc_tte.qmd).covariate,level,min_at_risk,cmt,horizon,n_sim,probs,censoring: The settings used and the horizonH.warnings: The engine’s warnings, also raised as an R warning.
Examples
ex <- ferx_example("tte_weibull")
d <- utils::read.csv(ex$data)
d$WT <- 50 + 3 * (d$ID %% 10)
kv <- ferx_vpc_kmmc(ex$model, d, covariate = "WT", n_sim = 50L, seed = 1L)
kv
plot(kv)