Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with rand() #4

Open
runehaubo opened this issue Feb 6, 2018 · 0 comments
Open

Problems with rand() #4

runehaubo opened this issue Feb 6, 2018 · 0 comments

Comments

@runehaubo
Copy link
Owner

runehaubo commented Feb 6, 2018

data("TVbo", package="lmerTest")
> fm <- lmer(Coloursaturation ~ TVset*Picture +
+              (-1 + TVset|Assessor), data=TVbo)
> lmerTest:::rand(fm) # bug
Error in parse(text = x, keep.source = FALSE) : 
  <text>:2:0: unexpected end of input
1: Coloursaturation~-1+TVset - 
   ^

This notation seems to test the entire RE-term despite fm and fm2 being identical:

> fm2 <- lmer(Coloursaturation ~ TVset*Picture +
+              (0 + TVset|Assessor), data=TVbo)
> fm3 <- lm(Coloursaturation ~ TVset*Picture, data=TVbo)
> lmerTest:::rand(fm2)
Analysis of Random effects Table:
               Chi.sq Chi.DF p.value    
TVset:Assessor   64.3      1   1e-15 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> -2*c(logLik(fm2, REML=TRUE) - logLik(fm3, REML=TRUE))
[1] -64.30212
> anova(fm, fm2)
refitting model(s) with ML (instead of REML)
Data: TVbo
Models:
object: Coloursaturation ~ TVset * Picture + (-1 + TVset | Assessor)
..1: Coloursaturation ~ TVset * Picture + (0 + TVset | Assessor)
       Df    AIC    BIC  logLik deviance Chisq Chi Df Pr(>Chisq)
object 19 590.88 652.77 -276.44   552.88                        
..1    19 590.88 652.77 -276.44   552.88     0      0          1

Test is incorrectly labelled:

> fm4 <- lmer(Coloursaturation ~ TVset * Picture + (TVset | Assessor), data=TVbo)
> fm5 <- lmer(Coloursaturation ~ TVset * Picture + (1 | Assessor), data=TVbo)
> anova(fm4, fm5, refit=FALSE)
Data: TVbo
Models:
..1: Coloursaturation ~ TVset * Picture + (1 | Assessor)
object: Coloursaturation ~ TVset * Picture + (TVset | Assessor)
       Df    AIC    BIC  logLik deviance  Chisq Chi Df Pr(>Chisq)    
..1    14 633.22 678.83 -302.61   605.22                             
object 19 598.17 660.06 -280.09   560.17 45.048      5  1.418e-08 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> lmerTest:::rand(fm4) # wrong test!!!!
Analysis of Random effects Table:
               Chi.sq Chi.DF p.value    
TVset:Assessor     45      5   1e-08 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Also note that fm, fm2 and fm4 are just reparameterizations of the same model.

rand() fails to throw an error when models (of which one is lm) are fitted in different datasets due to missing values:

> m <- lmer(Preference ~ sens2 + Homesize + (1 |Consumer:Income), data=carrots)
> lmerTest:::rand(m)
Analysis of Random effects Table:
                Chi.sq Chi.DF p.value    
Consumer:Income   51.9      1   6e-13 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> m2 <- lm(Preference ~ sens2 + Homesize, data=carrots)
> nrow(model.frame(m))
[1] 1161
> nrow(model.frame(m2))
[1] 1233

Unable to handle models without parentheses around random terms:

> fm <- lmer(Reaction ~ 1 + Days|Subject, sleepstudy)
> lmerTest:::rand(fm) ## Bug in lmerTest::rand
Error: Invalid grouping factor specification, Subject - (1 + Days | Subject) + (1 | Subject)
In addition: There were 12 warnings (use warnings() to see them)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant