On Sun, 20 Feb 2005, Lorin Hochstein wrote:

Hello all,

(Apologies in advance if my terminology is incorrect, I'm relatively new to R and statistics).

I have data from a factorial design with two treatments (CRF-23), and I'm trying to compute treatment-contrast interactions through analysis of variance. I can't figure out how to do contrasts properly, despite reading the help for "C" and "contrasts" functions.

(I'm actually trying to solve an exercise in a textbook: "Experimental Design" by Kirk, Ex. 9.7b).

Here's what my data looks like:

score <- c(12, 8,10, 6, 8, 4,
     10,12, 8, 6,10,14,
      9, 7, 9, 5,11,12,
      7,13, 9, 9, 5,11,
      8, 7, 3, 8,12,10,
     13,14,19, 9,16,14)
n <- 6
A <- gl(2,3*n,labels=c("a1","a2"))
B <- rep(gl(3,n,labels=c("b1","b2","b3")),2)

I understand how to test for the effects of A, B, and AB: summary(aov(score~A*B))

Let's say I want to compute some contrasts on B and see if there is an interaction with A. I try to specify a matrix with the columns being the different contrasts on B:

contrasts.B <- matrix(c(1,-1,0,1,0,-1,0,1,-1),nrow=3) I know the following is wrong:
summary(aov(score~A*B,contrasts=contrasts.B))


I know I'm doing multiple things wrong here, because R can't possibly know I want those contrasts to be for the "B" variable, and because passing a contrast matrix never seems to change the result no matter what I do, so clearly I misunderstand how contrasts work. Can anyone advise?

There are only be two independent contrasts for a three-level factor, so you need to choose what you really want.


You can't really have `an interaction with A' with a contrast on B: that is just another contrast.

(I really want the result for each contrast separately, so should I be passing one vector as an argument to contrasts?)

I am not at all sure what you want to do. Here is one possibility

contrasts(B) <- contrasts.B[, 1:2]
fit <- aov(score~A*B)
summary(fit, split=list(B=1:2), expand.split = T)

Another way to specify this is

fit <- aov(score~A*B, contrasts = list(B=contrasts.B[, 1:2]))

which gives a list (as specified in ?aov) and names B.

If you want to look at the patterns of contrasts, use model.tables(), and to assess a single contrast, use se.contrast (but beware of lack of independence, even collinearity, if using multiple contrasts). Here is one way:

cont <- c(1, -1)[A] * c(1, -1, 0)[B]
sum(cont) # 0
sum(cont*score)
se.contrast(fit, as.matrix(cont))

I hope that gives you some progress.

--
Brian D. Ripley,                  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to