How to plot a Cox hazard model with splines

只愿长相守 提交于 2019-12-20 16:21:31

问题


I have a following model:

coxph(Surv(fulength, mortality == 1) ~ pspline(predictor))

where is fulength is a duration of follow-up (including mortality), predictor is a predictor of mortality.

The output of the command above is this:

                         coef  se(coef) se2    Chisq DF   p    
pspline(predictor), line 0.174 0.0563   0.0562 9.52  1.00 0.002
pspline(predictor), nonl                       4.74  3.09 0.200

How can I plot this model so that I get the nice curvy line with 95% confidence bands and hazard ratio on the y axis? What I am aiming for is something similar to this:


回答1:


This is when you get when you run the first example in ?cph of the rms-package:

n <- 1000
set.seed(731)
age <- 50 + 12*rnorm(n)
label(age) <- "Age"
sex <- factor(sample(c('Male','Female'), n, 
              rep=TRUE, prob=c(.6, .4)))
cens <- 15*runif(n)
h <- .02*exp(.04*(age-50)+.8*(sex=='Female'))
dt <- -log(runif(n))/h
label(dt) <- 'Follow-up Time'
e <- ifelse(dt <= cens,1,0)
dt <- pmin(dt, cens)
units(dt) <- "Year"
dd <- datadist(age, sex)
options(datadist='dd')
S <- Surv(dt,e)

f <- cph(S ~ rcs(age,4) + sex, x=TRUE, y=TRUE)
cox.zph(f, "rank")             # tests of PH
anova(f)
plot(Predict(f, age, sex)) # plot age effect, 2 curves for 2 sexes

Because the rms/Hmisc package combo uses lattice plots, annotation with a marginal age-density feature would need to be done with lattice-functions. On the other hand, if you want to change the response value to relative hazard you can just add a 'fun=exp' argument to the Predict call and relable the graph to get:

png(); plot(Predict(f, age, sex, fun=exp), ylab="Relative Hazard");dev.off()



来源:https://stackoverflow.com/questions/28385509/how-to-plot-a-cox-hazard-model-with-splines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!