Skip to contents

Computes the weighted Kaplan-Meier (WKM) statistic of Pepe and Fleming for comparing two survival curves. The statistic is the weighted integral of the difference between the Kaplan-Meier estimates of the treatment and control groups over the observed range, standardized to a Wald z statistic. Unlike weighted log-rank tests, this test targets the integrated difference in survival and is sensitive to differences even when the hazard functions cross. The single scan over the sorted data is performed in C++ for use inside simulation loops.

Usage

wkm_fast(
  time,
  event,
  group,
  control = NULL,
  side = 2,
  conf.level = 0.95,
  weight = c("PF", "sqrtPF", "constant"),
  presorted = FALSE,
  data = NULL
)

Arguments

time

Numeric vector of event or censoring times. Alternatively, a formula Surv(time, event) ~ group, with the variables in data; see formula_interface.

event

Integer vector, 1 for an event and 0 for censoring.

group

Grouping vector with exactly two distinct levels.

control

The level of group that denotes the control group. With the formula interface it defaults to the first level of the group variable.

side

Either 2 for a two-sided test or 1 for a one-sided test of treatment superiority (weighted difference greater than 0).

conf.level

Confidence level for the interval of the weighted difference.

weight

Weight function, one of "PF" (Pepe-Fleming combined censoring weight), "sqrtPF" (its square root) or "constant" (weight 1).

presorted

Logical; set to TRUE when time, event and group are already sorted in ascending order of time, to skip the internal sort. Defaults to FALSE. The order is checked, and an error is given when it does not hold.

data

A data frame in which the variables of a formula given as time are evaluated. Used only with the formula interface; see formula_interface.

Value

A named numeric vector of class "wkm_fast" with the weighted integrated difference, its standard error and confidence limits, and the Wald statistics for the test. The object also has the class "fastsurv", whose as.data.frame(), coef(), and confint() methods are described in as.data.frame.fastsurv.

Details

The default weight is the Pepe-Fleming combined censoring weight w(t) = n G1(t) G2(t) / (n1 G1(t) + n2 G2(t)), where G1 and G2 are the Kaplan-Meier estimates of the censoring survival functions of the two groups. This weight gives less weight to regions with heavy censoring and stabilizes the variance in the tail. The choice weight = "sqrtPF" uses its square root, and weight = "constant" uses a weight of 1, in which case the numerator reduces to the difference in restricted mean survival time over the observed range. With weight = "PF" the result reproduces nphsim::wkm.Stat for data without tied times.

Because the integral extends to the largest observed time of the pooled data, the curve of a group whose follow-up ends earlier with a censored time is carried forward flat beyond that time. The Pepe-Fleming weight is zero there, but the constant and square-root weights are not, so with these weights the statistic can be biased, even under the null hypothesis, when follow-up differs between the groups. The Pepe-Fleming weight is recommended in that case.

The integral runs up to the largest observed time, so it is not defined when a time is infinite (for example a subject without a finite event or dropout time in simulated data), and all the statistics are then NA.

The weighted difference is computed as treatment minus control, so a positive value and a positive z indicate longer survival under treatment.

References

Pepe, M. S., & Fleming, T. R. (1989). Weighted Kaplan-Meier statistics: a class of distance tests for censored survival data. Biometrics, 45(2), 497-507.

Pepe, M. S., & Fleming, T. R. (1991). Weighted Kaplan-Meier statistics: large sample and optimality considerations. Journal of the Royal Statistical Society. Series B (Methodological), 53(2), 341-352.

Examples

set.seed(1)
n <- 300
g <- rep(0:1, each = n / 2)
tt <- c(rexp(n / 2, log(2) / 12), rexp(n / 2, log(2) / 16))
cc <- rexp(n, rate = 0.02)
time <- pmin(tt, cc)
event <- as.integer(tt <= cc)
wkm_fast(time, event, group = g, control = 0)
#> Weighted Kaplan-Meier test (Pepe-Fleming, two-group)
#> 
#>   control = 0
#>   weight = PF,  alternative = two.sided
#> 
#>                                             Est. lower 95% upper 95%     z
#> weighted difference (treatment - control) 2.8030    0.4869    5.1192 2.372
#>                                           Pr(>|z|)  
#> weighted difference (treatment - control)   0.0177 *
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

# Formula interface
d <- data.frame(time, event, g)
wkm_fast(Surv(time, event) ~ g, data = d)
#> Weighted Kaplan-Meier test (Pepe-Fleming, two-group)
#> 
#>   control = 0
#>   weight = PF,  alternative = two.sided
#> 
#>                                             Est. lower 95% upper 95%     z
#> weighted difference (treatment - control) 2.8030    0.4869    5.1192 2.372
#>                                           Pr(>|z|)  
#> weighted difference (treatment - control)   0.0177 *
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1