[R] How to get LSMEANS from linear mixed model?

Chuck Cleland ccleland at optonline.net
Tue Apr 24 13:31:19 CEST 2007


Yannan Jiang wrote:
> Hi there,
> 
>  
> 
> I am trying to run simulations using R with linear mixed model (lme). There
> are two factors in my fixed effect model, educ (treatment and control) and
> mth (visit 1, 2, and 3). What I want to obtain is the estimated treatment
> difference (treatment - control) at visit 3, plus the standard error and
> p-value. This can be easily obtained in SAS using lsmeans or estimate
> statements, but I am not sure how to do this in R. 
> 
>  
> 
> The fixed effects I obtained are as follows:
> 
>  
> 
> Fixed effects: ymth ~ educ * mth - 1 
> 
>                                     Value               Std.Error
> DF        t-value               p-value
> 
> educcont                       0.14814308       0.006232419      93
> 23.769758         0.0000
> 
> eductreat                       0.13696952       0.006255672      93
> 21.895254         0.0000
> 
> mthymth2                      0.00003759       0.006333043      165
> 0.005936           0.9953
> 
> mthymth3                      0.01075489       0.006251328      165
> 1.720416           0.0872
> 
> eductreat:mthymth2       0.00323847       0.008947291      165
> 0.361950           0.7179
> 
> eductreat:mthymth3       -0.01246565      0.008941306      165
> -1.394164          0.1651
> 
>  
> 
>  
> 
> The estimated treatment difference I am interested are:
> 
>  
> 
>  a<-0.14814308+0.01075489 
> 
>  b<-0.13696952+0.01075489-0.01246565
> 
>> b-a
> 
> [1] -0.02363921   (treatment effect at visit 3, same as SAS lsmean output)
> 
>  
> 
> But I don't know how to get the standard error and corresponding p-value for
> this estimate. Any of your helps on that would be greatly appreciated! 

  How about fitting the model this way?

df$mth <- relevel(df$mth, ref = "ymth3")
lme(ymth ~ educ * mth, random = ~ 1 | id, data = df)

  The coefficient for educ will contain the simple effect of educ at
mth=ymth3, along with a standard error and p-value.

> Thanks,
> 
> Yannan
> 
>  
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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. 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894



More information about the R-help mailing list