Hi Indrajit,
In your first SAS code, change to type=un. cs imposes the (somewhat
dubious) assumption that the variance of both the intercept and slope are
equal. If you are using lme4, all random effects in a single block (e.g.,
(1 + month | batch) the 1 = intercept and month = random slope) will have
an unstructured (or freely estimated) variance covariance matrix.
Cheers,
Josh
On Mon, Apr 29, 2013 at 11:26 PM, Indrajit Sengupta <
indrajitsg2013@gmail.com> wrote:
> 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
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://joshuawiley.com/
Senior Analyst - Elkhart Group Ltd.
http://elkhartgroup.com
[[alternative HTML version deleted]]