[R] Mixed Modeling in lme4

Indrajit Sengupta indrajitsg2013 at gmail.com
Tue Apr 30 08:26:11 CEST 2013


Hi All,

I am trying to shift from running mixed models in SAS using PROC MIXED
to using lme4 package in R. In trying to match the coefficients of R
output to that of SAS output, I came across this problem.

The dataset I am using is this one:

http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_mixed_sect034.htm

If I run the following code:

proc mixed data=rc method=ML covtest;
class Batch;
model Y = Month / s;
random Int Month / type=cs sub=Batch s;
run;

The Fixed effect coefficients match with that of R. But the random
effect does not. Here is the R code:

rc <- read.table('rc.csv', sep = ',', header=T, na.strings=".")

m1 <- lmer(formula = Y ~ Month + (Month|Batch), data = rc, REML = F)

summary(m1)

fixef(m1)

ranef(m1)

But if I change the SAS code as follows:

proc mixed data=rc method=ML covtest;
class Batch;
model Y = Month / s;
random Int / type=cs sub=Batch s;
run;

and the R code as follows:

m2 <- lmer(formula = Y ~ Month + (1|Batch), data = rc, REML = F)

summary(m2)

fixef(m2)

ranef(m2)

both fixed and random effect coefficients match. I am unable to
understand this discrepancy. Am I wrongly specifying the model in the
first case?

It would be helpful if someone can throw some light on this.

Regards,
Indrajit



More information about the R-help mailing list