Message-ID: <20061229141114.BQX86597@po-d.temple.edu>
Date: 2006-12-29T19:11:14Z
From: Richard M. Heiberger
Subject: coded to categorical variables in a large dataset
## The main reason for wanting such a coding is to use it in
## a linear model. Therefore, declare the variable to be a factor
## and use it directly.
tmp <- sample(1:5, 40, replace=TRUE)
tmpf <- factor(tmp)
tmp.y <- rnorm(40)
tmp.aov <- aov(tmp.y ~ tmpf)
summary(tmp.aov)
contrasts(tmpf)
update(tmp.aov, x=TRUE)$x[1:6,]
## If you really want to see the redundant column 1 of
## of the contrasts, that can be done with the statement
contrasts(tmpf)
contrasts(tmpf, how.many=5) <- contr.treatment(5, contrasts=FALSE)
contrasts(tmpf)
tmp2.aov <- aov(tmp.y ~ tmpf)
summary(tmp2.aov)
update(tmp2.aov, x=TRUE)$x[1:6,]