This vignette explains how
cifmodeling interprets time-to-event data and processes
them in its main functions. Use it to check input conventions, review
computational steps, or investigate unexpected results. For analysis
examples, see the worked examples; for
statistical formulas, see Computational
formulas in cifcurve().
The main functions use a formula-and-data interface, but the formula’s right-hand side serves different purposes in curve estimation and regression.
| Function | Formula | Role of other arguments |
|---|---|---|
cifcurve() |
Event(time, status) ~ group |
Estimates separate curves by group;
optional case weights are supplied through weights. |
ciftest() |
Event(time, status) ~ group |
Compares groups; test selects the test and
optional case weights are supplied separately. |
polyreg() |
nuisance.model = Event(time, status) ~ age + sex |
Models the non-exposure part of the outcome
distribution; exposure = "arm" names the exposure whose
effect is estimated, while strata specifies
censoring-estimation strata. |
The right-hand-side group defines curve
groups in cifcurve() and comparison
groups in ciftest(). Within
ciftest(), strata defines analysis
strata, while strata.censor and
strata.competing.risk specify censoring
strata and working-AJ strata,
respectively.
The response may be specified with Event() or a
supported right-censored survival::Surv() object. Binomial
models use a standard response formula. The event coding must agree with
the chosen code.event1, code.event2, and
code.censoring arguments. In particular,
polyreg() does not put the exposure in
nuisance.model; it is supplied separately. The nuisance
component describes part of the outcome probability structure; its
covariates may also be used for confounding adjustment. It is not a
propensity-score model.
The supported outcome types also differ by function:
| Function | Outcome types | Time-point requirement |
|---|---|---|
cifcurve() |
"survival",
"competing-risk" |
Curves are estimated over follow-up; no fixed evaluation time is required. |
ciftest() |
"survival",
"competing-risk" |
Tests use follow-up information; an analysis horizon
may be set using tau. |
polyreg() |
"survival", "competing-risk",
"binomial", "proportional-survival",
"proportional-competing-risk" |
time.point is required for fixed-time
survival and competing-risk models. Models with time-constant effect
parameters can use observed event times or a supplied grid. |
The following calls estimate a curve by fruit-intake group and an age- and sex-adjusted risk ratio at eight years:
library(cifmodeling)
data(diabetes.complications)
curve <- cifcurve(
Event(t, epsilon) ~ fruitq1,
data = diabetes.complications,
outcome.type = "competing-risk"
)
fit <- polyreg(
nuisance.model = Event(t, epsilon) ~ age + sex,
exposure = "fruitq1",
data = diabetes.complications,
outcome.type = "competing-risk",
effect.measure1 = "RR",
effect.measure2 = "RR",
time.point = 8
)In cifcurve(), outcome.type = NULL
determines the outcome type from the observed event codes. For
descriptive CIF estimation, specify
outcome.type = "competing-risk" explicitly if an event
category is absent from an analysis subset. In contrast,
polyreg() defaults to "competing-risk", and
its fixed-time competing-risk model requires both event types to
have been observed by time.point. Explicitly
selecting the outcome type does not remove this requirement. See Direct polytomous regression for the model
and its effect measures.
Event and censoring codes differ across datasets. Check the meaning of the status variable before fitting a model.
| Data convention | Event | Censoring |
|---|---|---|
Common Surv() convention |
1 |
0 |
Binary ADaM ADTTE CNSR |
0 |
1 |
For an ADTTE dataset, AVAL is typically the analysis
time and CNSR = 0 indicates an observed event. If
CNSR is coded 0/1, use Event() with explicit
event and censoring codes without reversing the values:
# Illustrative ADTTE dataset: AVAL, CNSR, and ARM are its columns.
curve_adtte <- cifcurve(
Event(AVAL, CNSR) ~ ARM,
data = adtte,
outcome.type = "survival",
code.event1 = 0,
code.censoring = 1
)
fit_adtte <- polyreg(
nuisance.model = Event(AVAL, CNSR) ~ 1,
exposure = "ARM",
data = adtte,
outcome.type = "survival",
time.point = 12, # Adapt to the endpoint's time unit.
code.event1 = 0,
code.censoring = 1,
code.exposure.ref = "Placebo" # Replace with an observed ARM level.
)Do not pass an unrecoded ADTTE CNSR variable directly to
Surv(AVAL, CNSR): Surv() ordinarily interprets
0 as censoring. Some ADTTE datasets use multiple positive
CNSR codes for different censoring reasons. Check the
dataset’s metadata and, if necessary, recode them to a single censoring
status.
Competing-risk analyses require a status variable that
distinguishes the primary event, competing event, and
censoring. A binary CNSR flag alone cannot
identify which type of event occurred. For example, the usual
cifmodeling codes are 1 (primary event), 2 (competing
event), and 0 (censoring), but other distinct codes can be specified
explicitly.
cifcurve() computes estimatesThe cifcurve() workflow has four stages:
util_read_surv()
interprets the formula, checks time and event variables, and collects
group and weight information.error
argument selects the variance method, conf.type the
confidence-interval transformation, and conf.dist the
normal or Student reference distribution. For Student intervals,
df.method controls the working degrees of freedom.survfit-compatible object containing curves, uncertainty
estimates, and available inference diagnostics.For competing risks, one output convention is particularly important:
$surv contains 1 - CIF for the
selected event, not the CIF itself. The plotting and reporting
methods account for this convention. Also, n.risk.type
controls how risk-set counts are displayed; it does not change
the curve estimate or its standard error.
The default engine is "calculateAJ_Rcpp". The older
"calculateKM" engine supports a narrower set of
normal-reference variance methods. For IF-based and Fay–Graubard-type
intervals, see the formulas vignette.
Important limitation: weights supplied to
cifcurve() are treated as fixed. If they were estimated
externally (for example, propensity-score weights), the reported
variance does not include uncertainty from estimating the weight
model.
polyreg() fits a modelpolyreg() estimates exposure effects on the selected
effect-measure scale and uses a nuisance model to maintain coherent
cause-specific CIFs. Its computation has five stages:
strata argument defines censoring-estimation
strata; it is different from the covariates in
nuisance.model.data.initial.values.
Numerical solvers then iteratively solve the estimating equations.report.*.conf arguments control optional intervals.coef(), vcov(), summary(), and
generics::tidy() to extract results. Additional diagnostic
information includes fitted quantities, weights, and influence-function
contributions when available.The underlying workflow uses helpers including
createAnalysisDataset(), calculateIPCW(),
getInitialValues() (or
getInitialValuesProportional()), and
solveEstimatingEquation(). These are internal
implementation steps; users do not normally call the helpers
directly.
If a model produces a warning or unexpected result, check the inputs and model specification before changing optimization controls:
code.exposure.ref
explicitly when necessary.report.optim.convergence = TRUE in polyreg().
For an unstable fit, consider a simpler nuisance model, fewer evaluation
times for models with time-constant effect parameters, or alternative
starting values.optim.parameter1 and optim.parameter2 control
convergence tolerances; other optim.parameter* arguments
control parameter bounds and solver behavior. Record any changes when
reporting an analysis.boot.seed and report the number of replications
(boot.replications).A convergence flag does not, by itself, establish that the model is suitable for the data. Also check for sparse events, limited follow-up, and extreme censoring weights.
For practical analyses, see Worked
examples. For the mathematical basis of the curve estimators and
confidence intervals, see Computational
formulas in cifcurve(). For tables and file exports,
see Reporting results. Complete
function arguments are collected in the function reference.