Quantcast

lmer() function

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

lmer() function

Ali Mahani
I'm trying to estimate a two-tier model with varying intercepts and slopes across 20 groups, with each group having about 50 observations and with no group predictor. I use the command lmer(y~x+(1+x | group)). But the result is a constant intercept (zero standard deviation, all 20 intercept values are the same). I'm puzzled; am I setting up my model wrong, or is the algorithm malfunctioning because the number of groups is too small for the lmer() function?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: lmer() function

Ben Bolker

Ali Mahani wrote
I'm trying to estimate a two-tier model with varying intercepts and slopes across 20 groups, with each group having about 50 observations and with no group predictor. I use the command lmer(y~x+(1+x | group)). But the result is a constant intercept (zero standard deviation, all 20 intercept values are the same). I'm puzzled; am I setting up my model wrong, or is the algorithm malfunctioning because the number of groups is too small for the lmer() function?
A reproducible example would be nice.  I seem to get reasonable answers
for a simulated case -- see below.

  Further discussion might be worth moving to the r-sig-mixed-models list.


set.seed(1001)
a <- rnorm(20)
b <- rnorm(20)
g <- factor(rep(1:20,each=50))
x <- runif(50*20)
y <- rnorm(50*20,a[g]+b[g]*x,1)

dat <- data.frame(x,y,g)
library(lme4)

L1 <- lmer(y~x+(1+x|g),data=dat)

 
> L1
Linear mixed model fit by REML
Formula: y ~ x + (1 + x | g)
   Data: dat
  AIC  BIC logLik deviance REMLdev
 2923 2953  -1456     2910    2911
Random effects:
 Groups   Name        Variance Std.Dev. Corr  
 g        (Intercept) 1.46933  1.21216        
                x           1.74461  1.32084  0.039
 Residual              0.94526  0.97224        
Number of obs: 1000, groups: g, 20

Fixed effects:
             Estimate Std. Error  t value
(Intercept)  0.054024   0.277936  0.19437
x           -0.001076   0.314719 -0.00342

Correlation of Fixed Effects:
  (Intr)
x -0.031

> sessionInfo()
R version 2.9.0 (2009-04-17)
i486-pc-linux-gnu

locale:
LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C

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

other attached packages:
[1] lme4_0.999375-29   Matrix_0.999375-23 lattice_0.17-22  

loaded via a namespace (and not attached):
[1] coda_0.13-4   grid_2.9.0    rjags_1.0.3-8 tcltk_2.9.0  
>

Loading...