0
$\begingroup$

I'm doing a linear mixed model using lme.

In my adjustement factors, I have a continuous varaible (named X1). And I want to check the linearity of this variable using a spline function or a fractional polynomial but I don't succeed.

Can someone help me ? How to do that ?

Ex with spline :

lme(Y ~ T + X + pspline(X1, 4), data = df, random = ~ T | SUBJECT )

But then, I don't know how to conclude for the linearity.

$\endgroup$

1 Answer 1

3
$\begingroup$

You can check for linearity using natural cubic splines from the splines package and a likelihood ratio test - note that you need to fit the model using maximum likelihood (not restricted maximum likelihood) because of the different fixed-effects parts. For example,

library("splines")
fm0 <- lme(Y ~ T + X + X1, data = df, random = ~ T | SUBJECT, method = "ML")
fm1 <- lme(Y ~ T + X + ns(X1, 4), data = df, random = ~ T | SUBJECT, method = "ML")
anova(fm0, fm1)
$\endgroup$
4
  • $\begingroup$ What is the difference between using a spline function like pspline(X1,4) and a natural cubic spline like in your example ? If the likelihood ratio test is significant, does this mean that the variable is not linear ? Thanks a lot for your answer. $\endgroup$
    – Lemon3
    Apr 11, 2019 at 19:28
  • $\begingroup$ Indeed, if the likelihood ratio test is significant it means that the model with the spline provides a better fit to the data than the model with the linear term. $\endgroup$ Apr 11, 2019 at 19:31
  • $\begingroup$ Dimitris, what strategy do you recommend for choosing the degrees of freedom for the ns() term in an lme model? $\endgroup$ Apr 11, 2019 at 22:34
  • $\begingroup$ Check Section 2.4 (slides 65-57) in my course notes for my suggestions: drizopoulos.com/courses/EMC/CE08.pdf $\endgroup$ Apr 12, 2019 at 4:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.