[英]implementing a non-linear relationship within a cox proportional hazards model using the survival package in R
I am modeling tree mortality based on tree census data. 我正在根据树木普查数据对树木死亡率进行建模。 People go out at various intervals, and record whether trees lived or died. 人们以不同的时间间隔外出,并记录树木是否生死。 I am using the coxph
function to run a cox proportional hazard model to analyze the probability of tree mortality as a function of several predictor variables. 我正在使用coxph
函数来运行cox比例风险模型,以将树木死亡率作为几个预测变量的函数进行分析。 The code looks like: 代码如下:
model <- coxph(S ~ x1 + x2 + x3, data = data)
However, one of my predictors, tree size, is actually expected to have a non-linear relationship with mortality probability. 但是,实际上我的预测因子之一是树的大小与死亡率的关系是非线性的。 Specifically, trees die a lot when they are small, the probability of death goes down as they reach a 'juvenile' stage and are an intermediate size, and then the mortality probability creeps back up as trees get older and larger in size. 具体来说,树木很小时会死亡很多,死亡的概率随着它们进入“少年”阶段而下降,并且处于中等大小,然后死亡概率随着树木的变大和变大而回升。 This creates a 'inverse J shaped' pattern between mortality probability and tree size. 这在死亡率概率和树木大小之间创建了“反J形”模式。 It looks like this: 看起来像这样:
How can I incorporate this non-linear relationship into the coxph framework? 如何将这种非线性关系合并到coxph框架中? If this is not possible, how else can I analyze the mortality probability in the R environment, using a JAGS model or something else? 如果这不可能,那么我如何使用JAGS模型或其他方法分析R环境中的死亡率概率?
Try: 尝试:
library(mgcv)
fit <- gam(S ~ s(x1, bs = 'cr', k = 10) + s(x2, bs= 'cr', k = 10) +
s(x3, bs = 'cr', k = 10), family = cox.ph(), data = data)
You can fit an additive Cox proportional hazards model , where all terms are non-linear splines. 您可以拟合加性Cox比例风险模型 ,其中所有项均为非线性样条曲线。 See ?cox.ph
for extensive examples. 有关更多示例,请参见?cox.ph
。
If you have not used mgcv
before, you may need to look at ?gam
and ?s
as well. 如果您以前没有使用过mgcv
,则可能还需要查看?gam
和?s
。 After model fitting, summary.gam()
, gam.check()
and predict.gam()
are your friends. 拟合模型后, summary.gam()
, gam.check()
和gam.check()
predict.gam()
是您的朋友。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.