Why do I get empty results with ls_means statement in lmerTest?

376 views Asked by At

Here's my data:

subject     arm treat   bline   change
'subject1'  'L' N   6.3597  4.9281
'subject1'  'R' T   10.3499 1.8915
'subject3'  'L' N   12.4108 -0.9008
'subject3'  'R' T   13.2422 -0.7357
'subject4'  'L' T   8.7383  2.756
'subject4'  'R' N   10.8257 -0.531
'subject5'  'L' N   7.1766  2.0536
'subject5'  'R' T   8.1369  1.9841
'subject6'  'L' T   10.3978  9.0743
'subject6'  'R' N   11.3184  3.381
'subject8'  'L' T   10.7251  2.9658
'subject8'  'R' N   10.9818  2.9908
'subject9'  'L' T   7.3745   2.9143
'subject9'  'R' N   9.4863  -3.0847
'subject10' 'L' T   11.8132  -2.1629
'subject10' 'R' N   9.5287   0.1401
'subject11' 'L' T   8.2977   6.2219
'subject11' 'R' N   9.3691   0.7408
'subject12' 'L' T   12.6003  -0.7645
'subject12' 'R' N   11.7329  0.0342
'subject13' 'L' N   9.4918  2.0716
'subject13' 'R' T   9.6205  1.5705
'subject14' 'L' T   9.3945  4.6176
'subject14' 'R' N   11.0176 1.445
'subject16' 'L' T   8.0221  1.4751
'subject16' 'R' N   9.8307  -2.3697

When I fit a mixed model with treat and arm as factors:

m <- lmer(change ~ bline + treat + arm + (1|subject), data=change1)
ls_means(m, which = NULL, level=0.95, ddf="Kenward-Roger")

The ls_means statement returns no result. Can anyone help with what is going wrong?

2

There are 2 answers

3
Russ Lenth On BEST ANSWER

I too see empty results:

> ls_means(m, which = NULL, level=0.95, ddf="Kenward-Roger")
Least Squares Means table:

     Estimate Std. Error df t value lower upper Pr(>|t|)

  Confidence level: 95%
  Degrees of freedom method: Kenward-Roger 

However, the emmeans package works fine. You can use emmeans() or lsmeans() -- the latter just re-labels the emmeans() results. "Estimated marginal means" is a more generally-appropriate term.

> library(emmeans)
> lsmeans(m, "treat")
 treat lsmean   SE df lower.CL upper.CL
 N      0.996 0.72 15   -0.539     2.53
 T      2.290 0.72 15    0.755     3.82

Results are averaged over the levels of: arm 
Degrees-of-freedom method: kenward-roger 
Confidence level used: 0.95 

> lsmeans(m, "arm")
 arm lsmean    SE   df lower.CL upper.CL
 L     1.97 0.737 15.6    0.403     3.53
 R     1.32 0.737 15.6   -0.248     2.88

Results are averaged over the levels of: treat 
Degrees-of-freedom method: kenward-roger 
Confidence level used: 0.95 

I suspect that lmerTest::ls_means() does not support predictors of class "character". If you change treat and arm to factors, it may work.

7
Ben Bolker On

We're going to need more information. Here's a reproducible example that seems just fine:

set.seed(101)
library(lme4)
library(lmerTest)
dd <- expand.grid(subject=factor(1:40), arm=c("L","R"))
## replicate N/T in random order for each subject
dd$treat <- c(replicate(40,sample(c("N","T"))))
dd$bline <- rnorm(nrow(dd))
dd$change <- simulate(~bline+treat+arm+(1|subject),
                      newdata=dd,
                      newparams=list(beta=rep(1,4),
                                     theta=1,
                                     sigma=1))[[1]]

m <- lmer(change ~ bline + treat + arm + (1|subject), data=dd)
ls_means(m, which = NULL, level=0.95, ddf="Kenward-Roger")
##  Least Squares Means table:
##  
##      Estimate Std. Error   df t value   lower   upper  Pr(>|t|)    
## armL  1.37494    0.22716 55.6  6.0527 0.91981 1.83007 1.275e-07 ***
## armR  2.54956    0.22716 55.6 11.2235 2.09443 3.00469 6.490e-16 ***

My best guess at this point is that you are having some problem with model fitting. lmerTest can sometimes be opaque/swallow warnings or error messages. Did you get any warnings you neglected to tell us about? If you re-run the model with lme4::lmer(...) (i.e. use the basic version from lme4, not the augmented version in lmerTest), do you see any warnings?