## 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,]
coded to categorical variables in a large dataset
1 message · Richard M. Heiberger