0

我正在尝试绘制一个 cox 模型,并让它根据一个因子变量(shunttyp)显示 2 个组。我尝试了以下代码:

coxph.model <- coxph(Surv(days, sens)~male+ coceva + ptatot + diatot + compldich + duplflow1 + shunttyp, data=cox1df)

ggsurvplot(survfit(coxph.model), palette= "#2E9FDF", ggtheme = theme_minimal(), cox1df)

这成功地绘制了完整的模型。我对基于变量“shunttyp”的曲线感兴趣,该变量是一个因子变量。

但是下面的代码不起作用。

ggsurvplot(survfit(coxph.model), group.by = "shunttyp" ,data= cox1df)

或者

ggsurvplot(survfit(coxph.model), strata = c("shunttyp"), data = cox1df)

我尝试按照在线示例(sthda.com)进行操作,这导致我:

new_df <- with(cox1df, data.frame(male = c(1, 2), coceva = c(1,1), compldich = c(1, 1), shunttyp = c(1,1),ptatot = rep(mean(ptatot, na.rm = TRUE), 2),diatot = rep(mean(diatot, na.rm = TRUE), 2),duplflow1 = rep(mean(duplflow1, na.rm = TRUE), 2) ))

但老实说,我不知道这是否正确或我在这里做什么。

我的目标是得到一个看起来像这样的情节,但地层是 shunttyp=0 和 shunttyp=1。 在此处输入图像描述

我不知道如何到达那里,并且花了几天时间试图在网上找到答案。任何帮助都非常感谢。

4

0 回答 0