# Shouldn't the beta estimates always be the same using lm and lmer?

Can anyone tell me under what conditions the beta estimates differ between lm and lmer with a random intercept? I came across a situation where the fixed effect differed considerably. I thought the std errors should change but the fixed effects should remain unchanged. The difference does not seem to be due to having different cluster sizes or having a large number of clusters with a single observation.

I cannot supply the data but have concocted a simplified example below. In this case the correlation within clusters should be negligible.

library(lme4)
x=c(rep(0,10),rep(1,10))
y=rnorm(length(x),mean=3100,sd=400)-200*x
m=c(1,2,3,4,4,6,7,8,8,10,11,12,13,14,15,16,17,18,20,20)
summary(lm(y~x))
summary(lmer(y~x+(1|m)))

-
Just FYI, this question seems to be on the border between a question about statistical issues, & a question about the implementation of procedures in R. As such, I think it's OK here, but also may be appropriate on Stack Overflow. Please don't cross-post (SE strongly discourages this), however, if you don't get a satisfactory answer here after a reasonable period of time, you can ask to have it migrated. –  gung Aug 9 '12 at 16:22
I tried your code. And the mean function for both models seems to be the same? –  jkd Aug 10 '12 at 4:37
The effect for x changes from -160.9 to -126.7. The mean Y at X=1 changes from 2889 to 2912.3. Is this what you get? –  Gavin Aug 10 '12 at 13:27
The results are random. I won't get your same numbers. I was looking at your regression coefficient for x. I tried it a few times, and that coefficient is almost always the same or it differed by only a small amount. –  jkd Aug 10 '12 at 16:24
I forgot to set the seed! Sorry. Almost impossible to replicate now. Nonetheless, shouldn't they never differ at all? Not even by a small amount? –  Gavin Aug 11 '12 at 23:48
show 1 more comment

The results of a linear model and a linear mixed-model can differ if the design is unbalanced, i.e., the number of observations per cell is different.

First, consider a balanced design:

df <- data.frame(x = rep(0:1, each = 10), y = 1:20, m = rep(1:10, each = 2))

lm(y ~ x, df)
# Coefficients:
# (Intercept)            x
#         5.5         10.0

library(lme4)
lmer(y ~ x + (1 | m), df)
# Fixed effects:
#             Estimate Std. Error t value
# (Intercept)    5.500      1.414   3.889
# x             10.000      2.000   5.000


The regression coefficients do not differ between both models.

Now, consider an unbalanced design: (The number of observations per subject differs.)

df2 <- data.frame(x = rep(0:1, each = 10), y = 1:20, m = rep.int(1:10, times = rep(c(1, 3), times = 5)))

lm(y ~ x, df2)
# Coefficients:
# (Intercept)            x
#         5.5         10.0

library(lme4)
lmer(y ~ x + (1 | m), df2)
# Fixed effects:
#             Estimate Std. Error t value
# (Intercept)    8.752      1.643   5.325
# x              2.699      1.164   2.318


The result of the simple linear model is the same as in the first example, but the result of lmer changed.

-
Thank you for your response. In your example m ~ N(0,sigma2). So the slope estimate should be the same. Is the reason for the difference in slope coefficients in an unbalanced design that there is now opportunity for x to vary with m? I suppose my general question is what part of the model specification allows this behaviour. –  Gavin Aug 30 '12 at 13:13
@Gavin You are right. The reason for the differences between the regression coefficients is due to different effects between the instances of m. This behaviour is a result of including at least one random factor in the model formula. Hence, it generally is a basic part of mixed models. –  Sven Hohenstein Aug 30 '12 at 17:13