Re: [R] lme and lmer syntax

From: Doran, Harold <HDoran_at_air.org>
Date: Wed 26 Oct 2005 - 03:24:44 EST


There is an issue with implicit nesting in lmer. In your lme() model you nest block/irrigation/density/fertilizer. In lmer you need to do something like (I dind't include all of your variables, but I think the makes the point)

lmer(yield~irrigation*density*fertilizer+(1|fertilizer:density)+(1|density), data)

Which notes that fertilizer is nested in density.

Try this and then compare the results.

-----Original Message-----
From: r-help-bounces@stat.math.ethz.ch [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Ronaldo Reis-Jr. Sent: Tuesday, October 25, 2005 12:21 PM To: R-Help
Subject: Re: [R] lme and lmer syntax

Em Seg 24 Out 2005 18:08, Doran, Harold escreveu:
> Ronaldo
>
> See the article on lmer pasted below for syntax. It is the only
> current source documenting the code. In lmer(), the nesting structure
> for the ranmdom effects is handled in a slightly different way. If
> your observations are nested as you note, then you can use
>
> > lmer(y~x1 + x2 +(1|x1) + (1|x2), data)
>
> @Article{Rnews:Bates:2005,
> author = {Douglas Bates},
> title = {Fitting Linear Mixed Models in {R}},
> journal = {R News},
> year = 2005,
> volume = 5,
> number = 1,
> pages = {27--30},
> month = {May},
> url = {http://CRAN.R-project.org/doc/Rnews/},
> }
>

Hi,

I try this with a splitsplitplot example.

I make the correct model with aov, lme do compare with lmer.

But I cant make a correct model in lmer. Look that the aov and lme results are similars, but very different from lmer. In aov and lme is used the correct DF for each variable, in lmer it use a same DF for all? Denom=54.

What is my mistake?

Thanks
Ronaldo

> summary(splitplot)

     yield        block      irrigation   density   fertilizer
 Min.   : 60.00   A:18   control  :36   high  :24   N :24     
 1st Qu.: 86.00   B:18   irrigated:36   low   :24   NP:24     
 Median : 95.00   C:18                  medium:24   P :24     
 Mean   : 99.72   D:18                                        
 3rd Qu.:114.00                                               
 Max.   :136.00                                               

>
> attach(splitplot)
>
> m.aov <-
aov(yield~irrigation*density*fertilizer+Error(block/irrigation/density/fertilizer))
>
> summary(m.aov)

Error: block

          Df  Sum Sq Mean Sq F value Pr(>F)
Residuals  3 194.444  64.815               

Error: block:irrigation
           Df Sum Sq Mean Sq F value  Pr(>F) irrigation  1 8277.6  8277.6  17.590 0.02473 *
Residuals   3 1411.8   470.6                  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Error: block:irrigation:density
                   Df  Sum Sq Mean Sq F value  Pr(>F)  
density             2 1758.36  879.18  3.7842 0.05318 .
irrigation:density  2 2747.03 1373.51  5.9119 0.01633 *
Residuals          12 2787.94  232.33                  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Error: block:irrigation:density:fertilizer
                              Df  Sum Sq Mean Sq F value    Pr(>F)    
fertilizer                     2 1977.44  988.72 11.4493 0.0001418 ***
irrigation:fertilizer          2  953.44  476.72  5.5204 0.0081078 ** 
density:fertilizer             4  304.89   76.22  0.8826 0.4840526    
irrigation:density:fertilizer  4  234.72   58.68  0.6795 0.6106672    
Residuals                     36 3108.83   86.36                      
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

>
> library(nlme)
>
> m.lme <- lme(yield~irrigation*density*fertilizer,random=~1|
block/irrigation/density/fertilizer)
>
> anova(m.lme)
numDF denDF F-value p-value (Intercept) 1 36 2683.2245 <.0001 irrigation 1 3 31.0269 0.0114 density 2 12 3.7780 0.0534 fertilizer 2 36 11.4490 0.0001 irrigation:density 2 12 5.9023 0.0164 irrigation:fertilizer 2 36 5.5203 0.0081 density:fertilizer 4 36 0.8826 0.4841 irrigation:density:fertilizer 4 36 0.6795 0.6107
>
> library(lme4)
Loading required package: Matrix Loading required package: lattice
>
> g1 <- block:irrigation
> g2 <- block:irrigation:density
> g3 <- block:irrigation:density:fertilizer
>
> m.lmer <-
> lmer(yield~irrigation*density*fertilizer+(1|g1)+(1|g2)+(1|g3))
>
> anova(m.lmer)
Analysis of Variance Table Df Sum Sq Mean Sq Denom F value Pr(>F) irrigation 1 827.41 827.41 54.00 30.9203 8.546e-07 *** density 2 202.53 101.26 54.00 3.7842 0.028971 * fertilizer 2 612.76 306.38 54.00 11.4493 7.159e-05 *** irrigation:density 2 316.40 158.20 54.00 5.9120 0.004767 ** irrigation:fertilizer 2 295.45 147.72 54.00 5.5204 0.006586 ** density:fertilizer 4 94.48 23.62 54.00 0.8826 0.480561 irrigation:density:fertilizer 4 72.73 18.18 54.00 0.6795 0.609157 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ----- End of example ------ -- A divisão do trabalho é limitada pelo tamanho do mercado --Adam Smith -- |> // | \\ [***********************************] | ( õ õ ) [Ronaldo Reis Júnior ] |> V [UFV/DBA-Entomologia ] | / \ [36570-000 Viçosa - MG ] |> /(.''`.)\ [Fone: 31-3899-4007 ] | /(: :' :)\ [chrysopa@insecta.ufv.br ] |>/ (`. `'` ) \[ICQ#: 5692561 | LinuxUser#: 205366 ] | ( `- ) [***********************************] |>> _/ \_Powered by GNU/Debian Woody/Sarge ______________________________________________ R-help@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 ______________________________________________ R-help@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
Received on Wed Oct 26 03:28:52 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:47 EST