# Differences in Confidence Intervals in Cox Model Predictions

**URL:** <https://discourse.datamethods.org/t/differences-in-confidence-intervals-in-cox-model-predictions/26583>\
**Category:** data analysis\
**Tags:** survival-analysis, prediction\
**Created:** [February 25, 2025, 1:59pm UTC](https://discourse.datamethods.org/t/differences-in-confidence-intervals-in-cox-model-predictions/26583 "2025-02-25T13:59:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ABohynDOE](https://discourse.datamethods.org/user_avatar/discourse.datamethods.org/abohyndoe/32/4929_2.png) [@ABohynDOE](https://discourse.datamethods.org/u/ABohynDOE)\
**Post date:** [February 25, 2025, 1:59pm UTC](https://discourse.datamethods.org/t/differences-in-confidence-intervals-in-cox-model-predictions/26583/1 "2025-02-25T13:59:42Z")

</div>

Hi everyone,

I’m trying to replicate the plot of relative hazard over age by sex from this [vignette](https://cran.r-project.org/web/packages/survival/vignettes/splines.pdf#page=11) from the **survival** package. However, I notice a difference in the confidence intervals (CIs) around the relative hazard estimates depending on how I compute them.

Specifically, I obtain different CIs when using:

1. `type = "lp"` in `predict()`, then computing the 95% CI from the standard error (SE) and exponentiating the results (as done in the vignette).
2. `type = "risk"` in `predict()`, then computing the 95% CI directly from the SE.

The confidence interval is narrower in the second case.

According to the help file of `predict.coxph`, `"risk"` is simply `exp(lp)`, so I would have expected the two approaches to yield the same results.

Does anyone have an idea why they differ?

Thanks in advance for your insights!

![image](https://discourse.datamethods.org/uploads/default/original/2X/1/12e1347b5d3de2585db0f66841e6a7ad688a24b1.png)

```auto
library(survival)
library(dplyr)
library(tinyplot)

fit <- coxph(Surv(futime, death) ~ sex * splines::ns(age, df =3), data = flchain)
pdata <- expand.grid(age = 50:99, sex = c("M", "F"))

lp_pred <- broom::augment(fit, newdata = pdata, type.predict = "lp", se = TRUE) |> 
  mutate(
    type = "lp",
    conf.low = .fitted - 1.96 * .se.fit,
    conf.high = .fitted + 1.96 * .se.fit,
    across(c(.fitted, conf.low, conf.high), exp)
  )

risk_pred <- broom::augment(
  fit, newdata = pdata, type.predict = "risk", se = TRUE
  ) |> 
  mutate(
    type = "risk",
    conf.low = .fitted - 1.96 * .se.fit,
    conf.high = .fitted + 1.96 * .se.fit
  )

pred <- rbind(lp_pred, risk_pred)

with(
  pred,
  tinyplot(
    x = age, y = .fitted, ymin = conf.low, ymax = conf.high, by = sex, 
    facet = type, type = "ribbon", log = "y"
  )
)

```

---

<div class="post-metadata">

**Author:** ![f2harrell](https://discourse.datamethods.org/user_avatar/discourse.datamethods.org/f2harrell/32/165_2.png) [@f2harrell](https://discourse.datamethods.org/u/f2harrell)\
**Post date:** [February 25, 2025, 9:15pm UTC](https://discourse.datamethods.org/t/differences-in-confidence-intervals-in-cox-model-predictions/26583/2 "2025-02-25T21:15:20Z")

</div>

Note that you don’t get relative risks form a Cox model. You get relative hazards.
