如何用样条曲线绘制Cox危害模型 [英] How to plot a Cox hazard model with splines

查看:427
本文介绍了如何用样条曲线绘制Cox危害模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下模型:

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

其中fulength是随访时间(包括死亡率),预测因子是死亡率的预测因子。

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

如何绘制该模型,以便在y轴上获得具有95%置信带和危险比的优美曲线?我的目标与此类似:

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:

推荐答案

这是您在rms-package的?cph中运行第一个示例时得到的:

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

由于rms / Hmisc软件包组合使用格子图,因此带有边际年龄密度功能的注释将需要用晶格函数来完成。另一方面,如果您想将响应值更改为相对危险,则可以在Predict调用中添加一个'fun = exp'参数,然后使该图相关:

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()

这篇关于如何用样条曲线绘制Cox危害模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆