Skip to content

Bug in weights in lmer

4 messages · Nick Isaac, Doran, Harold, Luca Borger

#
I have unearthed a bug in the way lmer() deals with weights.

Adding weights causes an inflation of the variance estimates. The
phenomenon is easily demonstrated by comparing the following models,
all of which should be identical:

w<-rep(1,nrow(sleepstudy))
(fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy) )
(fm2 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy, weights = w) )
(fm3 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy, weights = w/sum(w)) )

I have tried this with other datasets and models and find the same
general pattern. I find that the inflation factor is correlated with
sum(w) and is higher for cross-classified models than simple nested
ones.

The fixed effect estimates are also changed.

Best wishes, Nick
R version 2.6.2 (2008-02-08)
i386-apple-darwin8.10.1

locale:
en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] lme4_0.999375-13  Matrix_0.999375-7 lattice_0.17-6

loaded via a namespace (and not attached):
[1] grid_2.6.2
#
I'm confused. When I run this, I get the exact same answers for all
three models for all variance components and for all fixed effects. See
my results below. Where is the bug?
[1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1
 [38] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1
 [75] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1
[112] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1
[149] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Linear mixed-effects model fit by REML 
Formula: Reaction ~ Days + (Days | Subject) 
   Data: sleepstudy 
  AIC  BIC logLik MLdeviance REMLdeviance
 1754 1770 -871.8       1752         1744
Random effects:
 Groups   Name        Variance Std.Dev. Corr  
 Subject  (Intercept) 610.835  24.7151        
          Days         35.056   5.9208  0.067 
 Residual             655.066  25.5943        
number of obs: 180, groups: Subject, 18

Fixed effects:
            Estimate Std. Error t value
(Intercept)  251.405      6.820   36.86
Days          10.467      1.546    6.77

Correlation of Fixed Effects:
     (Intr)
Days -0.137
w) )
Linear mixed-effects model fit by REML 
Formula: Reaction ~ Days + (Days | Subject) 
   Data: sleepstudy 
  AIC  BIC logLik MLdeviance REMLdeviance
 1754 1770 -871.8       1752         1744
Random effects:
 Groups   Name        Variance Std.Dev. Corr  
 Subject  (Intercept) 610.835  24.7151        
          Days         35.056   5.9208  0.067 
 Residual             655.066  25.5943        
number of obs: 180, groups: Subject, 18

Fixed effects:
            Estimate Std. Error t value
(Intercept)  251.405      6.820   36.86
Days          10.467      1.546    6.77

Correlation of Fixed Effects:
     (Intr)
Days -0.137
w/sum(w)) )
Linear mixed-effects model fit by REML 
Formula: Reaction ~ Days + (Days | Subject) 
   Data: sleepstudy 
  AIC  BIC logLik MLdeviance REMLdeviance
 1754 1770 -871.8       1752         1744
Random effects:
 Groups   Name        Variance Std.Dev. Corr  
 Subject  (Intercept) 610.835  24.7151        
          Days         35.056   5.9208  0.067 
 Residual             655.066  25.5943        
number of obs: 180, groups: Subject, 18

Fixed effects:
            Estimate Std. Error t value
(Intercept)  251.405      6.820   36.86
Days          10.467      1.546    6.77

Correlation of Fixed Effects:
     (Intr)
Days -0.137
#
Thanks Harold - very curious.
See my results below. This sounds like a versioning issue, in which
case it would be good to get as many folk as possible to replicate it.

cheers, Nick
Linear mixed model fit by REML
Formula: Reaction ~ Days + (Days | Subject)
   Data: sleepstudy
  AIC  BIC logLik deviance REMLdev
 1756 1775 -871.8     1752    1744
Random effects:
 Groups   Name        Variance Std.Dev. Corr
 Subject  (Intercept) 612.095  24.7405
          Days         35.071   5.9221  0.065
 Residual             654.944  25.5919
Number of obs: 180, groups: Subject, 18

Fixed effects:
            Estimate Std. Error t value
(Intercept)  251.405      6.825   36.84
Days          10.467      1.546    6.77

Correlation of Fixed Effects:
     (Intr)
Days -0.138
+ w) )
Linear mixed model fit by REML
Formula: Reaction ~ Days + (Days | Subject)
   Data: sleepstudy
  AIC  BIC logLik deviance REMLdev
 1756 1775 -871.8     1752    1744
Random effects:
 Groups   Name        Variance Std.Dev. Corr
 Subject  (Intercept) 6640265  2576.87
          Days         380465   616.82  0.065
 Residual             7105115  2665.54
Number of obs: 180, groups: Subject, 18

Fixed effects:
            Estimate Std. Error t value
(Intercept)    975.9      710.8   1.373
Days           173.3      161.0   1.076

Correlation of Fixed Effects:
     (Intr)
Days -0.138
+ w/sum(w)) )
Linear mixed model fit by REML
Formula: Reaction ~ Days + (Days | Subject)
   Data: sleepstudy
   AIC BIC logLik deviance REMLdev
 820.9 840 -404.4    817.3   808.9
Random effects:
 Groups   Name        Variance  Std.Dev. Corr
 Subject  (Intercept) 169988830 13038.0
          Days          9739898  3120.9  0.065
 Residual               1010497  1005.2
Number of obs: 180, groups: Subject, 18

Fixed effects:
            Estimate Std. Error t value
(Intercept)    72.74    3596.47 0.02022
Days           12.92     814.61 0.01586

Correlation of Fixed Effects:
     (Intr)
Days -0.138
#
Hello,

in case this if of any interest, I obtained apparently the same results as 
Nick using:
R version 2.6.2 (2008-02-08)
i386-pc-mingw32

locale:
LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United 
Kingdom.1252;LC_MONETARY=English_United 
Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] lme4_0.999375-13  Matrix_0.999375-9 lattice_0.17-6

loaded via a namespace (and not attached):
[1] grid_2.6.2  tools_2.6.2
### Results:
Linear mixed model fit by REML
Formula: Reaction ~ Days + (Days | Subject)
   Data: sleepstudy
  AIC  BIC logLik deviance REMLdev
 1756 1775 -871.8     1752    1744
Random effects:
 Groups   Name        Variance Std.Dev. Corr
 Subject  (Intercept) 612.095  24.7405
          Days         35.071   5.9221  0.065
 Residual             654.944  25.5919
Number of obs: 180, groups: Subject, 18

Fixed effects:
            Estimate Std. Error t value
(Intercept)  251.405      6.825   36.84
Days          10.467      1.546    6.77

Correlation of Fixed Effects:
     (Intr)
Days -0.138
Linear mixed model fit by REML
Formula: Reaction ~ Days + (Days | Subject)
   Data: sleepstudy
  AIC  BIC logLik deviance REMLdev
 1756 1775 -871.8     1752    1744
Random effects:
 Groups   Name        Variance Std.Dev. Corr
 Subject  (Intercept) 6640265  2576.87
          Days         380465   616.82  0.065
 Residual             7105115  2665.54
Number of obs: 180, groups: Subject, 18

Fixed effects:
            Estimate Std. Error t value
(Intercept)    975.9      710.8   1.373
Days           173.3      161.0   1.076

Correlation of Fixed Effects:
     (Intr)
Days -0.138
Linear mixed model fit by REML
Formula: Reaction ~ Days + (Days | Subject)
   Data: sleepstudy
   AIC BIC logLik deviance REMLdev
 820.9 840 -404.4    817.3   808.9
Random effects:
 Groups   Name        Variance  Std.Dev. Corr
 Subject  (Intercept) 169992420 13038.1
          Days          9740118  3120.9  0.065
 Residual               1010516  1005.2
Number of obs: 180, groups: Subject, 18

Fixed effects:
            Estimate Std. Error t value
(Intercept)    72.74    3596.51 0.02022
Days           12.92     814.62 0.01586

Correlation of Fixed Effects:
     (Intr)
Days -0.138
Cheers,

Luca

---------------------------
Luca B?rger, PhD
Postdoctoral Research Fellow
Department of Integrative Biology
University of Guelph
Guelph, Ontario, Canada N1G 2W1
phone: +1 519 824 4120 ext. 54554
fax:     +1 519 767 1656


----- Original Message ----- 
From: "Nick Isaac" <njbisaac at googlemail.com>
To: "Doran, Harold" <HDoran at air.org>
Cc: <R-sig-mixed-models at r-project.org>
Sent: Wednesday, April 23, 2008 12:00 PM
Subject: Re: [R-sig-ME] Bug in weights in lmer