[R-sig-ME] contrasts among simple effects

Lenth, Russell V russell-lenth at uiowa.edu
Wed Oct 21 17:37:00 CEST 2015


I did not experience either of the problems you report running a very similar example -- see below. I wonder if you have some kind of masking problem, or need to start afresh or update your packages or your version of R. 

Russ
[PS - if you reply, please include me directly]
--
Russell V. Lenth  -  Professor Emeritus
Department of Statistics and Actuarial Science   
The University of Iowa  -  Iowa City, IA 52242  USA   
Voice (319)335-0712 (Dept. office)  -  FAX (319)335-3017


> library(nlme)
> Oats.lme <- lme(yield ~ Variety * ordered(nitro), ~ 1|Block/Variety, data = Oats)

> library(lsmeans)
> lsm <- lsmeans(Oats.lme, ~ Variety | nitro)

> lsm
nitro = 0.0:
 Variety        lsmean       SE df  lower.CL  upper.CL
 Golden Rain  80.00000 9.106959  5  56.58982 103.41018
 Marvellous   86.66667 9.106959  5  63.25648 110.07685
 Victory      71.50000 9.106959  5  48.08982  94.91018

nitro = 0.2:
 Variety        lsmean       SE df  lower.CL  upper.CL
 Golden Rain  98.50000 9.106959  5  75.08982 121.91018
 Marvellous  108.50000 9.106959  5  85.08982 131.91018
 Victory      89.66667 9.106959  5  66.25648 113.07685

nitro = 0.4:
 Variety        lsmean       SE df  lower.CL  upper.CL
 Golden Rain 114.66667 9.106959  5  91.25648 138.07685
 Marvellous  117.16667 9.106959  5  93.75648 140.57685
 Victory     110.83333 9.106959  5  87.42315 134.24352

nitro = 0.6:
 Variety        lsmean       SE df  lower.CL  upper.CL
 Golden Rain 124.83333 9.106959  5 101.42315 148.24352
 Marvellous  126.83333 9.106959  5 103.42315 150.24352
 Victory     118.50000 9.106959  5  95.08982 141.91018

Confidence level used: 0.95 


> pairs(lsm)
nitro = 0.0:
 contrast                   estimate       SE df t.ratio p.value
 Golden Rain - Marvellous  -6.666667 9.715029 10  -0.686  0.7766
 Golden Rain - Victory      8.500000 9.715029 10   0.875  0.6673
 Marvellous - Victory      15.166667 9.715029 10   1.561  0.3057

nitro = 0.2:
 contrast                   estimate       SE df t.ratio p.value
 Golden Rain - Marvellous -10.000000 9.715029 10  -1.029  0.5762
 Golden Rain - Victory      8.833333 9.715029 10   0.909  0.6470
 Marvellous - Victory      18.833333 9.715029 10   1.939  0.1783

nitro = 0.4:
 contrast                   estimate       SE df t.ratio p.value
 Golden Rain - Marvellous  -2.500000 9.715029 10  -0.257  0.9643
 Golden Rain - Victory      3.833333 9.715029 10   0.395  0.9184
 Marvellous - Victory       6.333333 9.715029 10   0.652  0.7955

nitro = 0.6:
 contrast                   estimate       SE df t.ratio p.value
 Golden Rain - Marvellous  -2.000000 9.715029 10  -0.206  0.9770
 Golden Rain - Victory      6.333333 9.715029 10   0.652  0.7955
 Marvellous - Victory       8.333333 9.715029 10   0.858  0.6775

P value adjustment: tukey method for comparing a family of 3 estimates 


> pairs(lsm, by = "Variety")
Variety = Golden Rain:
 contrast    estimate       SE df t.ratio p.value
 0 - 0.2   -18.500000 7.682957 45  -2.408  0.0900
 0 - 0.4   -34.666667 7.682957 45  -4.512  0.0003
 0 - 0.6   -44.833333 7.682957 45  -5.835  <.0001
 0.2 - 0.4 -16.166667 7.682957 45  -2.104  0.1673
 0.2 - 0.6 -26.333333 7.682957 45  -3.427  0.0069
 0.4 - 0.6 -10.166667 7.682957 45  -1.323  0.5533

Variety = Marvellous:
 contrast    estimate       SE df t.ratio p.value
 0 - 0.2   -21.833333 7.682957 45  -2.842  0.0328
 0 - 0.4   -30.500000 7.682957 45  -3.970  0.0014
 0 - 0.6   -40.166667 7.682957 45  -5.228  <.0001
 0.2 - 0.4  -8.666667 7.682957 45  -1.128  0.6744
 0.2 - 0.6 -18.333333 7.682957 45  -2.386  0.0944
 0.4 - 0.6  -9.666667 7.682957 45  -1.258  0.5938

Variety = Victory:
 contrast    estimate       SE df t.ratio p.value
 0 - 0.2   -18.166667 7.682957 45  -2.365  0.0988
 0 - 0.4   -39.333333 7.682957 45  -5.120  <.0001
 0 - 0.6   -47.000000 7.682957 45  -6.117  <.0001
 0.2 - 0.4 -21.166667 7.682957 45  -2.755  0.0406
 0.2 - 0.6 -28.833333 7.682957 45  -3.753  0.0027
 0.4 - 0.6  -7.666667 7.682957 45  -0.998  0.7514

P value adjustment: tukey method for comparing a family of 4 estimates



> Date: Mon, 19 Oct 2015 14:24:05 -0500
> From: James Henson <jfhenson1 at gmail.com>
> To: Thierry Onkelinx <thierry.onkelinx at inbo.be>
> Cc: "r-sig-mixed-models at r-project.org" <r-sig-mixed-models at r-project.org>
> Subject: Re: [R-sig-ME] contrasts among simple effects
> 
> Dear Russell,
> 
> Your assistance is appreciated. However, the code below returns an error message. Maybe my model is inappropriate. It was necessary to remove the ordered statement [ordered(time)], because apparently with the ordered statement lsmeans did not read time as a factor.
>
> library("nlme")
>
> # with AR1 variance/covariance structure
> heartRate$time <- factor(heartRate$time)
> 
> model2a <- lme(HR ~ drug*time, random =~1|person, correlation =corAR1(form=~1|person), data = heartRate)
> 
> summary(model2a)
>
> library("lsmeans")
> 
> anova(model2a)
> 
> lsm <- lsmeans(model2a, ~ drug|time)
> 
> lsm
>
> Error in format.default(nm[j], width = nchar(m[1, j]), just = "left") :
>   4 arguments passed to .Internal(nchar) which requires 3
> 
> 
> pairs(lsm)
>
> pairs(lsm, by = "drug")
> 
> The Using lsmeans tutorial (Oct 9, 2015) illustrates the usefulness of the lsmeans package.
> 
> Best regards,
> 
> James F. Henson



More information about the R-sig-mixed-models mailing list