I am trying to compare two levels of a factor aggregated over the levels of another one using the multcomp package.
I use a "between-subjects-version" of the dataset obk.long contained in the afex package which I computed like this:
library(dplyr) library(afex) data(obk.long) obk <- obk.long%>% group_by(id)%>% mutate(treatment,value = mean(value))%>% distinct(id) obk <- data.frame(obk)
It is now possible to test several contrasts by doing the following.
fit <- lm(value~treatment*gender,data=obk) summary(fit) # test for difference in A and B when gender = F K <- matrix(c(0, 1,-1,0,0,0),1) t <- glht(fit, linfct = K) summary(t)
So far so good, but what if I want to compare A versus B aggregated over the levels of gender? I was thinking about this approach:
K <- matrix(c(0, 0.5,-0.5,0,0.5,-0.5),1) t <- glht(fit, linfct = K) summary(t)
Alternatively, I could fit another model without gender
fit2 <- lm(value~treatment,data=obk) summary(fit2) K <- matrix(c(0, 1,-1),1) t <- glht(fit2, linfct = K) summary(t)
but the results are not the same. This is probably due to the interaction?
What is the right (best) way to test this contrast using multcomp?