How to use this vignette
cifcurve() computes Kaplan–Meier (KM) survival curves
and Aalen–Johansen (AJ) cumulative incidence functions (CIFs), along
with pointwise standard errors and confidence intervals. This vignette
documents how cifcurve() computes its estimates,
variances, and intervals. For analysis workflows and
publication tables, see Worked examples
and Reporting results.
The main arguments control distinct parts of the calculation:
| Argument | What it controls | Options or default |
|---|---|---|
outcome.type |
Estimated probability |
"survival" (KM) or
"competing-risk" (AJ) |
weights |
Case weights | Optional, treated as fixed |
error |
Standard-error calculation | Greenwood/Tsiatis (KM); delta/Aalen (AJ);
"if" or "fay" (both) |
conf.dist |
CI reference distribution |
"normal" (default) or
"t"
|
conf.type |
CI transformation |
"arcsine-square root" (default),
"plain", "log", "log-log",
"logit"
|
df.method |
Working df for Student CIs |
"deletion" (FDF, default) or
"equal" (EDF, IF-t only) |
report.influence.function |
Return empirical IF contributions |
FALSE (default) |
engine |
Computation back end |
"calculateAJ_Rcpp" (default) |
n.risk.type |
Displayed risk-set counts |
"weighted" (default),
"unweighted", or "ess"; estimates
unchanged |
Here, IF denotes influence function and FG denotes Fay–Graubard (not Fine–Gray regression). FDF denotes Fay-type working degrees of freedom, and EDF denotes equal-allocation working degrees of freedom. FDF and EDF describe working-df allocations, not variance corrections.
With unweighted data, error = NULL
selects Greenwood variance for KM and delta-method variance for AJ. When
case weights are supplied, the default is error = "if"; the
available weighted variance methods are "if" and
"fay". Setting conf.dist = "t" without
specifying error also selects "if" and
computes working degrees of freedom. None of error,
conf.dist, conf.type, or
df.method changes the point estimate; they affect its
uncertainty estimates or confidence limits.
For competing-risk outcomes, fit$surv contains
one minus the event-1 CIF, not overall event-free
survival. To obtain CIF confidence limits, complement the stored limits
and reverse their order. All supplied weights, including externally
estimated IPTW, are treated as fixed; uncertainty from
propensity-score estimation is not included. The default C++ engine
handles tied event times and implements the IF and FG calculations
described below.
The sections below cover KM/AJ formulas, the implemented IF and
Fay–Graubard calculations, working degrees of freedom, and
confidence-interval transformations. Weighted Greenwood/Tsiatis formulas
are included for comparison; they are not available as
weighted error options in cifcurve().
Kaplan–Meier estimation and classical variances
For outcome.type = "survival", fit$surv
contains the KM survival estimate. With unweighted data,
error = "greenwood" is the default;
error = "tsiatis" selects the alternative classical
standard error. Let
denote the distinct event times,
the number at risk just before
,
and
the number of events at
.
The KM estimator of
is
Kaplan–Meier estimator
The estimator is right-continuous, so events at contribute to .
For unweighted KM estimates, cifcurve() offers Greenwood
and Tsiatis variance formulas (Tsiatis, 1981). The formulas differ in
their denominators:
Greenwood variance
Tsiatis variance
For weighted data, let be the supplied case weight, and let and be the weighted event count and risk-set size at . The weighted KM estimator is
Xie and Liu (2005) proposed the following adjusted Greenwood expression:
Greenwood variance for weighted Kaplan–Meier where is an adjustment factor defined as For comparison, the analogous Tsiatis-type expression uses the corresponding first-order denominator. It is not the variance formula proposed by Xie and Liu (2005).
Tsiatis variance for weighted Kaplan–Meier
Neither weighted formula is selectable through error in
the current cifcurve() implementation. With weights, use
error = "if" or "fay". Requesting another
variance method issues a warning and falls back to IF.
Aalen–Johansen estimation and classical variances
With outcome.type = "competing-risk",
cifcurve() estimates the event-1 CIF using AJ. For
unweighted data, error = "delta" is the default, while
error = "aalen" selects the alternative classical variance.
In the formulas, cause 1 is the event of interest, cause 2 is the
competing event,
counts
cause-
events at
,
and
.
AJ weights each cause-specific event increment by the probability of
remaining event-free just before that time.
For cause , the estimator is
Aalen-Johansen estimator
Here
is overall event-free survival immediately before
,
with
.
It differs from the $surv component of a competing-risk
fit, which stores
.
For unweighted AJ estimates, error
selects either the Aalen (1978) or delta-method variance. The
implemented formulas are:
Aalen variance
Delta method variance
Influence-function representation
Set error = "if" to estimate variance from individual
influence-function (IF) contributions. Add
report.influence.function = TRUE to return the uncorrected
empirical contributions. The classical AJ representation below provides
background; the next section describes the finite-jump,
fixed-weight calculation implemented in
cifcurve(). For unweighted AJ estimates, Zhang and
Fine (2008) give the asymptotic linear expansion
The process
also converges weakly to a tight Gaussian process. Let
be the sample at-risk process, and define
For continuous cumulative hazards, let
and
be the martingales for all events and
cause-
events, respectively, for observation
.
The influence function is then
Equivalently, after changing the order
of integration,
A consistent estimator of the
asymptotic variance of
is
so the variance of
itself is estimated by
The preceding representation applies to unweighted AJ estimation
under the stated assumptions, including continuous cumulative hazards.
By contrast, cifcurve() differentiates the
empirical weighted product-limit estimator, allowing
tied event times. The C++ routine stores contributions on the estimator
scale (conventionally
);
their squared sum estimates the variance of
.
Externally supplied weights remain fixed, so propensity-score estimation
is not included. Deng and Wang (2025) derive influence functions that
account for estimating propensity scores.
Fixed-weight IF and Fay–Graubard variances
This section details the calculations behind
error = "if" and error = "fay". Both retain
the same KM/AJ point estimate but use different
contributions to estimate variance. The C++ engine differentiates the
finite-jump product limit, with or without weights, within each stratum.
Only positive-weight observations enter the variance and
degrees-of-freedom calculations; let
be their number. Without supplied weights, set
.
Define
where
and
.
For survival data there is one event cause. Set
Starting from
and
,
the uncorrected empirical IF contributions obey
With error = "if", the
variance is
for KM survival or
for the
cause-
CIF. The contributions are already on the estimator scale, with the
usual
factor incorporated. This recursion differentiates the finite-jump
product limit used by the software, rather than relying on a
continuous-hazard approximation.
With error = "fay", the Fay–Graubard correction (Fay and
Graubard 2001) applies the same recursion after replacing
and
by
and
,
respectively, where
The Fay–Graubard (FG) variance sums the
squared corrected contributions; the KM/AJ point estimate is
unchanged. The leverage cap is fixed at 0.75 and reported as
fay.bound; users cannot set it directly. Both
"fg" and "fay-graubard" are aliases for
"fay".
Even when error = "fay",
report.influence.function = TRUE returns
uncorrected contributions for the event probability
1 - fit$surv. Observations with zero weight contribute
zero.
Working degrees of freedom for IF-t and FG-t
With conf.dist = "t", cifcurve() uses a
time- and stratum-specific t critical value rather than a normal one.
For error = "if", df.method selects deletion
allocation ("deletion", FDF) or equal allocation
("equal", EDF). For error = "fay", only
deletion allocation is available (FG-t). The trace ratio below provides
working, not exact finite-sample Student, degrees of
freedom.
The calculation starts with individual weighted hazard scores , stacked over event times . Hazard logits use the no-event category as the baseline, except at complete exit, when a positive cause becomes the baseline; only positive-probability coordinates are retained. No additional time- or cause-specific equation multipliers are used. At the fitted parameter , define where is the KM survival estimate or the AJ CIF. This production calculation contains hazard scores only, with no propensity-score estimating equations.
Deletion allocation (FDF). The default
df.method = "deletion" uses
These quantities use derivatives at the
original fit; they do not require refitting after deleting each
observation. The relevant deleted blocks must be invertible, and the
allocation must be nonnegative and nonzero. Because the allocation can
depend on how estimating equations are normalized, the score convention
above is part of the method definition.
Equal allocation (EDF). For
error = "if", df.method = "equal" sets
.
In the uncorrected IF calculation, the resulting degrees of freedom are
invariant to fixed invertible score transformations when the derivatives
are transformed consistently. This holds for a fixed active set, not for
arbitrary parameter-dependent transformations. EDF degrees of freedom
generally do not equal
,
and EDF is unavailable with FG-t.
For either allocation, let for IF-t, and use the diagonal matrix containing the factors above for FG-t. Form Here has blocks . FG-t uses the original, uncorrected derivatives and deletion allocation; it does not differentiate . The correction enters and at the indicated positions. Thus IF-t (deletion) and FG-t can differ in both variance and degrees of freedom.
The trace ratio matches moments of a Gaussian working quadratic form, following the Satterthwaite principle. It does not imply an exact t distribution or guarantee improved small-sample coverage. FDF uses Fay-type deletion allocation; EDF uses equal allocation. Even with the same IF variance, different allocations may produce different critical values.
Confidence interval options
Method combinations
The following argument combinations select the available IF/FG
interval methods. Setting conf.dist = "t" without
error selects IF, even for unweighted data.
df.method affects IF-t, but not normal-reference
intervals.
| Construction | error |
conf.dist |
df.method |
|---|---|---|---|
| IF-normal | "if" |
"normal" |
Not used |
| IF-t (FDF) | "if" |
"t" |
"deletion" (default) |
| IF-t (EDF) | "if" |
"t" |
"equal" |
| FG-normal | "fay" |
"normal" |
Not used |
| FG-t | "fay" |
"t" |
"deletion" |
Student intervals require error = "if" or
"fay" and the C++ engine
(engine = "calculateAJ_Rcpp", the default, or
"auto"). The legacy "calculateKM" engine does
not support them. Degrees of freedom are calculated separately for each
time and stratum and may be costly for large risk sets.
Transformations and probability scale
The transformation is applied to the stored
probability:
for KM, but
for AJ (fit$surv). At an interior estimate with positive
variance, the transformed limits are obtained from
The limits are mapped back through
and ordered on the probability scale. Where needed, they are restricted
to the transformation’s range before inversion and to
afterward. The supported transformations are:
conf.type |
|
|---|---|
"plain" |
|
"log" |
|
"log-log" |
|
"logit" |
|
"arcsin" (default; aliases
"arcsine-square root", "a") |
The default is the arcsine–square-root CI
transformation. This option is distinct from
type.y, which controls the vertical plotting scale.
For AJ, fit$lower and fit$upper are limits
for
,
so the CIF limits are 1 - fit$upper and
1 - fit$lower. Accordingly, "log-log" applies
,
not
.
When displaying risk, cifplot() uses the CIF limits.
conf.type = "none" (or "n") omits intervals.
By default, std.err is on the probability scale;
report.survfit.std.err = TRUE instead uses the log scale of
the stored surv component.
Boundaries, failures, and one-sided tests
For the C++ IF/FG calculations, a valid estimate of 0 or 1 receives a
singleton interval. This is a boundary convention, not
a coverage guarantee. Limits are missing for interior estimates with
zero or invalid variance, unavailable Student degrees of freedom, or
times beyond positive-weight follow-up. A failed Student interval does
not fall back to a normal interval. The fit records
df, df.reason, critical.value,
and conf.status by time and stratum;
summary(fit, times = ..., extend = TRUE) preserves these
diagnostics, including missing limits outside follow-up support.
These intervals are pointwise, not simultaneous
confidence bands. The optional one-sided fixed-time probability test
using time.point and null.hypothesis retains a
normal reference even when conf.dist = "t" is selected for
intervals. Its default alternative is higher survival for KM and lower
event-1 cumulative incidence for AJ.
Worked examples
These short examples demonstrate cifcurve() options
rather than a full analysis workflow. With this small synthetic dataset,
working degrees of freedom or CIs may be unavailable at some times;
conf.status indicates why. For complete analyses and
tables, see Worked examples and Reporting results.
library(cifmodeling)
example_data <- data.frame(
time = 1:12,
status = c(1, 0, 2, 1, 2, 0, 1, 2, 0, 1, 0, 0),
weight = c(1, 1.5, 0.8, 1.2, 1, 0.7, 1.3, 1, 0.9, 1.1, 1, 1)
)
# AJ with IF-t and equal-allocation degrees of freedom.
fit_edf <- cifcurve(
Event(time, status) ~ 1, data = example_data, weights = "weight",
outcome.type = "competing-risk", error = "if",
conf.dist = "t", df.method = "equal", conf.type = "log-log"
)
at_five <- summary(fit_edf, times = 5)
data.frame(
time = at_five$time, CIF = 1 - at_five$surv,
SE = at_five$std.err, lower = 1 - at_five$upper,
upper = 1 - at_five$lower, df = at_five$df,
critical.value = at_five$critical.value,
df.reason = at_five$df.reason,
status = at_five$conf.status
)## time CIF SE lower upper df critical.value df.reason
## 1 5 0.1904 0.1220426 0.04291352 0.6383596 10.94327 2.202378 ok
## status
## 1 ok
# KM for the composite of either event, with FG-t.
example_data$composite_event <- as.integer(example_data$status > 0)
fit_fg <- cifcurve(
Event(time, composite_event) ~ 1, data = example_data,
outcome.type = "survival", error = "fay",
conf.dist = "t", conf.type = "arcsin"
)The first output table shows the event-1 CIF and its CI on the
probability scale, along with degrees of freedom, the critical value,
and inference status. The same diagnostics are stored as
fit_edf$df, fit_edf$df.reason,
fit_edf$critical.value, and
fit_edf$conf.status on the original event-time grid; use
summary(fit_edf, times = ...) to extract them at a chosen
time. In the second fit, error = "fay" changes the
variance, while conf.dist = "t" changes the reference
critical value.
To plot Student intervals, first fit them with
cifcurve() and pass the result to cifplot().
The cifplot() formula interface does not
forward conf.dist or df.method to
cifcurve().
cifplot(fit_edf, outcome.type = "competing-risk", add.risktable = FALSE)See Function reference for the full set of arguments and Reporting cumulative incidence for extracting estimates and building tables.
References
- Aalen OO. Nonparametric inference for a family of counting processes. Ann Statist. 1978;6(4):701–726. doi:10.1214/aos/1176344247
- Tsiatis AA. A large sample study of Cox’s regression model. Ann Statist. 1981;9(1):93–108. doi:10.1214/aos/1176345335
- Zhang M-J, Fine JP. Summarizing differences in cumulative incidence functions. Stat Med. 2008;27(24):4939–4949. doi:10.1002/sim.3339
- Xie J, Liu C. Adjusted Kaplan–Meier estimator and log-rank test with inverse probability of treatment weighting for survival data. Stat Med 2005;24(20):3089–110. doi:10.1002/sim.2174
- Deng Y, Wang R. Adjusted Nelson–Aalen estimators by inverse treatment probability weighting with an estimated propensity score. Statistics in Medicine. 2025;44(10–12):e70085. doi:10.1002/sim.70085
- Fay MP, Graubard BI. Small-sample adjustments for Wald-type tests using sandwich estimators. Biometrics. 2001;57(4):1198–1206. doi:10.1111/j.0006-341X.2001.01198.x