If I wanted to calculate confidence intervals using the coxph and confinf functions, how do I change the confidence interval calculation to log-log? My understanding is that log is the default.
I tried conf.type="log-log" but it did not work, just got an error message
library(survival)
coxph(formula = Surv(futime, fustat) ~ tx, data = tki, conf.type="log-log")
fit <- coxph(formula = Surv(futime, fustat) ~ tx, data = tki)
summary(fit)
#output provides HR CIs
confint(fit)
#coefficient CIs
exp(confint(fit))
> dput(tki) structure(list(futime = c(9.26, 11.06, 2.35, 3.75, 12.4, 10.3, 8.11, 7.29, 6.75, 6.56, 0.26, 1.9, 0.34, 1.63, 1.55, 1.6, 4.78, 2.65, 1.72, 3.63), fustat = c(1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1), tx = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -20L))
The log(-log()) method of producing confidence intervals applies to the estimates of survival probabilities (or related transformations). We need to use the
survfit()function to create those,confint()will not work. The default method islogas you note. Supplyingconf.type = "log-log"changes the method as desired.Note however, that the use of
survfit()with acoxph()model almost always requires you to correctly specify thenewdata =option. See the details in?survfit.coxph. Ignoring this will usually still give you some result, but it will be wrong in subtle ways.Created on 2023-02-21 with reprex v2.0.2
Reply to comment:
I think you have misunderstood something about how confidence intervals are calculated and what the different methods are estimating.
By default,
coxph()estimates the variance of the parameters using the inverse of the information matrix. An alternative is to use a "robust" variance estimate by enteringrobust = TRUEin thecoxph()call. (The robust estimate uses an infintisimal jackknife, see 2.7 of the package documentation vignette, https://cran.r-project.org/web/packages/survival/vignettes/survival.pdf .) Theconfint()function then uses the estimated variance to construct a "wald-type" confidence interval for the parameter estimates. Finally, taking theexp()of the confidence interval for the parameter estimate gives a confidence interval for the hazard ratio. (The code included in the question seems to have a mistake in labeling the confidence intervals. But, you can see the result matchessummary(fit).)At no point in the above calculations was a log or a log-log confidence interval used or available. If you try to include a
conf.type =option in thecoxph()call then it gives an error and refuses to run.The log method of calculating confidence intervals is the default for the
survfit()function. By specifyingconf.type =option in thesurvfit()function you can change the method used from "log" to any of the supported options: "log", "log-log", "plain", "none", "logit", or "arcsin".survfit()uses these methods to calculate a confidence interval for the survival probability.survfit()does not estimate the hazard ratio, it bases the estimate of the survival probability off of the hazard ratio that was estimated bycoxph().