0
$\begingroup$

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)
$\endgroup$
4
  • $\begingroup$ I suppose I was trying to find out how to code it. $\endgroup$
    – Antonio
    Commented Dec 20, 2022 at 15:16
  • 1
    $\begingroup$ You test for significance of the set of spline terms. $\endgroup$
    – whuber
    Commented Dec 20, 2022 at 17:30
  • 2
    $\begingroup$ 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. $\endgroup$
    – EdM
    Commented Dec 20, 2022 at 17:47
  • $\begingroup$ @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. $\endgroup$
    – Antonio
    Commented Dec 21, 2022 at 13:41

0

Browse other questions tagged or ask your own question.