Reputation: 3640
I fit this model in nlme
:
library(nlme)
data("Machines")
fit1 <- lme(score ~ - 1 + Machine, random=~1|Worker, data=Machines)
I can get the coefficients with
> fit1$coefficients
$fixed
MachineA MachineB MachineC
52.35556 60.32222 66.27222
$random
$random$Worker
(Intercept)
6 -8.70711058
2 -1.59425968
4 -0.06931564
1 1.21035769
3 6.21174760
5 2.94858062
now I fit the same model in lme4
library(lme4)
fit2 <- lmer(score ~ -1 + Machine + (1|Worker), data=Machines)
I get the exact same fixed effects:
>summary(fit2)
...
Fixed effects:
Estimate Std. Error t value
MachineA 52.356 2.229 23.48
MachineB 60.322 2.229 27.06
MachineC 66.272 2.229 29.73
...
I now want the random effects per worker, they aren't displayed in the summary, but it must be this:
> fit2@u
[1] -5.34898187 -0.97939105 -0.04258222 0.74355106 3.81602197 1.81138210
why are they different from the nlme
results while the fixed effects are the same?
Upvotes: 1
Views: 269
Reputation: 2715
Use ranef()
to extract the random effects.
library(lme4)
library(nlme)
data("Machines")
fit1 <- lme(score ~ - 1 + Machine, random=~1|Worker, data=Machines)
ranef(fit1)
fit2 <- lmer(score ~ -1 + Machine + (1|Worker), data=Machines)
ranef(fit2)
Upvotes: 3