简体   繁体   English

在 R 中使用 coxph(生存包)对分层变量进行模型诊断时出错

[英]Error when model diagnostics on stratified variable with coxph (survival package) in R

I have a dataset where 3 groups have recieved exposure to different media.我有一个数据集,其中 3 组已收到不同媒体的曝光。 One group is exposed to 1 of the 3 media.一组暴露于 3 种媒体中的一种。 Therefore, my coxph model is stratified:因此,我的 coxph 模型是分层的:

# 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:但是,如果我删除了 strata() 参数,我可以在模型上运行诊断:

          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?然后使用strata参数,这样我就可以在ggsurvplot中绘制不同的曝光? Where am I going wrong here?我在哪里错了?

Thank you in advance for helping me resolve this trouble.预先感谢您帮助我解决此问题。

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.考虑到我对您的应用程序的了解,并关注您提出的实际问题,我将使用strata()是否是最佳建模选择括起来。

Schoenfeld residuals are used to diagnose proportional hazard violations a Cox model's covariates . Schoenfeld 残差用于诊断 Cox 模型协变量的比例风险违规。 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".因此,您没有需要诊断和可能纠正的 PH 违规,这就是cox.zph抛出“空模型”错误的原因,如“此模型仅估计(Cox 模型的)截距项”。

Put differently: Schoenfeld residuals are covariate-specific quantities, so if there are no covariates in the Cox model, there are no Schoenfelds to calculate.换句话说:Schoenfeld 残差是特定于协变量的量,因此如果 Cox 模型中没有协变量,则无需计算 Schoenfeld。 cox.zph 's calculations involve the Schoenfeld residuals, hence the error. cox.zph的计算涉及 Schoenfeld 残差,因此存在误差。

Instead, you have a strata() term.相反,您有一个strata()术语。 Stratifying permits different groups to have a different baseline hazard rate (= the Cox's version of an intercept term, heuristically speaking).分层允许不同的组有不同的基线危险率(= Cox 版本的截距项,启发式地讲)。 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.您可能会分层的原因有很多,但其中一个是纠正可能的 PH 违规 - 正是这个问题导致您首先运行cox.zph If you keep stratifying on treatment , there are no PH-related model diagnostics for you to run.如果您继续对treatment进行分层,则没有可供您运行的与 PH 相关的模型诊断。

(As an aside: for ggcoxdiagnostics in your MWE, you need to pass in the coxph object, not the cox.zph object.) (顺便说一句:对于 MWE 中的ggcoxdiagnostics ,您需要传入coxph对象,而不是cox.zph对象。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM