我想要一个 R 函数,它将具有相同参考组的 cox 模型的多条样条曲线放在一个图上

问题描述 投票:0回答:0

我一直在关注这个线程,但由于我的工作环境(云计算服务器等)而面临一些不相关的问题:https://stackoverflow.com/questions/28385509/how-to-plot-a -cox-hazard-model-with-splines.

在打扰我心爱的 IT 专业人员修复我的云环境之前,我想知道是否有人知道另一种方法来制作我正在寻找的那种图表,由另一个变量分层的 cox 回归样条。

例如,如果我有这 2 个图,参考组是每个性别的每日卡路里摄入量 == 1075。

library(survival)

lung1 <- lung %>% filter(sex == 1)
fit <- coxph(Surv(time, status) ~ pspline(meal.cal, df = 5), data = lung1)
ptemp <- termplot(fit, se = TRUE, plot = FALSE)
percterm <- ptemp$meal.cal
center <- with(percterm, y[x==1075])
ytemp <- percterm$y + outer(percterm$se, c(0, -1.96,1.96), "*")
matplot(percterm$x, exp(ytemp - center), log = "y", type = "l", col = "2", lty = c(1,2,2))


lung2 <- lung %>% filter(sex == 2)
fit <- coxph(Surv(time, status) ~ pspline(meal.cal, df = 5), data = lung2)
ptemp <- termplot(fit, se = TRUE, plot = FALSE)
percterm <- ptemp$meal.cal
center <- with(percterm, y[x==1075])
ytemp <- percterm$y + outer(percterm$se, c(0, -1.96,1.96), "*")
matplot(percterm$x, exp(ytemp - center), log = "y", type = "l", col = "2", lty = c(1,2,2))

但我想要 1 个带有 2 条线的图和一个参考,例如,当男性的卡路里摄入量为 1075 时。

感谢您的帮助!

r spline cox-regression
© www.soinside.com 2019 - 2024. All rights reserved.