I would like to be able to compare 2 models as is often done as follows:

modelA <- lm(Ys ~ X1 + X2 + X3)
modelB <- lm(Ys ~ X1 + X2)
anova(modelA, modelB)

but instead of adding or removing a co-variate- my first model is a fixed effects model with a single time point per subject, and my second model is a mixed effects model with several time points per subject and grouped by subjectID:

modelA <- lm(Ys ~ X1 + X2 + X3) #e.g. 5 observations/subjects

modelB <- lme(Ys ~ X1 + X2 + X3, random= ~ 1 | subjectID) 
#e.g. same 5 subjects with 3 time points each= 15 observations

since chi-square with anova fails in this scenario, how should I compare them. Is there a specific package in R I should use? An F-test requires knowing what the d.f. are for a mixed model, which I am unclear on how to calculate.

Thanks for your help!


marked as duplicate by amoeba, kjetil b halvorsen, Peter Flom regression Mar 6 '18 at 11:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ You tagged the question with the label lme. Have you tried applying the function lmer within the {lme4} package? $\endgroup$ – Antoni Parellada Nov 25 '15 at 3:34