[R] Using multcomp::glht() with Anova object

John Fox jfox at mcmaster.ca
Wed Dec 5 18:39:30 CET 2012


Dear Steve,

Usually the best place to look for information about functions in the car package, along with the help files for the package, is the book with which the package is associated. In this case, there's an on-line appendix to the book on multivariate linear models which describes how to use the linearHypothesis() function in the car package with repeated measures: sec. 3.2 of <http://socserv.socsci.mcmaster.ca/jfox/Books/Companion/appendix/Appendix-Multivariate-Linear-Models.pdf>. I think that this should help you do what you want.

I hope this helps,
 John

------------------------------------------------
John Fox
Sen. William McMaster Prof. of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/

On Wed, 5 Dec 2012 11:09:44 -0600
 Stephen Politzer-Ahles <politzerahless at gmail.com> wrote:
> Hello everyone,
> 
> I've conducted a Type III repeated-measures ANOVA using Anova() from the
> car package, based on the suggestions at
> http://blog.gribblelab.org/2009/03/09/repeated-measures-anova-using-r/(option
> 3) and
> http://languagescience.umd.edu/wiki/EEG#ERP_ANOVA_in_R. My ANOVA has two
> factors: Condition (3 levels) and Region (6 levels) and their interaction.
> Below is code to run the Anova and get the model object (the data are at
> https://docs.google.com/open?id=0B6-m45Jvl3ZmOVFTYVpZYV9sUUk).
> 
> 
> data <- as.matrix( read.table( file="EEGpriming.txt", header=T, sep="\t") )
> 
> Condition <- c( rep("Cond1", 6), rep("Cond2", 6), rep("Cond3", 6) )
> Region <- factor( rep( c("la", "ma", "ra", "lp", "mp", "rp"), 3 ) )
> 
> library(car)
> 
> model.Anova <- Anova( lm(eeg ~ 1), idata=data.frame(Condition, Region),
> idesign=~Condition*Region ) )
> 
> I'm now trying to do post-hoc comparisons between all levels of Condition
> using glht() from the multcomp package. I do this using the way that has
> worked for me with lmer() objects in the past: set up a contrast matrix and
> then feed it to glht():
> 
> designmatrix <- matrix(0, nrow=3, ncol=18)
> rownames(designmatrix) <- c("Cond1_minus_Cond2", "Cond3_minus_Cond1",
> "Cond3_minus_Cond2")
> designmatrix[1, 1:6] <- 1
> designmatrix[1, 7:12] <- -1
> designmatrix[2, 1:6] <- -1
> designmatrix[2, 13:18] <- 1
> designmatrix[3, 13:18] <- 1
> designmatrix[3, 7:12] <- -1
> 
> library(multcomp)
> 
> glht( model.Anova, linfct=designmatrix )
> 
> However, when I give glht() an Anova object, I get the following error:
> 
> > glht( model.anova, linfct=designmatrix )
> Error in UseMethod("vcov") :
>   no applicable method for 'vcov' applied to an object of class "Anova.mlm"
> Error in modelparm.default(model, ...) :
>   no ‘vcov’ method for ‘model’ found!
> 
> Does anyone know how if it's possible to use glht with an Anova object? (I
> guess I can get these same comparisons by re-doing the anova using aov() or
> lme(), since I don't need the Huynh-Feldt corrections in the post-hoc
> tests...but I am just curious if i can do the post-hocs directly on my
> Anova object.)
> 
> Best,
> Steve Politzer-Ahles
> 
> -- 
> Stephen Politzer-Ahles
> University of Kansas
> Linguistics Department
> http://people.ku.edu/~sjpa/
> 
> 	[[alternative HTML version deleted]]
>




More information about the R-help mailing list