首页 > 解决方案 > Residuals.cph error "you must specify x=TRUE in the fit"

问题描述

I am trying to analyze graphs showing deviance residuals for my covariates. I have created this cox model named res.cox1 as shown in the code below and then proceed to use the residuals.cph function. Turns out, I keep getting the error:

Error in residuals.cph(res.cox1, type = "deviance") : you must specify x=TRUE in the fit

I have tried to add x = TRUE, y = TRUE, surv = TRUE to my fit, but none of it is helping. I don't quite understand what's wrong with my code, as I did not have problems creating residual graphs when I used the coxph function. Reason why I insist on using the cph function is the because of rcs(). Using rcs() when I had my coxph function did not work out, hence why I am trying to make it work with cph.

I don't know what to do.

res.cox1 = cph(with(H, Surv(TimeAxis, new_totmort) ~ Ln_PWVx_AUS + rcs(MAP_PWV_AUS) + A_HRcarX_AUS + sex_AUS + age_scr_AUS + BMI_AUS + Ln_glukos_0_AUS + Current_smoking_AUS + BPlowering_AUS + Lipidlowering_AUS + Hypertension_AUS + Diabetes_confirmed_AUS + Had_CV_Treatment, x=TRUE))
resid(res.cox1, type = "deviance")

标签: rcox-regression

解决方案


尝试x=TRUE向外移动一步,使其仅用一个括号括起来。

res.cox1 = cph(with(H, Surv(TimeAxis, new_totmort) ~ Ln_PWVx_AUS + rcs(MAP_PWV_AUS) + A_HRcarX_AUS + sex_AUS + age_scr_AUS + BMI_AUS + Ln_glukos_0_AUS + Current_smoking_AUS + BPlowering_AUS + Lipidlowering_AUS + Hypertension_AUS + Diabetes_confirmed_AUS + Had_CV_Treatment), x=TRUE)
resid(res.cox1, type = "deviance")

推荐阅读