Solved – What if linearity doesn’t hold in a cox model

cox-modelrregression

I have built a multivariable cox model with coxph(). However, I am unable to run ggcoxfunctional() on some of the variables because of missing data.

ggcoxfunctional(Surv(time, status=="failed") ~ wbc3, data = selr3cox)
Error in xy.coords(x, y) : 'x' and 'y' lengths differ.

If I run ggdiagnostics() on the cox.model with type="martingale" ,

ggcoxdiagnostics(res.cox, type = "martingale",
                 linear.predictions = FALSE, ggtheme = theme_bw())

I get a reasonably horizontal line. Does that mean linearity assumption for all the variables included in the model holds or must I still run ggcoxfunctional() on each variable (with imputed data) in the model?

Next, if after transforming a variable to make it linear is unsuccessful, am I right to think that variable should not be included in the model? How would one do multivariate analysis to check on the significance of that variable then?

The link below contains part of my data. Apologies if this question should appear on SO rather than Crossvalidated. Hope someone can help.

https://github.com/dcicantab5/recover-study.git

Best Answer

"'x' and 'y' lengths differ" is often a more serious programmatic problem.

I imagine that your selection/filtering 'status=="failed"' makes the y vector of shorter length. Your 'wbc3' variable does not get filtered in the same way.

Related Question