
Censored Survival Outcomes
Source:vignettes/articles/censored-survival-outcomes.Rmd
censored-survival-outcomes.RmdFor a time-to-event outcome, the event time is often known only to lie in an interval: a patient was still event-free when the study closed (right censoring), or an infection was only found at the next scheduled visit (interval censoring). This article shows how to record censored outcomes in EDI (Experimental Design and Inference), analyze right- and interval-censored data, which inference classes accept interval censoring, and what censoring assumes. It assumes you know the four steps of an EDI analysis (design, assign, record responses, infer) from Get started.
Recording censored outcomes
For a "survival" response, EDI records each outcome as
an interval (y_L, y_R] that the event time is known to lie
in:
| What you know | Record it as |
|---|---|
The event happened at time t
|
y = t |
Event-free at last contact, time t (right
censored) |
y_L = t, y_R = Inf |
The event happened before time t (left censored) |
y_L = 0, y_R = t |
The event happened between visits at a and
b (interval censored) |
y_L = a, y_R = b |
With add_all_subject_responses() you pass three vectors
ys, y_Ls and y_Rs; each subject
has either a ys value or both bounds, and NA
in the others. add_one_subject_response() takes the same
three arguments one subject at a time. The survival cookbook is the full worked
example for right censoring, including the randomization test,
bootstrap, InferenceSuite and a sequential design; this
article only adds what is different.
Right censoring at the end of follow-up
In many trials censoring is administrative: patients enroll over two years, the study closes at year three, and anyone still event-free is censored at however long they have been followed.
set.seed(2)
n = 150
X_surv = data.frame(age = round(rnorm(n, 60, 10)), stage = sample(1:3, n, replace = TRUE))
des_rc = DesignFixediBCRD$new(n = n, response_type = "survival", verbose = FALSE)
des_rc$add_all_subjects_to_experiment(X_surv)
des_rc$assign_w_to_all_subjects()
w_rc = des_rc$get_w()
event_time = rexp(n, rate = exp(-1 - 0.5 * w_rc + 0.02 * (X_surv$age - 60) +
0.3 * (X_surv$stage - 2)))
follow_up = 3 - runif(n, 0, 2) # enrolled during years 0-2, study ends at year 3
observed = event_time <= follow_up
des_rc$add_all_subject_responses(
ys = ifelse(observed, event_time, NA),
y_Ls = ifelse(observed, NA, follow_up),
y_Rs = ifelse(observed, NA, Inf)
)
table(event_observed = observed)
#> event_observed
#> FALSE TRUE
#> 78 72
inf_rc = InferenceSurvivalCoxPHRegr$new(des_rc, verbose = FALSE)
inf_rc$num_cores = 1L
log_hr = inf_rc$compute_estimate()
ci_rc = inf_rc$compute_lik_ratio_confidence_interval(alpha = 0.05)
exp(c(hazard_ratio = log_hr, ci_rc))
#> hazard_ratio 2.5% 97.5%
#> 0.4847499 0.2943431 0.7829552The true hazard ratio is 0.61; the estimate is 0.48, and the interval contains the truth. Every survival class in EDI accepts right-censored data.
Interval censoring: events found at scheduled visits
Now suppose the event (say, a recurrence) can only be detected at
clinic visits every three months, for two years. A recurrence found at
the month-9 visit happened sometime after month 6. A recurrence found at
the first visit happened sometime before month 3, which is left
censoring, the case y_L = 0. Patients with no recurrence by
month 24 are right censored there.
set.seed(7)
n = 120
X_ic = data.frame(age = round(rnorm(n, 60, 10)))
des_ic = DesignFixediBCRD$new(n = n, response_type = "survival", verbose = FALSE)
des_ic$add_all_subjects_to_experiment(X_ic)
des_ic$assign_w_to_all_subjects()
w_ic = des_ic$get_w()
# Weibull event times; treatment multiplies the time scale by exp(0.4), about 1.5
t_event = rweibull(n, shape = 1.5, scale = 12 * exp(0.4 * w_ic - 0.02 * (X_ic$age - 60)))
visits = seq(3, 24, by = 3)
y_L = sapply(t_event, function(t) max(c(0, visits[visits < t])))
y_R = sapply(t_event, function(t) if (t > max(visits)) Inf else min(visits[visits >= t]))
des_ic$add_all_subject_responses(y_Ls = y_L, y_Rs = y_R)
table(type = ifelse(is.infinite(y_R), "right censored",
ifelse(y_L == 0, "left censored", "interval censored")))
#> type
#> interval censored left censored right censored
#> 99 8 13
head(cbind(y_L, y_R))
#> y_L y_R
#> [1,] 18 21
#> [2,] 0 3
#> [3,] 6 9
#> [4,] 6 9
#> [5,] 18 21
#> [6,] 18 21No subject has an exact time, and you should not invent one (the visit time or the midpoint), because that biases the analysis. Instead, use a class that takes the intervals as they are. A Weibull accelerated-failure-time model gives a time ratio:
inf_wb = InferenceSurvivalWeibullRegr$new(des_ic, verbose = FALSE)
inf_wb$num_cores = 1L
exp(c(time_ratio = inf_wb$compute_estimate(),
inf_wb$compute_lik_ratio_confidence_interval(alpha = 0.05)))
#> time_ratio 2.5% 97.5%
#> 1.557451 1.239437 1.972582On interval-censored data, the Cox class switches to the
semiparametric proportional-hazards model of icenReg
(ic_sp()), and the log-rank class to the interval-censored
log-rank test of Sun (1996), via interval:
inf_cox = InferenceSurvivalCoxPHRegr$new(des_ic, verbose = FALSE)
inf_cox$num_cores = 1L
exp(c(hazard_ratio = inf_cox$compute_estimate(),
inf_cox$compute_asymp_confidence_interval(alpha = 0.05)))
#> hazard_ratio 2.5% 97.5%
#> 0.4934320 0.3287465 0.7406166
inf_lr = InferenceSurvivalLogRank$new(des_ic, verbose = FALSE)
inf_lr$num_cores = 1L
inf_lr$compute_asymp_two_sided_pval()
#> [1] 0.002767542
inf_lr$set_seed(1)
inf_lr$compute_rand_two_sided_pval(r = 200, show_progress = FALSE)
#> [1] 0.02985075For these Weibull data with shape 1.5, a time ratio of \(e^{0.4} \approx 1.49\) is the same as a
hazard ratio of \(e^{-0.4 \times 1.5} \approx
0.55\), so the two models agree. The randomization test needs
nothing new: it redraws w from the design and recomputes
the interval-censored statistic. A test of a nonzero null time ratio
\(e^{\delta}\) (delta in
compute_rand_two_sided_pval()) rescales the treated
subjects’ interval bounds by \(e^{\delta}\) as it rescales exact times (a
bound of 0 or Inf stays put), so the Weibull class’s
randomization confidence interval for the time ratio,
inf_wb$compute_rand_confidence_interval(), works on
interval-censored data too.
Median and restricted mean survival differences
A hazard ratio or time ratio leans on a model. Two classes compare
the arms without one, on the time scale itself: the difference in median
survival (InferenceSurvivalKMDiff) and the difference in
restricted mean survival time, the area under each arm’s survival curve
up to a horizon \(\tau\)
(InferenceSurvivalRestrictedMeanDiff). On interval-censored
data both read the survival curves from the Turnbull NPMLE instead of
Kaplan-Meier.
inf_km = InferenceSurvivalKMDiff$new(des_ic, verbose = FALSE)
inf_km$num_cores = 1L
inf_km$set_seed(1)
km_est = inf_km$compute_estimate()
km_ci = inf_km$compute_asymp_confidence_interval(alpha = 0.05)
inf_km$set_seed(1)
km_p = inf_km$compute_rand_two_sided_pval(r = 200, show_progress = FALSE)
c(median_difference = km_est, km_ci, rand_pval = km_p)
#> median_difference 2.5% 97.5% rand_pval
#> 6.00000000 -3.00000000 9.00000000 0.02985075
# tau = 24 months, the planned follow-up, fixed in the protocol before the data are seen
inf_rmst = InferenceSurvivalRestrictedMeanDiff$new(des_ic, verbose = FALSE, tau = 24)
inf_rmst$num_cores = 1L
inf_rmst$set_seed(1)
rmst_est = inf_rmst$compute_estimate()
rmst_ci = inf_rmst$compute_asymp_confidence_interval(alpha = 0.05)
inf_rmst$set_seed(1)
rmst_p = inf_rmst$compute_rand_two_sided_pval(r = 200, show_progress = FALSE)
c(rmst_difference = rmst_est, rmst_ci, rand_pval = rmst_p)
#> rmst_difference 2.5% 97.5% rand_pval
#> 3.65000000 1.13518111 6.53135505 0.02985075The treated arm’s median recurrence time is 6 months later, and over the first 24 months treated patients are recurrence-free for 3.65 months longer on average (95% interval 1.14 to 6.53). The median difference is a multiple of three months: the Turnbull curve only drops between visits, so its median sits on the visit grid. That makes the median a coarse statistic, and its interval is wide; here it covers zero although the randomization test rejects at the 5% level. The restricted mean uses the whole curve and is more precise.
Neither class has a closed-form standard error on interval-censored
data, so compute_asymp_confidence_interval() is really a
nonparametric bootstrap interval, at the bootstrap defaults: B = 501, a
percentile interval for the median difference and a BCa interval for the
restricted mean. It is reproducible after set_seed(), but
each call refits the Turnbull NPMLE about a thousand times and takes
seconds rather than milliseconds. BCa needs B of at least 501; if time
matters more than the BCa correction, call
compute_bootstrap_confidence_interval(B = 199, type = "percentile")
yourself. Other differences from right-censored data:
-
The Bayesian bootstrap is refused, with an error,
because the Turnbull fit (
interval::icfit()) takes no weights. Use the ordinary bootstrap. -
The jackknife of a median is unreliable:
InferenceSurvivalKMDiff’s jackknife-Wald interval and p-value are usuallyNA, with a warning. - Randomization confidence intervals are not available for either class (their units do not fit the randomization interval search); the randomization p-value is.
-
A median may not be reached. If an arm’s survival
curve never falls to 0.5, for example at an early interim look, the
median difference is
NA. The restricted mean is defined however short the follow-up, so use it then.
Why prespecify tau? By default the horizon is the
smaller of the two arms’ last finite visit times, here also 24 months.
That default depends on the data: a few missed final visits in one arm
would shorten it and change what is being estimated. EDI fixes the
horizon once, from the observed data or from your tau, and
holds it fixed in every randomization and bootstrap draw. (Recomputing
it in each draw would make the null draws compare restricted means over
different horizons and can take away almost all the test’s power.)
Choosing tau in the protocol, typically the planned
follow-up, makes the estimand known before the data are seen.
Which classes accept interval censoring
A class that cannot use left- or interval-censored data refuses at construction, with an error that says so, rather than treating the intervals as right-censored. Trying each class on this design shows which ones accept it:
survival_classes = c("InferenceSurvivalCoxPHRegr", "InferenceSurvivalWeibullRegr",
"InferenceSurvivalLogRank", "InferenceSurvivalGehanWilcox",
"InferenceSurvivalRestrictedMeanDiff", "InferenceSurvivalKMDiff",
"InferenceSurvivalStratCoxPHRegr", "InferenceSurvivalDepCensTransformRegr")
accepts = sapply(survival_classes, function(cl)
tryCatch({ get(cl)$new(des_ic, verbose = FALSE); TRUE }, error = function(e) FALSE))
data.frame(accepts_interval_censoring = accepts)
#> accepts_interval_censoring
#> InferenceSurvivalCoxPHRegr TRUE
#> InferenceSurvivalWeibullRegr TRUE
#> InferenceSurvivalLogRank TRUE
#> InferenceSurvivalGehanWilcox TRUE
#> InferenceSurvivalRestrictedMeanDiff TRUE
#> InferenceSurvivalKMDiff TRUE
#> InferenceSurvivalStratCoxPHRegr FALSE
#> InferenceSurvivalDepCensTransformRegr FALSEIn short:
-
Accept left- and interval-censored data:
InferenceSurvivalCoxPHRegr(icenReg semiparametric PH),InferenceSurvivalWeibullRegr(the interval-censored Weibull likelihood),InferenceSurvivalLogRankandInferenceSurvivalGehanWilcox(interval-censored rank tests),InferenceSurvivalRestrictedMeanDiffandInferenceSurvivalKMDiff(survival curves from the Turnbull NPMLE (Turnbull 1976, doi:10.1111/j.2517-6161.1976.tb01597.x); their intervals come from the bootstrap, see above). - Exact and right-censored data only: the stratified Cox, dependent-censoring, frailty and KK matched-pair survival classes.
Not every procedure is available on the interval-censored path; for
example, the Bayesian bootstrap is not. Each class’s help page lists
what changes. The InferenceSuite (see the survival cookbook)
skips the classes that do not apply.
What censoring assumes
All of these methods assume censoring is noninformative:
given the covariates, a patient censored at time t has the
same future risk as one still under follow-up. Administrative censoring
at the end of the study satisfies this; dropout because a patient felt
worse does not. In a randomized trial the comparison stays fair as long
as censoring does not depend on prognosis differently in the two arms,
but that is an assumption, not something the data can confirm. InferenceSurvivalDepCensTransformRegr
relaxes it under a parametric model (a bivariate log-normal for event
and censoring times), for right-censored data.
Where to go next
- The full right-censored workflow (randomization test, bootstrap,
InferenceSuite, sequential design): survival cookbook. - Missing baseline covariates, and why EDI cannot analyze outcomes that are simply missing: Missing Covariate Values and Imputation.
- Which procedures hold their level at your sample size: Procedure trust.