[R] car::Anova - Can it be used for ANCOVA with repeated-measures factors.
Henrik Singmann
henrik.singmann at psychologie.uni-freiburg.de
Sat Jul 21 19:29:04 CEST 2012
Dear list,
I would like to run an ANCOVA using car::Anova with repeated measures factors, but I can't figure out how to do it. My (between-subjects) covariate always interacts with my within-subject factors.
As far as I understand ANCOVA, covariates usually do not interact with the effects of interest but are simply additive (or am I wrong here?).
More specifically, I can add a covariate as a factor to the between-subjects part when fitting the MLM that behaves like expected (i.e., does not interact with the other factors), but when calling Anova on the model, I don't know how I can specify the between-within design (i.e., which parts of the model should interact with the repeated measures factors).
As far as I understand it, neither the idesign, icontrasts or imatrix arguments, nor the linearHypothesis function can specify the within-between design (as far as I get it they all specify the within or intra-subject design, see John Fox's slides from User 2011: http://web.warwick.ac.uk/statsdept/useR-2011/TalkSlides/Contributed/17Aug_1705_FocusV_4-Multivariate_1-Fox.pdf).
If this it is not possible using car::Anova, is there another way to achiebve what I want or is it plainly wrong?
I have the feeling that using R's "New Functions for Multivariate Analysis" (Dalgaard, 2007, R News) this could be possible, but some advice on how, would be greatly appreciated, as this does not seem to be the most straight forward way.
Below is an example using the car::OBrienKaiser dataset adding an age covariate. The example is merely an adoption from ?Anova with miniml changes and includes e.g. age:phase:hour which I don't want to have.
Note that I posted this question to stackoverflow two days ago (http://stackoverflow.com/q/11567446/289572) and did not receive any responses. Please excuse my "crossposting", but I think R-help may be the better place.
Best,
Henrik
PS: I know that the posting guide says "No questions about contributed packages" but there are some questions about car on R-help, so I thought this would be the correct place.
###### Example follows #####
require(car)
set.seed(1)
n.OBrienKaiser <- within(OBrienKaiser, age <- sample(18:35, size = 16, replace = TRUE))
phase <- factor(rep(c("pretest", "posttest", "followup"), c(5, 5, 5)), levels=c("pretest", "posttest", "followup"))
hour <- ordered(rep(1:5, 3))
idata <- data.frame(phase, hour)
mod.ok <- lm(cbind(pre.1, pre.2, pre.3, pre.4, pre.5, post.1, post.2, post.3, post.4, post.5,
fup.1, fup.2, fup.3, fup.4, fup.5) ~ treatment * gender + age, data=n.OBrienKaiser)
(av.ok <- Anova(mod.ok, idata=idata, idesign=~phase*hour, type = 3))
# Type II Repeated Measures MANOVA Tests: Pillai test statistic
# Df test stat approx F num Df den Df Pr(>F)
# (Intercept) 1 0.971 299.9 1 9 0.000000032 ***
# treatment 2 0.492 4.4 2 9 0.04726 *
# gender 1 0.193 2.1 1 9 0.17700
# age 1 0.045 0.4 1 9 0.53351
# treatment:gender 2 0.389 2.9 2 9 0.10867
# phase 1 0.855 23.6 2 8 0.00044 ***
# treatment:phase 2 0.696 2.4 4 18 0.08823 .
# gender:phase 1 0.079 0.3 2 8 0.71944
# age:phase 1 0.140 0.7 2 8 0.54603
# treatment:gender:phase 2 0.305 0.8 4 18 0.53450
# hour 1 0.939 23.3 4 6 0.00085 ***
# treatment:hour 2 0.346 0.4 8 14 0.92192
# gender:hour 1 0.286 0.6 4 6 0.67579
# age:hour 1 0.262 0.5 4 6 0.71800
# treatment:gender:hour 2 0.539 0.6 8 14 0.72919
# phase:hour 1 0.663 0.5 8 2 0.80707
# treatment:phase:hour 2 0.893 0.3 16 6 0.97400
# gender:phase:hour 1 0.700 0.6 8 2 0.76021
# age:phase:hour 1 0.813 1.1 8 2 0.56210
# treatment:gender:phase:hour 2 1.003 0.4 16 6 0.94434
# ---
# Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
--
Dipl. Psych. Henrik Singmann
PhD Student
Albert-Ludwigs-Universität Freiburg
http://www.psychologie.uni-freiburg.de/Members/singmann
More information about the R-help
mailing list