Skip to content

issues with weights in glmer (or glmmADMB) [SEC=UNCLASSIFIED]

1 message · Steve Candy

#
Ben Bolker <bbolker at ...> writes:
I have set up this small simulation to compare lmer{lme4} with lme{nlme} 
(with results compared also to asreml{asreml})

Note that lme and asreml give identical results for SEs of regression 
parameters while lmer SEs are an order of magnitude smaller.

I also give an asreml model that teases out the lev1 and lev2 variance 
components given a known lev1 variance.


## sample size weighted LMM
#
#
library(nlme)
library(lme4)
#generate some lognormal random effects (i.e. level-2)
Nsamp <- rep(0,50)
REs <- rnorm(n=50, mean=0, sd=0.3)
#generate some within residual errors (i.e. level-1)
RES <- NULL
Xf <- NULL
X <- NULL
for (i in 1:50) {
Nsamp[i] <- rpois(n=1,lambda=20)
RES <- c(RES,rep(REs[i],each=Nsamp[i]))
Xi <- as.integer(i/10)
X <- c(X,rep(Xi,each=Nsamp[i]))
Xf <- c(Xf,rep(i,each=Nsamp[i]))}

RES <- RES +  rnorm(n=length(RES), mean=0, sd=0.1)
RE.Xf <- as.factor(Xf)

#set up regression model
Y <- 1 + 5*X + RES

# calculate means and fit weighted LMM with random lack-of-fit term

Ym <- as.vector(tapply(X=Y, INDEX=RE.Xf, FUN=mean))
Xm <- as.vector(tapply(X=X, INDEX=RE.Xf, FUN=mean))

Xm.f <- as.factor(Xm)
wts <- 1/Nsamp

nlme.av <- lme(fixed=Ym ~ Xm, random=~1|Xm.f, weights=varFixed(~wts))
summary(nlme.av)

lmer.av <- lmer(formula=Ym ~ Xm + (1|Xm.f), weights=Nsamp)
summary(lmer.av)
+ Nsamp[i] <- rpois(n=1,lambda=20)
+ RES <- c(RES,rep(REs[i],each=Nsamp[i]))
+ Xi <- as.integer(i/10)
+ X <- c(X,rep(Xi,each=Nsamp[i]))
+ Xf <- c(Xf,rep(i,each=Nsamp[i]))}
fit term
Linear mixed-effects model fit by REML
 Data: NULL 
     AIC      BIC   logLik
  48.867 56.35181 -20.4335

Random effects:
 Formula: ~1 | Xm.f
         (Intercept) Residual
StdDev: 6.521819e-06 1.476964

Variance function:
 Structure: fixed weights
 Formula: ~wts 
Fixed effects: Ym ~ Xm 
               Value  Std.Error DF   t-value p-value
(Intercept) 0.876380 0.08709383 44  10.06248       0
Xm          5.036656 0.03275373  4 153.77353       0
 Correlation: 
   (Intr)
Xm -0.84 

Standardized Within-Group Residuals:
       Min         Q1        Med         Q3        Max 
-1.7507938 -0.7926107  0.1400055  0.6415305  2.0951252 

Number of Observations: 50
Number of Groups: 6
Linear mixed model fit by REML 
Formula: Ym ~ Xm + (1 | Xm.f) 
   AIC   BIC logLik deviance REMLdev
 196.2 203.8 -94.08    178.9   188.2
Random effects:
 Groups   Name        Variance Std.Dev.
 Xm.f     (Intercept) 0.00000  0.00000 
 Residual             0.11152  0.33395 
Number of obs: 50, groups: Xm.f, 6

Fixed effects:
            Estimate Std. Error t value
(Intercept) 0.876380   0.019693    44.5
Xm          5.036656   0.007406   680.1

Correlation of Fixed Effects:
   (Intr)
Xm -0.840
asreml(): 3.0.1 Library: 3.01gl X86_64  Run: Tue Jul 09 10:34:36 2013

     LogLik         S2      DF
     18.8188      2.1432    48  10:34:36  (1 component(s) restrained)
     22.5765      2.1637    48  10:34:36  (1 component(s) restrained)
     23.5813      2.1793    48  10:34:36  (1 component(s) restrained)
     23.6694      2.1813    48  10:34:36  (1 component(s) restrained)
     23.6752      2.1814    48  10:34:36  (1 component(s) restrained)
     23.6755      2.1814    48  10:34:36
     23.6755      2.1814    48  10:34:36
     23.6755      2.1814    48  10:34:36

Finished on: Tue Jul 09 10:34:36 2013
 
LogLikelihood Converged
$call
asreml(fixed = Ym ~ Xm, random = ~Xm.f, weights = Nsamp)

$loglik
[1] 23.67552

$nedf
[1] 48

$sigma
[1] 1.476964

$varcomp
                     gamma    component    std.error  z.ratio constraint
Xm.f!Xm.f.var 1.011929e-07 2.207444e-07 4.505927e-08 4.898979   Boundary
R!variance    1.000000e+00 2.181422e+00 4.452809e-01 4.898979   Positive

attr(,"class")
[1] "summary.asreml"
Xm (Intercept) 
  5.0366561   0.8763796
[1] 0.03275401 0.08709455
[1] 0.0004698345
[1] 1.476964
variance
family=asreml.gaussian(dispersion=0.01), weights=Nsamp)

asreml(): 3.0.1 Library: 3.01gl X86_64  Run: Tue Jul 09 10:45:14 2013

     LogLik         S2      DF
     19.5841      0.0100    48  10:45:14  (1 component(s) restrained)
     22.5914      0.0100    48  10:45:14  (1 component(s) restrained)
     23.1395      0.0100    48  10:45:14  (1 component(s) restrained)
     23.1885      0.0100    48  10:45:14  (1 component(s) restrained)
     23.1916      0.0100    48  10:45:14  (1 component(s) restrained)
     23.1918      0.0100    48  10:45:14
     23.1918      0.0100    48  10:45:14
     23.1918      0.0100    48  10:45:14

Finished on: Tue Jul 09 10:45:14 2013
 
LogLikelihood Converged
$call
asreml(fixed = Ym ~ Xm, random = ~Xm.f + RE.Xfs, family = asreml.gaussian
(dispersion = 0.01), 
    weights = Nsamp)

$loglik
[1] 23.19179

$nedf
[1] 48

$sigma
[1] 0.1

$varcomp
                         gamma    component  std.error  z.ratio constraint
Xm.f!Xm.f.var     1.011929e-07 1.011929e-07         NA       NA   Boundary
RE.Xfs!RE.Xfs.var 1.165194e-01 1.165194e-01 0.02389939 4.875413   Positive
R!variance        1.000000e-02 1.000000e-02         NA       NA      Fixed

attr(,"class")
[1] "summary.asreml"
[1] 0.0003181083
[1] 0.3413494
[1] 0.1
[1] 0.03346914 0.08534932
Xm (Intercept) 
  5.0336711   0.8798403
Dr Steven G. Candy
Senior Applied Statistician
Wildlife Conservation and Fisheries
Australian Antarctic Division
203 Channel Hwy, Kingston, Tasmania, 7050, Australia
ph: (+61) 3 62 323135