Kevin Thorpe kev|n@thorpe @end|ng |rom utoronto@c@
Tue Jul 20 18:11:42 CEST 2021

```You might get better answers on the r-sig-ME list.

The lmer() function from lme4 handles crossed and non-nested random effects quite seamlessly. I cannot comment on whether or not lme() can as well.

--
Kevin E. Thorpe
Head of Biostatistics,  Applied Health Research Centre (AHRC)
Li Ka Shing Knowledge Institute of St. Michael's
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: kevin.thorpe using utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016

> On Jul 20, 2021, at 10:32 AM, Juan Liu <21707095 using zju.edu.cn> wrote:
>
> EXTERNAL EMAIL:
>
> Dear R project,
>
> I am a doctoral student in Zhejiang university in China, I am using lme function in nlme package and learning the function by Package 'nlme' document. I am writing this email for some help to build a lme model.
>
> My goal was to include two non-nested random effects in the lme model. the document described how to write the random effects while I found it difficult for me to understand. My problem are as below:
>
>
>
>
> In these model, site and year were considered as non nested effects. I want to set the structure in lme model the same as lmer model(the 1st model below), and I used the structure "random=list(site=~1,year=~1)"(the 2nd model below) . According to the result, the  lme model was obviously wrong, for the R2 and AIC were different from that of lmer model. I want to know to get the same result as lmer model, how should I set the random argument?
>
> Below is the model and results in R,
>
>
>
>
> ################################################################1. lmer function
> lmer<-lmer(data, y~x1+x2+x3+(1|site)+(1|year))
> r2(lmer)##58.8%；29.7%
> r.squaredGLMM(lmer)##58.8%; 29.72%;AIC=462.4
> ###################################################################2. lme1
> lme1<-lme(data, y~x1+x2+x3,random = list(site=~1,year=~1))
> r2(lme1)## NA(can't get the result)
> r.squaredGLMM(lme1)##92.4%; 30.89%;AIC=533
>
>
>
>
> I will be appreciated for your help.
>
>
>
>
> Yours sincerely,
>
> Juan Liu
>
> Juan Liu
>
> PhD candidate
>
> College of Life Sciences, Zhejiang University
>
>
> Zhejiang 310058, P.R.China
>
> 21707095 using zju.edu.cn； liujuan_1994 using outlook.com
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help