2

I have a question regarding lmerTest for approximating the degrees of freedom and p values for linear mixed model.

I just took stats class in R to help me with my behavior experiments in lab, so I am very new to this. When using R Studio, I can run the anova() after mounting the lmerTest library and I can see the results in my console, depicted below:

lmsocial <- lmer(social~ grps + stim + grps*stim + (1|cohort) +(1|subj))
library(lmerTest)
anova(lmsocial)

Analysis of Variance Table of type 3  with  Satterthwaite 
approximation for degrees of freedom
      Sum Sq Mean Sq NumDF DenDF F.value   Pr(>F)   
grps       22471   22471     1    21  5.5922 0.027747 * 
stim       54289   54289     1    22 13.5107 0.001326 **
grps:stim  40423   40423     1    22 10.0599 0.004416 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

However, below is the read out I get on my PDF when I knit in R Studio (same for knitting in HTML). The are no errors when knitting, just so info missing:

lmsocial <- lmer(social~ grps + stim + grps*stim + (1|cohort) +(1|subj))
library(lmerTest)
anova(lmsocial)

## Analysis of Variance Table
##           Df Sum Sq Mean Sq F value
## grps       1  22471   22471  5.5922
## stim       1  54289   54289 13.5107
## grps:stim  1  40423   40423 10.0599

Am I missing something? When trying to generate a report, it would be nice to display the resulting ANOVA table form lmerTest.

How can I get it to knit properly?

2 Answers2

1

lmerTest is doing something a bit sneaky, I haven't figured out what yet. In the meantime, it seems to work as long as you add an explicit print() statement:

library("lmerTest")
fm1 <- lmer(Reaction~Days + (Days|Subject),sleepstudy)
print(a1 <- anova(fm1))

(or print(anova(fm1)), or a1 <- anova(fm1); print(a))

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • Hi @BenBolker, I did attach the package and I also tried to explicitly print. Neither work. When print, I still get the default lme4 ANOVA table without the degrees of freedom and p values. Glad to see I am not the only one. I though this was a _user error_ type situation. – Matt Valdez Mar 20 '15 at 21:27
0

the lmerTest package needs to be attached before the specification of the lmer model. The following should work:

library(lmerTest) lmsocial <- lmer(social~ grps + stim + grps*stim + (1|cohort) +(1|subj)) anova(lmsocial)

alku
  • 56
  • 1