therneau / survival

Survival package for R
381 stars 104 forks source link

Add `confint()` method for `survfit`objects #226

Closed mccarthy-m-g closed 6 months ago

mccarthy-m-g commented 1 year ago

Problem

The documentation for ?survfit.object states that there is a so-called survfitconf routine that can be used to defer the computation of CI intervals until after fitting a model with survfit():

One change in survival version 3 is the addition of a survfitconf routine which will compute confidence intervals for a survfit object. This allows the computation of CI intervals to be deferred until later, if desired, rather than making them a permanent part of the object. Later iterations of the base routines may omit the confidence intervals.

However, searching through the survival repository doesn't return any hits for the term survfitconf anywhere but the documentation page quoted above, so it isn't clear to me what this is referring to. I thought it might have meant there was a confint.survfit() method in the package, but that isn't the case:

library(survival)

fit <- survfit(Surv(time, status) ~ x, data = aml)

confint(fit)
#> Error in UseMethod("vcov"): no applicable method for 'vcov' applied to an object of class "survfit"

Created on 2023-06-06 with reprex v2.0.2

The closest thing I could find was the survfitCI() function on the ?survival-internal page documenting internal survival functions, but given that this is intended to be an internal function I don't think this is what was meant by the survfitconf routine either.

Request

Would it be possible to add a confint.survfit() method to the package, and/or to clarify what the survfitconf routine refers to?

therneau commented 11 months ago

What would you suggest as the output of such a function? The function produces a curve, not a parameter. There is no sensible result for coef(fit) either.

therneau commented 11 months ago

To clarify: there is an interval function to calculate the confidence interval at each time point. If you look at fit <- survfit(Surv(time, status) ~ ph.ecog, data=lung) for instance, there are 216 time points: 64 for ph.ecog=0, then 104 for ph.ecog=1, .... Do you want to have a 216 by 2 matrix?

However, it is clear that I should remove that "helpful comment" from the documentation, since it is only confusing.