Numerical Differences in Survival Probability Estimates between coxph and cph Functions

I noticed slight differences in the predicted probabilities between coxph and cph Function, and the difference increases as the time increases. I set parameters to be the same and even obtained similar coefficient estimates. I noticed there was a similar question but, in my case, I set specific covariates in both functions.

Here are the codes from both functions:

From the coxph function:

S_t <- coxph(Surv(time = Y, event = d) ~ ns(age)+ns(psa)+tstage+deyo+gs+insurance+income+education+race, ties="breslow", data = data)

S_t_pred.obj <- survfit(S_t, stype=1, newdata=X, se.fit = FALSE)

S_t_pred.sum <- summary(S_t_pred.obj, times=c(3.452538, 9.724030, 131.384242, 150.000000), extend = TRUE)$surv

t(S_t_pred.sum[,1:5])
 3.452538     9.724030   131.384242    150.000000

1 0.9930111 0.9720974 0.1174563 1.462549e-68
2 0.9975552 0.9901719 0.4735629 2.113293e-24
3 0.9966625 0.9866011 0.3602773 4.624577e-33
4 0.9969770 0.9878579 0.3967149 5.207450e-30
5 0.9957809 0.9830846 0.2749658 1.276493e-41

From the cph function:

S_t1 <- cph(Surv(time = Y, event = d) ~ ns(age)+ns(psa)+tstage+deyo+gs+insurance+income+education+race, method="breslow", data = data, surv=T)

S_t_pred.sum1 <- survest(S_t1, stype=1, times=c(3.452538, 9.724030, 131.384242, 150.000000), newdata=X, se.fit = FALSE, extend = TRUE)$surv

S_t_pred.sum1[1:5,]
   3.452538     9.724030    131.384242   150.000000

1 0.9930182 0.9652215 0.1183159 0.0001055417
2 0.9975577 0.9877219 0.4747697 0.0409388941
3 0.9966659 0.9832685 0.3615318 0.0127198369
4 0.9969801 0.9848355 0.3979659 0.0192029730
5 0.9957852 0.9788867 0.2761774 0.0040062571

Is this difference due to some numerical approximations? I would greatly appreciate any insights or guidance on why these differences may be occurring. Thank you for your time.

ns is not part of rms. Use rcs for both coxph and cph and see what happens.

Thanks for the reply, are still differences with rcs. Also, the coefficient for ns were the same in both coxph and cph. If ns is not part of cph, why do I get the same coefficients with both functions.

The difference still persists even if I use rcs.

Coefficients will be the same; predicted values may not be the same if using ns.

I see. There are still differences though even if I use rcs.

If you can give me the smallest possible simple simulated example that fails I’ll dig into this. I need to be able to reproduce it. Or give me R code such as d <- data.frame(t=1:3, censor=c(1,0,1), x=...); ... cph..., data=d), ... coxph ... survest ... survfit.

Here is a reproducible example.

set.seed(1000)
dat <- data.frame(time = runif(100, 1, 150),
                  d = rbinom(100, 1, 0.7),
                  age = rnorm(100, mean= 50, sd = 10),
                  psa = runif(100, 0.2, 98),
                  race = factor(rbinom(100, 1, 0.6))
)


S_t <- coxph(Surv(time = time, event = d) ~ rcs(age)+ rcs(psa)+race, ties="breslow", data = dat)

S_t_pred.obj <- survfit(S_t, stype=1, newdata=dat, se.fit = FALSE)

S_t_pred.sum <- summary(S_t_pred.obj, times=c(3.452538, 9.724030, 131.384242, 150.000000), extend = TRUE)$surv

t(S_t_pred.sum[,1:5])

S_t1 <- cph(Surv(time = time, event = d) ~ rcs(age)+ rcs(psa)+race, method="breslow", data = dat, surv=T)

S_t_pred.sum1 <- survest(S_t1, stype=1, times=c(3.452538, 9.724030, 131.384242, 150.000000), newdata=dat, se.fit = FALSE, extend = TRUE)$surv

S_t_pred.sum1[1:5,]
1 Like

Sorry I didn’t get to this. Did you figure out anything else about the problem?