Skip to contents

Fits 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.

ProcedureRegimeError orderEffective nRegularityBasisReferences
randfinite sampleexactsubjectsregulartheory[Fisher1935], [LehmannRomano2005]
waldasymptotic\(O(n_{eff}^{-1})\)subjectsregularassumed default[Hall1992]
jackknifeasymptotic\(O(n_{eff}^{-1})\)subjectsregularassumed default[ShaoTu1995]
bootstrapasymptotic\(O(n_{eff}^{-1})\)subjectsregularassumed default[Hall1992]
bayes_bootasymptotic\(O(n_{eff}^{-1})\)subjectsregularassumed default[Rubin1981], [Lo1987]
rand_bootstrapasymptotic\(O(n_{eff}^{-1})\)subjectsregularassumed 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_T not 0.5), for wald, jackknife, bootstrap, bayes_boot, rand_bootstrap: the effective n is the size of the smaller arm.

  • On DesignFixedBlockedCluster, DesignFixedCluster, for wald, 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

+ inherited public methods from Inference


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_obj

The design object.

model_formula

Optional 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.

verbose

If TRUE, print additional information.

smart_cold_start_default

Whether to use smart cold start values by default.


InferenceSurvivalKMDiff$compute_estimate()

Computes the class-specific mean or survival contrast; see InferenceMLEorKMSummaryTable.

Usage

InferenceSurvivalKMDiff$compute_estimate(estimate_only = FALSE)

Arguments

estimate_only

If TRUE, skip variance component calculations.

Returns

The setting-appropriate (see description) numeric estimate of the treatment effect

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.

Usage

InferenceSurvivalKMDiff$compute_estimate_with_bootstrap_weights(
  subject_or_block_weights,
  estimate_only = FALSE
)

Arguments

subject_or_block_weights

Row weights for the bootstrap sample.

estimate_only

If TRUE, skip variance calculations.


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

delta

Null median difference. Default 0.

B

Number of Bayesian-bootstrap replicates. Default 501.

type

Bayesian-bootstrap p-value type.

na.rm

Whether to discard non-finite weighted-median draws. Defaults to TRUE for this estimator.

show_progress

Whether to display a progress bar.

min_number_usable_samples

Minimum number of finite draws required.

weighting_unit_type

Optional Bayesian-bootstrap weighting-unit scheme.

min_fraction_usable_samples

Minimum fraction of the B draws that must be finite when na.rm = TRUE. Default 0.95. See InferenceBayesianBootstrap$compute_bayesian_bootstrap_two_sided_pval.

Returns

A numeric two-sided p-value, or NA_real_ when too few finite draws remain.


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).

Usage

InferenceSurvivalKMDiff$compute_asymp_confidence_interval(alpha = 0.05)

Arguments

alpha

The significance level; the confidence level is 1 - alpha. Default is 0.05.

Returns

A numeric vector of length 2 giving the (lower, upper) confidence bounds for the difference in median survival times, on the original time scale.


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.

Usage

InferenceSurvivalKMDiff$compute_asymp_two_sided_pval(delta = 0)

Arguments

delta

The null difference to test against. Default is 0.

Returns

The approximate frequentist p-value


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
)

Arguments

delta

The null difference to test against. For any treatment effect at all this is set to zero (the default).

Returns

The approximate frequentist p-value


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

alpha

The confidence level in the computed confidence interval is 1 - alpha. The default is 0.05.

r

The number of randomization vectors. The default is 501.

pval_epsilon

The bisection algorithm tolerance. The default is 0.005.

show_progress

Show a text progress indicator.

ci_search_control

Unused.

Returns

A 1 - alpha sized frequentist confidence interval


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"
)

Arguments

alpha

Significance level; the confidence level is 1 - alpha. Default 0.05.

unit

Deletion unit passed to the shared jackknife. Default "auto", which chooses a design-aware unit automatically; see InferenceJackknife.

Returns

A length-2 numeric jackknife-Wald confidence interval, or c(NA, NA) (with the warning above).


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().

Usage

InferenceSurvivalKMDiff$compute_jackknife_wald_two_sided_pval(
  delta = 0,
  unit = "auto"
)

Arguments

delta

Null treatment-effect value (difference in medians). Default 0.

unit

Deletion unit passed to the shared jackknife. Default "auto", which chooses a design-aware unit automatically; see InferenceJackknife.

Returns

A two-sided jackknife-Wald p-value, or NA (with the warning above).


InferenceSurvivalKMDiff$clone()

The objects of this class are cloneable with this method.

Usage

InferenceSurvivalKMDiff$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

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