Stephen Politzer-Ahles
2012-Sep-07 18:46 UTC
[R] Contrasts for 2x4 interaction in mixed effects model
Hello everyone, I am running a mixed effects model where I have two fixed factors, one with 2 levels and one with 4, and their interaction. Let's say these are my factors and their levels: FirstFactor: 1, 2 SecondFactor: A, B, C, D For the interaction, I am interested in the four two-way comparisons, not the two four-way comparisons. In other words, I want to test whether 1A is significantly different than 2A, whether 1B is significantly different than 1B, etc; I am not interested in the comparison of 1A~1B~1C~1D. However, the latter comparisons are what the coefficients seem to give me when I summarize my model. For instance, the coefficient for the interaction term "FirstFactor2:SecondFactorB" doesn't tell me how different 2B is from 1B, it tells me how different 2B is from 2A. Is there a straightforward way to code the contrasts so that the coefficients I get for the interaction terms do the comparisons I'm interested in? Thank you for your advice, Steve Politzer-Ahles -- Stephen Politzer-Ahles University of Kansas Linguistics Department http://www.linguistics.ku.edu/ [[alternative HTML version deleted]]
Richard M. Heiberger
2012-Sep-07 20:51 UTC
[R] Contrasts for 2x4 interaction in mixed effects model
Stephen,
You are looking for the nesting of the FirstFactor within the SecondFactor.
Here is an example for your two-way design.
The model.matrix shows the dummy variables.
The last four columns show the two-level comparisons of Fir within each
level of Sec
Rich
tmp <- data.frame(y=rnorm(16),
Sec=rep(LETTERS[1:4], each=4),
Fir=rep(factor(1:2), 4, each=2))
contrasts(tmp$Fir) <- c(1, -1)
tmp.aov <- aov(y ~ Sec/Fir, data=tmp)
anova(tmp.aov)
cbind(tmp, model.matrix(tmp.aov)[, -1])
On Fri, Sep 7, 2012 at 2:46 PM, Stephen Politzer-Ahles <
politzerahless@gmail.com> wrote:
> Hello everyone,
>
> I am running a mixed effects model where I have two fixed factors, one with
> 2 levels and one with 4, and their interaction. Let's say these are my
> factors and their levels:
>
> FirstFactor: 1, 2
> SecondFactor: A, B, C, D
>
> For the interaction, I am interested in the four two-way comparisons, not
> the two four-way comparisons. In other words, I want to test whether 1A is
> significantly different than 2A, whether 1B is significantly different than
> 1B, etc; I am not interested in the comparison of 1A~1B~1C~1D.
>
> However, the latter comparisons are what the coefficients seem to give me
> when I summarize my model. For instance, the coefficient for the
> interaction term "FirstFactor2:SecondFactorB" doesn't tell me
how different
> 2B is from 1B, it tells me how different 2B is from 2A.
>
> Is there a straightforward way to code the contrasts so that the
> coefficients I get for the interaction terms do the comparisons I'm
> interested in?
>
> Thank you for your advice,
> Steve Politzer-Ahles
>
> --
> Stephen Politzer-Ahles
> University of Kansas
> Linguistics Department
> http://www.linguistics.ku.edu/
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
Stephen Politzer-Ahles
2012-Sep-11 12:46 UTC
[R] Contrasts for 2x4 interaction in mixed effects model
Hi Rachel,
Do you get what you need with
lmer(H.y.~(cond/patient)*stance + (1|subj), data=H)
? That should give you the comparison between patient groups at each level
of Condition (the cond1:patient1, cond2:patient2, and cond2:patient3 that
you were looking for). (And I guess it will also give interactions between
those and Stance; I haven't ever run a model like that myself, though.)
I'm new myself to mixed effects models and so I'm not sure if you need
to
do anything different from what I did to deal with the fact that your
"cond" variable is between-subjects (in my data that started this
thread,
all the variables were within-subjects). So you may want to check about
that as well.
Best of luck,
Steve
Message: 73
Date: Tue, 11 Sep 2012 00:22:21 -0700 (PDT)
From: semperparatus <robe0899@umn.edu>
To: r-help@r-project.org
Subject: Re: [R] Contrasts for 2x4 interaction in mixed effects model
Message-ID:
<CAN_X31jAmDXurD2bMoQJQ8W=FEnC8hw8AT+eVJSFabvAHOFmdg@mail.gmail.com>
Content-Type: text/plain
Thanks for your response. First time posting on any R forum, and apparently
I didn't read carefully enough to see the difference in my model. I much
appreciate the quick response.
On Tue, Sep 11, 2012 at 2:16 AM, David Winsemius [via R] <
ml-node+s789695n4642723h15@n4.nabble.com> wrote:
>
> On Sep 10, 2012, at 5:59 PM, semperparatus wrote:
>
> > I want to change it because I don't want to compare in this
instance
> between
> > conditions, but I simply want to see the contrast t-statistic between
> > patient and control at every level of condition (1, 2, and 3).
> >
> >> From there I'd like to be able to plot the t-statistic for the
contrast
> > between patient and control at level 1 of conditon, level 2 of
> condition,
> > and level 3 of condition, each with error bars.
> >
> > In the post I responded to the output gave fixed effect output for
> > SecA:Fir1, SecB:Fir1, SecC:Fir1, and SecD:Fir1. I'm hoping to get
the
> same
> > sort of output but for mine it would be Cond1:Patient1,
Cond2:Patient1,
> > Cond3:Patient1.
>
> It does not appear that you have the same situation as was being discussed
> earlier:
>
> Yours was:
>
> ' *When I tried using the syntax you used with my model:
> lmer(H.y. ~ patient*stance*cond +(cond/patient) + (1|subj), data=H), I
> got this
> result, which seems to be using condition 1 as a part of the baseline. Any
> idea how to change that?*'
>
> The other was:
>
> test <- lmer(Latency ~ (Nuisance1*Nuisance2) + (Sec/Fir) + (1|Subject) +
> (1|Item), datatotest)
>
> He had separated his nuisance parameters from the 2 variables (Sec and
> Fir) for which he was interested in examining contrasts.
>
> PLEASE learn to include context.
>
>
>
> --
> David Winsemius, MD
> Alameda, CA, USA
[[alternative HTML version deleted]]