0

I made a model with a splined variable.

coxph(Surv(time, DEATH_EVENT) ~ age+anaemia+creatinine_phosphokinase+
ns(ejection_fraction, knots=c(15))+serum_creatinine+hypertension, data=HF)

This is the code I used to check ejection_fraction's linearity. How can I check its linearity after I've applied a spline?

X <- HF$ejection_fraction
Y <- resid(reducedMod, type = "martingale")
plot(X, Y, pch = 20, col = "darkgray",
     xlab = "Ejection Fraction", ylab = "Martingale Residual")+
abline(h = 0) +
lines(smooth.spline(X, Y, df = 7), lty = 2, lwd = 2)
Antonio
  • 543
  • 1
  • 9
  • I suppose I was trying to find out how to code it. – Antonio Dec 20 '22 at 15:16
  • 1
    You test for significance of the set of spline terms. – whuber Dec 20 '22 at 17:30
  • 2
    If you've used a spline you already suspect that the relationship between outcome and predictor isn't strictly linear. To test for linearity per se, test the non-linear terms of the spline. That's probably not what you want here, however: you seem to want to see if the spline worked OK. For that you can proceed as you do for any predictor: start with the full model with the spline and plot its martingale residuals against the values of the continuous variable. The smoothed plot should be reasonably flat. – EdM Dec 20 '22 at 17:47
  • @EdM That's exactly what I wanted to know! I realize I never updated the model in the code above to the one with the spline. Thank You. – Antonio Dec 21 '22 at 13:41

0 Answers0