当用coxph(生存包)中的分层变量上的模型诊断时出错

发布于 2025-02-10 15:46:14 字数 1032 浏览 1 评论 0原文

我有一个数据集,其中有3个小组收到了对不同媒体的接触。一组暴露于3个媒体中的1个。因此,我的coxph模型是分层的:

# My treatment variable is loaded as a factor.
fullModel <- coxph(Surv(time, status) ~ strata(treatment), data = d) 

当我尝试执行模型诊断时,我会遇到此错误:

test.assump <- cox.zph(fullModel)
Error in cox.zph(fullModel) : 
there are no score residuals for a Null model

但是,如果删除Strata()参数,我可以在模型上运行诊断:

          chisq df    p
treatment  1.29  2 0.52
GLOBAL     1.29  2 0.52

我已经做了此示例来重现我的错误:

data <- list(time=c(4,3,1,1,2,2,3,2,4,1,3,4), 
             status=c(1,1,1,0,1,1,0,1,1,0,0,1),  
             treatment=c(0,0,0,0,1,1,1,1,2,2,2,2))

cox.test <- coxph(Surv(time, status) ~ strata(treatment), data = data)

test.coxas <- cox.zph(cox.test)
ggcoxzph(test.coxas)

ggcoxdiagnostics(test.coxas, type = "schoenfeld",
                 linear.predictions = F)

我应该在没有层次论点的情况下进行诊断吗?然后在之后使用地层参数,以便我可以在GGSURVPLOT中绘制不同的暴露? 我在哪里出错?

预先感谢您帮助我解决这一麻烦。

I have a dataset where 3 groups have recieved exposure to different media. One group is exposed to 1 of the 3 media. Therefore, my coxph model is stratified:

# My treatment variable is loaded as a factor.
fullModel <- coxph(Surv(time, status) ~ strata(treatment), data = d) 

When I try to do model diagnostics I get this error:

test.assump <- cox.zph(fullModel)
Error in cox.zph(fullModel) : 
there are no score residuals for a Null model

But, if I remove the strata() argument, I get to run diagnostics on the model:

          chisq df    p
treatment  1.29  2 0.52
GLOBAL     1.29  2 0.52

I've made this example to reproduce my error:

data <- list(time=c(4,3,1,1,2,2,3,2,4,1,3,4), 
             status=c(1,1,1,0,1,1,0,1,1,0,0,1),  
             treatment=c(0,0,0,0,1,1,1,1,2,2,2,2))

cox.test <- coxph(Surv(time, status) ~ strata(treatment), data = data)

test.coxas <- cox.zph(cox.test)
ggcoxzph(test.coxas)

ggcoxdiagnostics(test.coxas, type = "schoenfeld",
                 linear.predictions = F)

Should I do diagnostics without the strata argument? And then use the strata argument after so I can plot the different exposures in a ggsurvplot?
Where am I going wrong here?

Thank you in advance for helping me resolve this trouble.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甚是思念 2025-02-17 15:46:14

考虑到我对您的应用程序的理解,并且专注于您提出的实际问题,我正在括起来是否使用Strata()是最佳的建模选择。

Schoenfeld残留物用于诊断违反比例危害的COX模型的协变量。您的模型规范没有协变量。 ergo,您没有侵犯诊断和可能正确的pH违规行为,这就是为什么cox.zph正在抛出“ null Model”错误,就像在“此模型”中仅估算(Cox Model的AN)版本拦截术语”。

换句话说:Schoenfeld残留物是协变量特异性的,因此,如果Cox模型中没有协变量,则没有可以计算的Schoenfeld。 cox.zph的计算涉及Schoenfeld残差,因此错误。

相反,您有一个strata()术语。分层允许不同的组具有不同的基线危险率(从启发式上讲,Cox的拦截术语版本)。您可能会分层的原因有很多,但是其中之一是正确可能违反pH,这是一个使您首先运行cox.zph的问题。如果您继续对处理进行分层,则没有与pH相关的模型诊断供您运行。

(作为一方面:对于GGCOXDIAMGNOSTICS在您的MWE中,您需要传递coxph对象,而不是cox.zph对象。

I'm bracketing whether using strata() is the best modeling choice, given what I understand of your application, and focusing on the actual question you asked.

Schoenfeld residuals are used to diagnose proportional hazard violations a Cox model's covariates. Your model specification has no covariates. Ergo, you have no PH violations to diagnose and potentially correct, which is why cox.zph is throwing a "null model" error, as in "this model only estimates the (Cox model's version of an) intercept term".

Put differently: Schoenfeld residuals are covariate-specific quantities, so if there are no covariates in the Cox model, there are no Schoenfelds to calculate. cox.zph's calculations involve the Schoenfeld residuals, hence the error.

Instead, you have a strata() term. Stratifying permits different groups to have a different baseline hazard rate (= the Cox's version of an intercept term, heuristically speaking). There are many reasons you might stratify, but one of them is to correct for possible PH violations—the very issue that's leading you to run cox.zph in the first place. If you keep stratifying on treatment, there are no PH-related model diagnostics for you to run.

(As an aside: for ggcoxdiagnostics in your MWE, you need to pass in the coxph object, not the cox.zph object.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文