Martin Turcotte
2010-Mar-18 22:11 UTC
[R] Please Post Planned Contrasts Example in lme {nlme}
Hi I am running some linear and non-linear mixed effect models and would like to
do some planned contrasts (a priori contrasts)
I have looked in the help and in many forums and it seems possible to do so but
don't understand how to write the function and I couldn't find an
example in Pinheiro and Bates.
lme {nlme} has a contrasts argument but I can't understand how to code it.
Here is a simple example of my working lme model:
dependent variable: APHIDS: log (number of aphids)
Fixed effects: DAY (time) and TREATMENT ( 6 different aphid treatments)
Random effects: POPULATION (each population is counted through time)
lme.fit<-lme(log(APHIDS)~ DAY*TREATMENT, random = ~ DAY| POPULATION,data=
aphid.data)
My hypothesis testing focuses on comparing Treatments ~ 1 and 4 , and eventually
2 vs 5, and 3 vs 6.
Q1: How can I do planned contrasts on these pairs for the main effect of
TREATMENT?
Q2: Can I also do this for the interaction term (DAY*TREATMENT)?
Q3: Would this code work for a non-linear mixed effect model nlme( )
P.S. Even just posting a personal example or a link to one would be greatly
appreciated.
thanks for the help
these forums are incredibly helpful
Martin Turcotte
mart.turcotte@gmail.com
[[alternative HTML version deleted]]
Tobias Verbeke
2010-Mar-19 01:57 UTC
[R] Please Post Planned Contrasts Example in lme {nlme}
Hi Martin, Martin Turcotte wrote:> Hi I am running some linear and non-linear mixed effect models and would like to do some planned contrasts (a priori contrasts) > > I have looked in the help and in many forums and it seems possible to do so but don't understand how to write the function and I couldn't find an example in Pinheiro and Bates. > > lme {nlme} has a contrasts argument but I can't understand how to code it. > > Here is a simple example of my working lme model: > dependent variable: APHIDS: log (number of aphids) > Fixed effects: DAY (time) and TREATMENT ( 6 different aphid treatments) > Random effects: POPULATION (each population is counted through time) > > lme.fit<-lme(log(APHIDS)~ DAY*TREATMENT, random = ~ DAY| POPULATION,data= aphid.data) > > My hypothesis testing focuses on comparing Treatments ~ 1 and 4 , and eventually 2 vs 5, and 3 vs 6. > > Q1: How can I do planned contrasts on these pairs for the main effect of TREATMENT? > > Q2: Can I also do this for the interaction term (DAY*TREATMENT)? > > Q3: Would this code work for a non-linear mixed effect model nlme( )I would have a look at the multcomp package which allows for defining contrasts in a very convenient way and can deal a.o. with lme (from nlme) and mer (from lme4) objects. http://cran.r-project.org/web/packages/multcomp/index.html The package comes with several vignettes with example uses (also an lmer one IIRC). Best, Tobias
Liviu Andronic
2010-Mar-19 09:33 UTC
[R] Please Post Planned Contrasts Example in lme {nlme}
On 3/18/10, Martin Turcotte <mart.turcotte at gmail.com> wrote:> Hi I am running some linear and non-linear mixed effect models and would like to do some planned contrasts (a priori contrasts) > > I have looked in the help and in many forums and it seems possible to do so but don't understand how to write the function and I couldn't find an example in Pinheiro and Bates. >Did you try John Fox' appendix on mixed effects models [1]? Liviu [1] http://socserv.socsci.mcmaster.ca/jfox/Books/Companion/appendix.html