# Can I compare lme models with and without quadratic (polynomial) term?

I am running mixed-effects analysis using lme package in R. I am trying to understand whether a linear model or a polynomial curve would better capture the change in a variable over time.

I know that anova() can be used to make model comparisons. Can I also use anova() to compare a linear and a quadratic model?

Thank you.

• You can do that, but with 'lme' you have to be carefull; you should use method='ML' so you may not use REML because with REML the likelihoods are ''modified''. – user83346 Jul 15 '16 at 9:24

Yeah you can. anova() can be used for model comparison whenever two nested models are fitted to the same set of data. In this case you wish to compare a linear model

$y = \beta_0 + \beta_1 x$

$y = \beta_0 + \beta_1 x + \beta_2 x^2$

As long as nothing is different between the two model apart from the presence of the quadratic term ($\beta_2 x^2$) then this is a perfectly reasonable comparison to make.

(Strictly speaking, it should still be a reasonable comparison to make if there were other variables added in the quadratic model too, but it would no longer be a test of whether a model with a quadratic term is a better fit to the data than one with only a linear term.)

Edit: As fcop has pointed out. It's only appropriate to use anova() for comparisons between mixed effects models (such as those produced by lme() and g/lmer()) when they have been fit using maximum likelihood, rather than with REML.

• I think you have to be more specific; with lme you can do it, but you should use method='ML' because method='REML' uses a modified likelihood. – user83346 Jul 15 '16 at 9:25
• And one more question: I am planning to use orthogonal polynomials with poly() command. I can still do the comparison I guess, right? – Berna Jul 15 '16 at 9:30
• @Berna: fine, you should use 'ML' to compare the models, but once you decided on a model for the mean you should use REML because that method is better for estimating the variance. – user83346 Jul 15 '16 at 9:31
• @Berna yeah, using poly is fine. You'd compare one model containing, e.g., poly(x, 1) with another containing poly(x, 2). – Ian_Fin Jul 15 '16 at 9:33
• @Berna No need to say thanks. If you feel the answer has satisfactorily addressed your question then I'd encourage you to consider accepting it as an answer. – Ian_Fin Jul 15 '16 at 9:42