4
$\begingroup$

In R's survival package, there is an optional weights argument you can supply when you fit a Kaplan-Meier curve. I can't find any documentation about what this does or what exactly a weighted Kaplan Meier estimate is.

I'm aware there are modification to Kaplan-Meier estimates for ties. For this question, any clarification about the basic estimator is fine, $$ \hat{S}(t) = \prod_{i: \space t_i \leq t} \bigg(1 - \frac{d_i}{n_i} \bigg) $$

How do weights change the Kaplan Meier estimate above? I don't see how a weight for every subject, $i$, could enter the model above.

If this were a model with iid observations and a well defined likelihood function, I would get parameter estimates by maximizing the log likelihood, $$\theta^* = \arg\max\limits_\theta \sum_i w_i \log(\mathcal{L}(\theta|x_i)),$$ with a weight $w_i$ for every observation. What is the analog for survival models, where terms in the likelihood are multiplied over the risk set?

Is there an interpretation in terms of $d_i$ and $n_i$ of how adding a weight, $w_i$, changes the Kaplan-Meier estimates

$\endgroup$

2 Answers 2

4
$\begingroup$

Weights in a survival model give you flexibility in terms of data formatting or a way to try to adjust estimates for sampling that wasn't representative. Therneau and Grambsch say, in Section 7.3 of Modeling Survival Data--Extending the Cox Model (Springer, 2000):

Two distinct uses for case weights (among many uses) need to be distinguished. The first is jrequency weights; a weight of 3 means that 3 data points were actually observed, had the same values for all variables, and have been collapsed into a single observation to save space. The program should then treat an observation with a weight of k as if it had appeared k times in the input data set. The second is sampling weights. For instance, if 10% of the high-risk subjects for a condition were included in a study but only 1% of those with low or moderate risk, we would want to weight the observations inversely as the sampling fractions to reflect this design, giving case weights 10 times greater to the low/moderate-risk individuals than to the high-risk ones.

For a Kaplan-Meier estimate, you could just weight both the deaths and the numbers at risk at each event time $i$ by the individual case weights. Think, for example, about the first example in the quote above: for a case weight of 2, you just double-count the weighted case in the denominator so long as it is at risk, and give it a count of 2 in the numerator at its event time. I'm not sure that's how it's implemented in the survival package; you could check by examining the C source code for Csurvfitkm, which does the main calculations. Perhaps Thomas Lumley, who used to maintain the package, could discuss further.

For the Cox partial likelihood solution, it's essentially what you propose. For the unweighted situation, differentiating the log partial likelihood with respect to the parameter-value vector $\theta$ gives a score vector (Equation 3.4 of Therneau and Grambsch):

$$ U(\theta) = \sum_{i=1}^n \int_0^{\infty} \left[X_i(s) - \bar x(\theta,s)\right] dN_i(s) = \sum_{i=1}^n U_i(\theta)$$

where $X_i$ represents the covariate values for case $i$ and $\bar x$ is a risk-weighted mean of $X$ over observations at risk.* The maximum partial likelihood estimator $\hat \theta$ solves:

$$\sum_{i=1}^n U_i(\hat \theta) = 0. $$

With case weights $w_i$, you instead solve:

$$\sum_{i=1}^n w_i U_i(\hat \theta) = 0. $$

while also case-weighting the contributions to $\bar x(\theta,s)$* in the score vector. Handling of variances and the information matrix is similar. See Section 7.3 of Therneau and Grambsch.

Note that the coxph default Efron approximation for tied event times is implemented via temporary case weights even in an unweighted Cox regression; see Section 5.1 of the main R survival vignette.

Case weights do affect some other calculations in coxph(). For example, non-integer case weights (as you might have in inverse propensity score weighting) lead to calculation of a robust variance estimate; see Section 2.7 of that vignette.


*The risk score for case $i$ in a regression without case weights is $r_i(\theta,s) =\exp[\theta' X_i(s)]$. Then the risk-weighted covariate average is:

$$\bar x(\theta,s) = \frac{\sum Y_i(s) r_i(s)X_i(s)}{\sum Y_i(s) r_i(s)}, $$

where $Y_i(s)$ is the at-risk indicator for time $s$. In the case-weighted regression, $r_i$ becomes $w_i r_i$.

$\endgroup$
5
  • $\begingroup$ I understand why you may want to use weights in a model. I don't understand how it affects the estimation of the survival function. Do you have a source for how a Kaplan-Meier model (or a Cox model) is fit using weights? $\endgroup$
    – Eli
    Commented Aug 2, 2021 at 19:33
  • $\begingroup$ I added more context to my question. Hope that clarifies what I'm asking. $\endgroup$
    – Eli
    Commented Aug 2, 2021 at 19:44
  • 1
    $\begingroup$ @Eli I provided the requested details. $\endgroup$
    – EdM
    Commented Aug 2, 2021 at 22:03
  • $\begingroup$ With the case weights, it is same as saying weighted cox regression model? $\endgroup$
    – Hello
    Commented Mar 8, 2022 at 2:14
  • $\begingroup$ @Hello see the answer from Thomas Lumley, who helped develop the survival package. The terminology can be confusing. $\endgroup$
    – EdM
    Commented Mar 8, 2022 at 14:32
7
$\begingroup$

In the weighted version of the Kaplan-Meier estimator you replace the number of events $d_i$ at time $t_i$ by the sum of the weights for the individuals who had events at that time. You replace the number at risk, $n_i$ by the sum of the weights for the individuals at risk.

The weights in the survival package are frequency weights; a weight of, say, 3 means the same as having 3 copies of that observation. If you gave every observation a weight of 3, you'd get the same point estimates, with standard errors that were $\sqrt{3}$ times smaller. Frequency weights give the same point estimates as sampling weights, but the standard error estimates are quite different.

In the Cox model, the weights are again frequency weights. Again, it's like having that many copies of the observation.

If your weights are actually sampling weights, the ideal approach is to use the survey package. It calls the survival package for the parts of the computation that can be done the same way, but does the standard error estimation differently.

$\endgroup$
1
  • $\begingroup$ Exact. Do you have any reference for the procedure to calculate the incidence density/ rate after weighting? See my question (bountied). Thank you $\endgroup$
    – geek45
    Commented Nov 6, 2023 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.