Skip to content

ask for help about lme function

3 messages · Juan Liu, Kevin E. Thorpe, Bert Gunter

#
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

866 Yuhangtang Road, Hangzhou

Zhejiang 310058, P.R.China

21707095 at zju.edu.cn? liujuan_1994 at outlook.com
#
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.
#
The mixed models list is r-sig-mixed-models .

nlme:lme is not really designed for crossed random effects. IIRC, it's
possible, but not easy. As Kevin said, lme4:lmer is really what you should
use.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Tue, Jul 20, 2021 at 9:12 AM Kevin Thorpe <kevin.thorpe at utoronto.ca>
wrote: