9
$\begingroup$

I have problems finding a solution regarding how to run a post-hoc test (Tukey HSD) after a 2-factor (both within-subjects) repeated-measures ANOVA in R. For the ANOVA, I've used the aov -function:

summary(aov(dv ~ x1 * x2 + Error(subject/(x1*x2)), data=df1))

After reading answers to other questions, I gathered that I would first have to re-run the ANOVA using some other fuction (e.g., lme). This is what I came up with.

Lme.mod <- lme(dv ~ x1*x2, random=list(subject=pdBlocked(list(~1, pdIdent(~x1-1), pdIdent(~x2-1)))), data=df1)
anova(Lme.mod)

Both main effects were significant, but there were no interaction effects. Then, I used these functions for the post-hoc comparisons:

summary(glht(Lme.mod, linfct=mcp(x1="Tukey")))
summary(glht(Lme.mod, linfct=mcp(x2="Tukey")))

However, there were some problems:

First of all, the R Help file says that "The mcp function must be used with care when defining parameters of interest in two-way ANOVA or ANCOVA models (...) multcomp version 1.0-0 and higher generates comparisons for the main effects only, ignoring covariates and interactions (older versions automatically averaged over interaction terms). A warning is given." And sure enough, I received the following warning message:

Warning message:
In mcp2matrix(model, linfct = linfct) :
covariate interactions found -- default contrast might be inappropriate

Another puzzling thing was that although both main effects were significant, there were no significant differences in the post-hoc comparisons for one of the factors (x1). I've never encountered this before. Are the scripts/analyses correct/appropriate, or is there something that I'm missing? Any help would be most appreciated!

$\endgroup$
2
  • $\begingroup$ Welcome to the site, @Jonna. Are you only interested in how to get R to do this? If so, this question would be off-topic for CV (see our FAQ), but on-topic for Stack Overflow. I can't tell if your question is about the nature of post-hoc tests w/ repeated measures data, or an algorithmic question about R coding. Please edit to clarify. (Note that if you just want to know about R, we can migrate your Q; please don't cross-post). $\endgroup$ Commented Feb 2, 2013 at 15:32
  • 1
    $\begingroup$ Thank you @gung! I guess my question has to do with both... I tried to clarify the problem by editing my post! $\endgroup$
    – Jonna
    Commented Feb 2, 2013 at 21:06

2 Answers 2

2
$\begingroup$

Would

df1$x1x2=interaction(df1$x1,df1$x2)
library(lmerTest)
Lme.mod <- lme(dv ~ x1x2, random=~1|subject,
               correlation=corCompSymm(form=~1|subject),
               data=df1)
anova(Lme.mod)
summary(glht(Lme.mod, linfct=mcp(x1x2="Tukey")))

be what you are after, i.e. do posthoc tests among all combinations of measurements levels of both factors x1 and x2? (I've also imposed compound symmetry, to make the lme result match that of the repeated measures aov call)

$\endgroup$
-2
$\begingroup$

Tukey Multicomparison Test

  1. Install multcomp package install.packages("multcomp")

  2. Make multcomp available for use library("multcomp")

  3. Check it is running - Explains what packages are currently open in R search()

Then use the function glht()

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.