Sets the "contrasts"
attribute for the factor.
C(object, contr, how.many, …)
a factor or ordered factor
which contrasts to use. Can be a matrix with one row for
each level of the factor or a suitable function like
contr.poly
or a character string giving the name of the function
the number of contrasts to set, by default one less
than nlevels(object)
.
additional arguments for the function contr
.
The factor object
with the "contrasts"
attribute set.
For compatibility with S, contr
can be treatment
,
helmert
, sum
or poly
(without quotes) as shorthand
for contr.treatment
and so on.
Chambers, J. M. and Hastie, T. J. (1992) Statistical models. Chapter 2 of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.
# NOT RUN {
## reset contrasts to defaults
options(contrasts = c("contr.treatment", "contr.poly"))
tens <- with(warpbreaks, C(tension, poly, 1))
# }
# NOT RUN {
attributes(tens)
# }
# NOT RUN {
## tension SHOULD be an ordered factor, but as it is not we can use
aov(breaks ~ wool + tens + tension, data = warpbreaks)
## show the use of ... The default contrast is contr.treatment here
summary(lm(breaks ~ wool + C(tension, base = 2), data = warpbreaks))
# following on from help(esoph)
model3 <- glm(cbind(ncases, ncontrols) ~ agegp + C(tobgp, , 1) +
C(alcgp, , 1), data = esoph, family = binomial())
summary(model3)
# }
Run the code above in your browser using DataLab