tags:

views:

343

answers:

2

I am sorry for asking such a basic question, but I can't seem to put my head around this or find a satisfying answer.

I checked ?contrasts and ?C - both lead to "Chapter 2 of Statistical Models in S", which is not readily available to me.

Under what cases do you create contrasts (in R) in your analysis? How is it done and what is it used for?

The more details the better.

(And again, sorry for the basic question)

Thanks,

Tal

+3  A: 

Contrasts are needed when you fit linear models with factors (i.e. categorical variables) as explanatory variables. The contrast specifies how the levels of the factors will be coded into a family of numeric dummy variables for fitting the model.

Here are some good notes for the different varieties of contrasts used: http://www.unc.edu/courses/2006spring/ecol/145/001/docs/lectures/lecture26.htm

When the contrasts used are changed, the model remains the same in terms of the underlying joint probability distributions allowed. Only its parametrization changes. The fitted values remain the same as well. Also, once you have the value of the parameters for one choice of contrasts, it is easy to derive what the value of the parameters for another choice of contrasts would have been.

Therefore the choice of contrasts has no statistical consequence. It is purely a matter of making coefficients and hypothesis tests easier to interpret.

Jyotirmoy Bhattacharya
+3  A: 

Take a look here (pages 365-370, which are free to view). On page 364 starts a one-way analysis of variance of a plant competition experiment. The code from page 364 that is missing is:

comp<-read.table("c:\\temp\\competition.txt",header=T)
attach(comp)
names(comp)
[1] "biomass" "clipping"
The categorical explanatory variable is clipping and it has five levels as follows:
levels(clipping)
...

The definition of contrasts is given later, on page 368 (in the homonym paragraph). If you want to follow the examples, you can download the datasets. See my post here.

It is out of the question that the book is highly recommended.

gd047