[R] Calculating contrasts in Anova with interaction term

Lynn Govaert lynn.govaert at gmail.com
Thu Aug 21 11:12:56 CEST 2014


Hi all,

I have the following variables: a trait z,  Treatment A and B, Population 1
and 2 (each having undergo the treatment), and their interaction. Now, I'm
doing an Anova as follows

aov( z ~ Treatment * Population )

I now want to compare the values of population 1 which underwent treatment
A with the values of population 2 which underwent treatment B using
contrasts. I found a very useful explanation for calculating contrasts on
the internet (
http://r-eco-evo.blogspot.be/2007/10/one-of-most-neglected-topics-in_06.html),
however, they did not explain it for an interaction term. Now I thought, if
I just make a new variable for my interaction term, which is a categorical
variable having 4 levels (level 1: pop 1 with treatment A, level 2: pop 1
with treatment B, level 3: pop 2 treatment A and level 4: pop 2 treatment
B).

If I then construct my contrast vector as con <- c(1,0,0,-1)
Then do contrasts(data$trait) <- con
Then my model
model <- aov( z ~ Treatment + Population + InteractionTerm ) with the
InteractionTerm the new created variable
and then do what they did
summary(model, split = list(trait = list("comparison"=1)))
I get the following result

Treatment                    1 0.00246 0.00246   3.059   0.0816 .
Population                   1 0.05643 0.05643  70.241 4.75e-15 ***
IntTerm                        1 0.02869 0.02869  35.713 8.37e-09 ***
  IntTerm: comparison   1 0.02869 0.02869  35.713 8.37e-09 ***
Residuals                236 0.18959 0.00080

It is just so strange that the two last rows are exactly the same. So I
guess I'm doing something wrong.


As a second related question. I also found another method to calculate
contrasts. Using the Phia package in R. It works fine, but I don't find how
I can make a link between my two variables, so it takes pop 1 with
treatment A and pop 2 with treatment B to compare those two. I only find
how I can make combination within my treatment variable or within my
population variable. And that is not what I want. You can find the
information on
http://cran.r-project.org/web/packages/phia/vignettes/phia.pdf

If anyone knows what I'm doing wrong in the first example or if it makes
sence that they could be the same. Or an answer to my second question. I
would be very happy.

Thanks in advance!
Lynn

	[[alternative HTML version deleted]]



More information about the R-help mailing list