[R] Treatment-Contrast Interactions

Lorin Hochstein lorin at cs.umd.edu
Sun Feb 20 16:50:39 CET 2005


Prof Brian Ripley wrote:

> 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.
>
[snip]

>>
>> 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)
>
>
> There are only be two independent contrasts for a three-level factor, 
> so you need to choose what you really want.

As it turns out, the contrasts I'm trying to compute are not 
independent. (This is just an exercise in a textbook...)

>
>> (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)

Ah, this gives me what we want! Unfortunately, since no pair of 
contrasts I have are independent, I have to compute them one at a time. 
This seems to work.

for(i in 1:3) {
  contrasts(B) <- contrasts.B[, i]
  fit <- aov(score~A*B)
  s <- summary(fit, split=list(B=1:2), expand.split = T)
  f <- s[[1]]$"F value"[6]
  print(f)
}


>
> 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'd like to understand this approach as well, but I can't reproduce my 
results using se.contrast. In particular, I get the same standard error 
even though I tried to use different contrasts:

 > c1 <- c(1,-1)[A]*c(1,-1,0)[B]
 > c2 <- c(1,-1)[A]*c(1,0,-1)[B]
 > c3 <- c(1,-1)[A]*c(0,1,-1)[B]
 > se.contrast(fit, as.matrix(c1))
Contrast 1
  14.24547
 > se.contrast(fit,as.matrix(c2))
Contrast 1
  14.24547
 > se.contrast(fit,as.matrix(c3))
Contrast 1
  14.24547



Lorin




More information about the R-help mailing list