1

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?

spore234
  • 3,550
  • 6
  • 50
  • 76
  • 1
    Could you provide a reproducable example? – Bas Dec 16 '15 at 08:48
  • @Bas I'm sorry, there was a typo, it's library(nlme) of course – spore234 Dec 16 '15 at 08:52
  • How did I not see that?.. Anyways, the summary of both packages seems to yield the same result. After taking a look at the `str` of fit2, I came up with the following: `fit2@pp$delb` EDIT: misread your question, let me see if I can find the correct values per worker – Bas Dec 16 '15 at 09:12
  • It looks like the intercept for fit1 and fit2 are different, the `intercept + worker + machine` should yield the expected – Bas Dec 16 '15 at 09:39
  • @Bas what do you mean by that? How can I get these values fro mthe fit2 model? – spore234 Dec 16 '15 at 10:27

1 Answers1

3

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)
Raad
  • 2,675
  • 1
  • 13
  • 26