
Kaplan-Meier Median-Difference Inference for Survival Responses
Source:R/inference_survival_km_diff.R
InferenceSurvivalKMDiff.RdFits a non-parametric treatment-effect estimator for censored survival
responses: the difference in Kaplan-Meier median survival times
between the treated and control arms, \(d = \hat m_T - \hat m_C\). The
confidence interval combines each arm's own Brookmeyer-Crowley confidence
interval \([l_i, u_i]\) for its median (via survival::survfit's
default log-transformed interval) by the method of variance estimates
recovery (MOVER; Zou and Donner, 2008), keeping each side's half-width
separately because a median's interval is often lopsided (a flat
Kaplan-Meier curve near 0.5 with few events gives a long upper tail):
$$\left[d - \sqrt{(\hat m_T - l_T)^2 + (u_C - \hat m_C)^2},
d + \sqrt{(u_T - \hat m_T)^2 + (\hat m_C - l_C)^2}\right].$$
The two arms are independent by design. When either arm's median is not
reached (its Kaplan-Meier curve never falls to 0.5) the estimate itself is
NA, and so is every result on the object (asymptotic, bootstrap,
jackknife and randomization); one warning of class
edi_km_median_not_reached_warning names the arm(s) and their lowest
survival and suggests InferenceSurvivalRestrictedMeanDiff (silent
inside resampling, where a draw that loses its median just counts as
unusable). When both medians are reached but a Brookmeyer-Crowley bound is
non-finite, the Wald-style confidence interval and p-value methods
($compute_asymp_confidence_interval(), $compute_asymp_two_sided_pval())
return NA, with the reason recorded and an
edi_wald_unavailable_warning; before EDI 1.0.6 they fell back to a
nonparametric bootstrap (v1.0.6-TODO-380). The
jackknife-Wald methods are unreliable for a median and are often NA,
with an edi_km_jackknife_na_warning giving the reason; prefer the
bootstrap. A convenience method,
$compute_asymp_log_rank_two_sided_pval_for_treatment_effect(), is also
provided for the log-rank p-value on the same fitted survival curves. For
left- or interval-censored data, the point estimate instead comes
from a Turnbull NPMLE median contrast (interval::icfit(), via
turnbull_npmle_stat_diff(); exact events are folded in as degenerate
intervals \([y, y]\) rather than dropped, and unusable rows are excluded
with a warning), which has no closed-form standard error —
inference on that path relies entirely on the nonparametric bootstrap:
$compute_asymp_confidence_interval() and
$compute_asymp_two_sided_pval() return the bootstrap interval and
p-value there. The Bayesian bootstrap
($compute_bayesian_bootstrap_confidence_interval(),
$compute_bayesian_bootstrap_two_sided_pval() and
$approximate_bayesian_bootstrap_distribution_beta_hat_T()) stops
with an error on left- or interval-censored data, because interval::icfit() has no weights argument; use the
nonparametric bootstrap there instead. On right-censored data it is
unaffected.
Randomization confidence intervals are not supported (the median
difference's units are not commensurate with the randomization CI bisection
algorithm's transformed-scale null search).
Small-sample behaviour
How fast the size (and coverage) error of each procedure is expected to vanish as the
effective sample size \(n_{eff}\) grows, from EDI's convergence-rate registry
(inference_convergence_expectation()). Exact procedures are valid at every
n by construction; the others are asymptotic, so a small-sample excess is expected, and
its constant is not given by an order. The table is the expectation for a balanced
complete-randomization design; it is not a measured size. Reference keys are explained
under References.
| Procedure | Regime | Error order | Effective n | Regularity | Basis | References |
rand | finite sample | exact | subjects | regular | theory | [Fisher1935], [LehmannRomano2005] |
wald | asymptotic | \(O(n_{eff}^{-1})\) | subjects | regular | assumed default | [Hall1992] |
jackknife | asymptotic | \(O(n_{eff}^{-1})\) | subjects | regular | assumed default | [ShaoTu1995] |
bootstrap | asymptotic | \(O(n_{eff}^{-1})\) | subjects | regular | assumed default | [Hall1992] |
bayes_boot | asymptotic | \(O(n_{eff}^{-1})\) | subjects | regular | assumed default | [Rubin1981], [Lo1987] |
rand_bootstrap | asymptotic | \(O(n_{eff}^{-1})\) | subjects | regular | assumed default | [Hall1992], [Kallus2018] |
The point estimate's bias is of order \(O(n_{eff}^{-1})\) (assumed default: [CoxSnell1968]).
Rows with basis assumed default: the order shown is the procedure's rate in a regular parametric model, and the cited works establish it for that case only. EDI has not derived it for this class.
Design-specific differences from the table:
On any design with unequal allocation (
prob_Tnot 0.5), forwald,jackknife,bootstrap,bayes_boot,rand_bootstrap: the effective n is the size of the smaller arm.On
DesignFixedBlockedCluster,DesignFixedCluster, forwald,jackknife,bootstrap,bayes_boot,rand_bootstrap: the effective n is the number of clusters.
References
Kaplan, E. L., and Meier, P. (1958). "Nonparametric Estimation
from Incomplete Observations." Journal of the American Statistical
Association, 53(282), 457-481, doi:10.2307/2281868
, for the
Kaplan-Meier survival curve estimator each arm's median is read from.
Brookmeyer, R., and Crowley, J. (1982). "A Confidence Interval for the
Median Survival Time." Biometrics, 38(1), 29-41,
doi:10.2307/2530286
, for each arm's median confidence interval.
Zou, G. Y., and Donner, A. (2008). "Construction of Confidence Limits
About Effect Measures: A General Approach." Statistics in
Medicine, 27(10), 1693-1702, doi:10.1002/sim.3095
, for the MOVER
combination of the two arms' intervals into one for the difference
(see [ZouDonner2008] in REFERENCES.md). Turnbull, B. W. (1976).
"The Empirical Distribution Function with Arbitrarily Grouped, Censored
and Truncated Data." Journal of the Royal Statistical Society,
Series B, 38(3), 290-295, doi:10.1111/j.2517-6161.1976.tb01597.x
, for
the NPMLE used on the left-/interval-censored path.
[Fisher1935] Fisher, R. A. (1935). The Design of Experiments. Oliver and Boyd.
[LehmannRomano2005] Lehmann, E. L., and Romano, J. P. (2005). Testing Statistical Hypotheses (3rd ed.). Springer.
[Hall1992] Hall, P. (1992). The Bootstrap and Edgeworth Expansion. Springer.
[ShaoTu1995] Shao, J., and Tu, D. (1995). The Jackknife and Bootstrap. Springer.
[Rubin1981] Rubin, D. B. (1981). "The Bayesian Bootstrap." The Annals of Statistics, 9(1), 130-134.
[Lo1987] Lo, A. Y. (1987). "A Large Sample Study of the Bayesian Bootstrap." The Annals of Statistics, 15(1), 360-375.
[Kallus2018] Kallus, N. (2018). "Optimal a priori balance in the design of controlled experiments." Journal of the Royal Statistical Society: Series B, 80(1), 85-112. Section 5 ("Algorithms for inference"), Algorithm 4.
[CoxSnell1968] Cox, D. R., and Snell, E. J. (1968). "A General Definition of Residuals." Journal of the Royal Statistical Society: Series B, 30(2), 248-265 (discussion 265-275).
Super class
Inference -> InferenceSurvivalKMDiff
Methods
Public methods
InferenceSurvivalKMDiff$compute_estimate_with_bootstrap_weights()InferenceSurvivalKMDiff$compute_bayesian_bootstrap_two_sided_pval()InferenceSurvivalKMDiff$compute_asymp_log_rank_two_sided_pval_for_treatment_effect()InferenceSurvivalKMDiff$compute_jackknife_wald_confidence_interval()InferenceSurvivalKMDiff$compute_jackknife_wald_two_sided_pval()
+ inherited public methods from Inference
Inference$capabilities()Inference$clear_randomization_cache()Inference$compute_exact_confidence_interval()Inference$compute_exact_two_sided_pval_for_treatment_effect()Inference$duplicate()Inference$get_analysis_data()Inference$get_covariates()Inference$get_design_object()Inference$get_estimand()Inference$get_model_formula()Inference$get_nonestimable_reason()Inference$get_nonestimable_stage()Inference$get_optimization_alg()Inference$get_procedure_validity()Inference$get_response()Inference$get_response_type()Inference$get_summary()Inference$get_supported_estimands()Inference$get_treatment()Inference$is_nonestimable()Inference$set_estimand()Inference$set_optimization_alg()Inference$set_seed()Inference$supports()
InferenceSurvivalKMDiff$new()
Uses the shared randomization two-sided p-value contract; see
InferenceRand.
Initialize Kaplan-Meier median-difference survival inference
and prepare treatment-group survival curves used by
InferenceSurvivalKMDiff.
Usage
InferenceSurvivalKMDiff$new(
des_obj,
model_formula = NULL,
verbose = FALSE,
smart_cold_start_default = NULL
)Arguments
des_objThe design object.
model_formulaOptional formula for covariate adjustment. If
NULL(default), the formula from the design object is used and its pre-computed design matrix is reused. If a formula is provided, a new design matrix is constructed from the design's imputed covariates.verboseIf TRUE, print additional information.
smart_cold_start_defaultWhether to use smart cold start values by default.
InferenceSurvivalKMDiff$compute_estimate()
Computes the class-specific mean or survival contrast; see
InferenceMLEorKMSummaryTable.
Examples
seq_des = DesignSeqOneByOneBernoulli$new(n = 6, response_type = "survival")
seq_des$add_one_subject_to_experiment_and_assign(MASS::biopsy[1, 2 : 10])
seq_des$add_one_subject_to_experiment_and_assign(MASS::biopsy[2, 2 : 10])
seq_des$add_one_subject_to_experiment_and_assign(MASS::biopsy[3, 2 : 10])
seq_des$add_one_subject_to_experiment_and_assign(MASS::biopsy[4, 2 : 10])
seq_des$add_one_subject_to_experiment_and_assign(MASS::biopsy[5, 2 : 10])
seq_des$add_one_subject_to_experiment_and_assign(MASS::biopsy[6, 2 : 10])
seq_des$add_all_subject_responses(
ys = c(4.71, NA, 4.78, 6.11, NA, 8.43),
y_Ls = c(NA, 1.23, NA, NA, 5.95, NA),
y_Rs = c(NA, Inf, NA, NA, Inf, NA)
)
seq_des_inf = InferenceSurvivalKMDiff$new(seq_des)
seq_des_inf$compute_estimate()InferenceSurvivalKMDiff$compute_estimate_with_bootstrap_weights()
Recomputes the class-specific treatment estimate for a bootstrap sample; see
InferenceNonParamBootstrap.
InferenceSurvivalKMDiff$compute_bayesian_bootstrap_two_sided_pval()
Computes a Bayesian-bootstrap two-sided p-value for the difference in Kaplan-Meier medians.
A weighted Kaplan-Meier curve can fail to reach 0.5 even when the
original sample has finite medians in both arms. Such a draw has no
finite median-difference estimate. This class therefore drops non-finite
weighted-median draws by default and requires at least
min_number_usable_samples finite draws. If too few remain, the
result is NA_real_ with nonestimability reason
"bayesian_bootstrap_too_few_finite_estimates". It also requires
at least min_fraction_usable_samples (default 95%) of the B
draws to be finite (v1.0.6-TODO-12); below that the result is NA_real_
with reason "bayesian_bootstrap_too_few_valid_replicates_fraction". Set
na.rm = FALSE to retain the generic fail-on-any-nonfinite policy.
Usage
InferenceSurvivalKMDiff$compute_bayesian_bootstrap_two_sided_pval(
delta = 0,
B = 501,
type = NULL,
na.rm = TRUE,
show_progress = TRUE,
min_number_usable_samples = 5L,
weighting_unit_type = NULL,
min_fraction_usable_samples = 0.95
)Arguments
deltaNull median difference. Default 0.
BNumber of Bayesian-bootstrap replicates. Default 501.
typeBayesian-bootstrap p-value type.
na.rmWhether to discard non-finite weighted-median draws. Defaults to
TRUEfor this estimator.show_progressWhether to display a progress bar.
min_number_usable_samplesMinimum number of finite draws required.
weighting_unit_typeOptional Bayesian-bootstrap weighting-unit scheme.
min_fraction_usable_samplesMinimum fraction of the
Bdraws that must be finite whenna.rm = TRUE. Default 0.95. SeeInferenceBayesianBootstrap$compute_bayesian_bootstrap_two_sided_pval.
InferenceSurvivalKMDiff$compute_asymp_confidence_interval()
Computes a (1 - alpha)-level confidence interval for the difference in Kaplan-Meier median survival times (treatment minus control).
The Brookmeyer-Crowley confidence interval \([l_i, u_i]\) at level
1 - alpha is obtained for each group's median separately via
survival::survfit (log-transformed, survfit's default). The two
groups are independent by design, and the intervals are combined by MOVER
(Zou and Donner, 2008), which keeps each side's half-width rather than
forcing a symmetric interval:
\([d - \sqrt{(\hat m_T - l_T)^2 + (u_C - \hat m_C)^2},
d + \sqrt{(u_T - \hat m_T)^2 + (\hat m_C - l_C)^2}]\) with
\(d = \hat m_T - \hat m_C\).
When either group's median is not reached (its Kaplan-Meier curve does not
fall to 0.5) the estimate is NA and so is this interval, with an
edi_km_median_not_reached_warning (see the class description). When
both medians are reached but a Brookmeyer-Crowley bound is NA, the
interval is NA too, with an edi_wald_unavailable_warning (no
bootstrap is substituted, v1.0.6-TODO-380). On left- or interval-censored
data, which have no analytic standard error, this is the nonparametric
bootstrap interval (see the class description).
InferenceSurvivalKMDiff$compute_asymp_two_sided_pval()
Computes a Wald-style 2-sided p-value based on the median difference
and the side-specific standard error of the MOVER interval: the 95% MOVER
half-width on the side of the estimate that delta lies on, divided by
\(z_{0.975}\). The test therefore agrees exactly with
$compute_asymp_confidence_interval(alpha = 0.05) (its p-value is 0.05
at either bound); at other levels the two are close but not exact inverses,
because each arm's interval changes shape with its level. NA (with an
edi_km_median_not_reached_warning) when a median is not reached, and
NA with an edi_wald_unavailable_warning under the same
conditions as the confidence interval (v1.0.6-TODO-380); the bootstrap p-value
on left- or interval-censored data.
InferenceSurvivalKMDiff$compute_asymp_log_rank_two_sided_pval_for_treatment_effect()
Computes a 2-sided p-value via the log rank test
Usage
InferenceSurvivalKMDiff$compute_asymp_log_rank_two_sided_pval_for_treatment_effect(
delta = 0
)InferenceSurvivalKMDiff$compute_rand_confidence_interval()
Uses the shared randomization confidence-interval contract; see
InferenceRandCI.
Usage
InferenceSurvivalKMDiff$compute_rand_confidence_interval(
alpha = 0.05,
r = 501,
pval_epsilon = 0.005,
show_progress = TRUE,
ci_search_control = NULL
)Arguments
alphaThe confidence level in the computed confidence interval is 1 -
alpha. The default is 0.05.rThe number of randomization vectors. The default is 501.
pval_epsilonThe bisection algorithm tolerance. The default is 0.005.
show_progressShow a text progress indicator.
ci_search_controlUnused.
InferenceSurvivalKMDiff$compute_jackknife_wald_confidence_interval()
Jackknife-Wald confidence interval; see
InferenceJackknife. The jackknife is
unreliable for a median (leave-one-out medians take only a few distinct
values, and the jackknife variance of a sample median is inconsistent), so
it often returns NA; when it does, a warning of class
edi_km_jackknife_na_warning (also an edi_procedure_na_warning)
gives the reason: the jackknife bias exceeds twice its standard error, or
some leave-one-out estimates are NA because deleting a unit leaves an
arm whose median is not reached. When the full-data median is itself not
reached only the edi_km_median_not_reached_warning is raised.
The bootstrap interval is the better choice for this estimator.
Usage
InferenceSurvivalKMDiff$compute_jackknife_wald_confidence_interval(
alpha = 0.05,
unit = "auto"
)InferenceSurvivalKMDiff$compute_jackknife_wald_two_sided_pval()
Jackknife-Wald two-sided p-value; see
InferenceJackknife. Unreliable for a
median for the same reasons as the interval; when the result is NA
an edi_km_jackknife_na_warning gives the reason (see
$compute_jackknife_wald_confidence_interval()). Prefer
$compute_bootstrap_two_sided_pval().
Examples
# \donttest{
# n = 40 so neither arm is empty or tiny (each arm's KM median must be reached)
set.seed(1)
seq_des = DesignSeqOneByOneBernoulli$new(n = 40, response_type = 'survival')
for (i in 1:40) {
seq_des$add_one_subject_to_experiment_and_assign(data.frame(x1 = rnorm(1)))
}
seq_des$add_all_subject_responses(runif(40))
inf = InferenceSurvivalKMDiff$new(seq_des)
inf$compute_estimate()
#> [1] -0.03043415
# }
## ------------------------------------------------
## Method `InferenceSurvivalKMDiff$compute_estimate()`
## ------------------------------------------------
seq_des = DesignSeqOneByOneBernoulli$new(n = 6, response_type = "survival")
seq_des$add_one_subject_to_experiment_and_assign(MASS::biopsy[1, 2 : 10])
#> [1] 0
seq_des$add_one_subject_to_experiment_and_assign(MASS::biopsy[2, 2 : 10])
#> [1] 1
seq_des$add_one_subject_to_experiment_and_assign(MASS::biopsy[3, 2 : 10])
#> [1] 0
seq_des$add_one_subject_to_experiment_and_assign(MASS::biopsy[4, 2 : 10])
#> [1] 1
seq_des$add_one_subject_to_experiment_and_assign(MASS::biopsy[5, 2 : 10])
#> [1] 1
seq_des$add_one_subject_to_experiment_and_assign(MASS::biopsy[6, 2 : 10])
#> [1] 0
seq_des$add_all_subject_responses(
ys = c(4.71, NA, 4.78, 6.11, NA, 8.43),
y_Ls = c(NA, 1.23, NA, NA, 5.95, NA),
y_Rs = c(NA, Inf, NA, NA, Inf, NA)
)
seq_des_inf = InferenceSurvivalKMDiff$new(seq_des)
seq_des_inf$compute_estimate()
#> [1] 1.33