[R] LMER vs PROC MIXED estimates

David Winsemius dwinsemius at comcast.net
Wed Nov 7 08:13:51 CET 2012


On Nov 6, 2012, at 7:00 PM, sandip1006 wrote:

> Hi experts,
> 
> I have just about started to use R (after using SAS for more than 5 years)
> and still finding my way...I have been trying to replicate PROC MIXED
> results in LMER but noticed that the estimates are coming different.

Better practice would be to spell the R functions with proper capitalization, in this case none.
> 
> My SAS code is as follows (trying to randomise X2 and Intercept):
> PROC MIXED DATA = <DATASET NAME> NAMELEN=100 METHOD=REML MAXITER=1000;
> CLASS GEOGRAPHY;
> MODEL y = X1 X2 X3/SOLUTION;
> RANDOM INTERCEPT X2/SOLUTION SUBJECT = GEOGRAPHY;
> ODS OUTPUT SOLUTIONR=RANDOM_EFFECT;
> ODS OUTPUT SOLUTIONF= FIXED_EFFECT;
> RUN;
> 
> the equivalent code that I was writting in R is as follows:
> testdata <- read.csv("adstest.csv",header=TRUE,sep=",")
> attach(testdata)

Why are you attach()-ing 'testdata'?

> library(lme4)
> options(contrasts = c(factor = "contr.SAS",ordered = "contr.poly"))


> lmm.2=lmer(y~X1+X2+X3 + (X2|Geography),REML=TRUE,data=bigads)
> 
> I am not sure if I have got the R script/options correct...but I seem to be
> getting different estimates from the same dataset....

Why are you giving a different data argument to 'lmer' than the dataframe you read in from disk? And you should at the very least show the output of str() on both datasets.


> any help on this would be highly appreciated!!!! 

A more appropriate place to post this (with better description of the dataset) would be the Mixed Models SIG.

-- 
David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list