# [R] question about custom contrasts in ANOVA

From: Scot W McNary <smcnary_at_charm.net>
Date: Thu 25 Aug 2005 - 13:43:48 EST

Hi,

This seems to require a custom contrast statement for the interaction term. I have a toy example that seems to work as it should, but wonder if I've correctly created the contrast needed.

# toy interaction contrast example, 10 schools, 100 kids, 5 attenders (1)
# and 5 non-attenders (2) in each school

# make the data

school <- gl(10, 10)
attend <- gl(2, 5, 100)
# creates an interaction with schools 6 and 7
y <- c(sample(seq(450, 650, 1), 50), rep(c(rep(650, 5), rep(450, 5)), 2),

sample(seq(450, 650, 1), 30))

# anova

summary(aov(y ~ school * attend))

# graphically

Means <- tapply(y, list(school, attend), mean)

plot(Means[,1], col="red", type = "l", ylim = c(400,700))

points(Means[,2], col="blue", type = "l")

# create contrasts for hypothesis of interest
# school i attend j - school i attend j'
# for all schools

sxa <- interaction(school, attend)
sxam <- as.matrix(rbind(diag(1,10), diag(1,10) * -1)) contrasts(sxa) <- sxam

summary(aov(y ~ sxa), split=list(sxa=1:10), expand.split = T)

The actual problem has a few more schools, other covariates, considerably more students, and is somewhat unbalanced.

Thanks,

Scot

```--
Scot W. McNary  email:smcnary@charm.net

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help