[R] contr.treatments query

From: Ted Harding <Ted.Harding_at_manchester.ac.uk>
Date: Tue, 20 May 2008 01:12:36 +0100 (BST)


Hi Folks,
I'm a bit puzzled by the following (example):

N<-factor(sample(c(1,2,3),1000,replace=TRUE)) unique(N)
# [1] 3 2 1
# Levels: 1 2 3

So far so good. Now:

contrasts(N)<-contr.treatment(3, base=1, contrasts=FALSE) contrasts(N)
# 1 2
# 1 1 0
# 2 0 1
# 3 0 0

whereas:

contr.treatment(3, base=1, contrasts=FALSE)
# 1 2 3
# 1 1 0 0
# 2 0 1 0
# 3 0 0 1

contr.treatment(3, base=1, contrasts=TRUE)
# 2 3
# 1 0 0
# 2 1 0
# 3 0 1

I can follow the last two fine -- they are what is implied by the code for contr.treatment().

Likewise:

contrasts(factor(Nlevs <-c(1,2,3)))
# 2 3
# 1 0 0
# 2 1 0
# 3 0 1

But why the different result when applied to N?

With thanks,
Ted.



E-Mail: (Ted Harding) <Ted.Harding_at_manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861
Date: 20-May-08                                       Time: 01:12:30
------------------------------ XFMail ------------------------------

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 20 May 2008 - 00:18:15 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 20 May 2008 - 07:30:39 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive