0

I'm comparing two mixed effects models to each other.

mod_1 <- lmer(firstfix ~ ps + cd + ps:cd + (1+ cd||subj) + (1+ ps||object), data = dat2, REML = FALSE)

mod_2 <- lmer(firstfix ~ ps  + ps:cd + (1+ cd||subj) + (1+ ps||object), data = dat2, REML = FALSE)

anova(mod_1, mod_2)

But the output of the anova() function is wrong. It looks like: enter image description here

The individual models give the correct output, so I'm not sure why the anova() function is being difficult? Thankful for any advice on what may be causing this or how to fix it.

  • 1
    Please provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example-aka-mcve-minimal-complete-and-ver). Also please include the output as text, not as a picture. What was the expected output? – Heikki Nov 23 '17 at 21:15
  • 1
    Have you somehow overwritten the anova function? (ie to reproduce try `summary(anova(almerModel))`). Does the error persist after restarting R? Does it work if you call the method explicitly `lme4:::anova.merMod(mod_1, mod_2)` ? – user20650 Nov 23 '17 at 21:52

2 Answers2

1

I strongly suspect that you typed summary(anova(mod_1,mod_2)) rather than just anova(mod_1,mod_2). I can get very similar output via

library(lme4)
mod_1 <- lmer(Reaction~Days+(Days|Subject),sleepstudy)
mod_2 <- lmer(Reaction~1+(Days|Subject),sleepstudy)
summary(anova(mod_1,mod_2))

whereas anova(mod_1,mod_2) is fine.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
-1

You could try by coding your interaction using a * rather than the semicolon when fitting the models :

lmer(firstfix ~ ps + ps*cd + (1+ cd||subj) + (1+ ps||object), data = dat2, REML = FALSE)

  • this is unlikely to be the issue. (Not downvoting, yet, as I guess there's a tiny chance that it's relevant.) – Ben Bolker Nov 24 '17 at 03:18
  • I believe you're right and that is irrelevant. Other thing I can think of is storing the anova before running it : > anova -> anova (...) And then you should more easily access it from your global environment – user9000006 Nov 24 '17 at 03:29