[19202] in s-news-athena
Re: [S] Defining contrasts in factors
daemon@ATHENA.MIT.EDU (Prof Brian Ripley)
Mon Sep 13 10:17:04 1999
Message-Id: <199909131414.PAA17738@toucan.stats.ox.ac.uk>
Date: Mon, 13 Sep 1999 15:14:06 +0100 (BST)
From: Prof Brian Ripley <ripley@stats.ox.ac.uk>
Reply-To: Prof Brian Ripley <ripley@stats.ox.ac.uk>
To: s-news@wubios.wustl.edu, pierre.delfosse@centexbel.be
Mime-Version: 1.0
Content-Type: TEXT/plain; charset=us-ascii
Content-Md5: Kz2z01Yvua5OL+tOvOR1mw==
> From: Pierre Delfosse <pierre.delfosse@centexbel.be>
>
> I would like to understand how the dummy coefficients associated to a
> factor are computed in "lm" in function of the values of the matrix of
> contrasts.
dummy.coef (sic) might help you.
> Let y1, y2 and y3 be the mean response values for the 3 levels of a
> factor.
>
> Setting contrasts with
> > options(contrasts=c("contr.treatment","contr.poly"))
> we have the following matrix of contrasts
> > contr.treatment(3)
> 2 3
> 1 0 0
> 2 1 0
> 3 0 1
>
> and the "lm" coefficients of the factor are y2-y1 and y3-y1.
>
> Setting contrasts with
> > options(contrasts=c("contr.sum","contr.poly"))
> we have the following matrix of contrasts
> > contr.sum(3)
> [,1] [,2]
> 1 1 0
> 2 0 1
> 3 -1 -1
>
> and the "lm" coefficients of the factor are y1-ybar and y2-ybar.
>
> Setting contrasts with
> > options(contrasts=c("contr.helmert","contr.poly"))
> we have the following matrix of contrasts
> > contr.helmert(3)
> [,1] [,2]
> 1 -1 -1
> 2 1 -1
> 3 0 2
> and the "lm" coefficients of the factor are (y2-y1)/2 and
> (y3-(y1+y2)/2)/3.
>
> The "lm" coefficients are thus visibly not obtained by multiplying the
> columns of the matrix of contrasts with the (y1, y2, y3) vector.
No, because there are more terms in the model than just the contrasts,
in particular the grand mean, and because the contrasts define a X matrix,
and the `"lm" coefficients' are derived from (X^T X)^{-1} X^T, not X^T.
Try writing out the whole X matrix and then using this formula
algebraically.
> How are they then obtained? How can I define other contrasts if I do not
> know the way they are computed?
I suggest you read a good book on the subject. Chapter 6 of Venables &
Ripley (second or third edition) has a very good exposition by Venables ....
--
Brian D. Ripley, ripley@stats.ox.ac.uk
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 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news