Sets Contrasts for a Factor (original) (raw)
Description
Sets the "contrasts"
attribute for the factor.
Usage
C(object, contr, how.many, ...)
Arguments
object | a factor or ordered factor |
---|---|
contr | which contrasts to use. Can be a matrix with one row for each level of the factor or a suitable function likecontr.poly or a character string giving the name of the function |
how.many | the number of contrasts to set, by default one less than nlevels(object). |
... | additional arguments for the function contr. |
Details
For compatibility with S, contr
can be treatment
,helmert
, sum
or poly
(without quotes) as shorthand for contr.treatment
and so on.
Value
The factor object
with the "contrasts"
attribute set.
References
Chambers JM, Hastie TJ (1992). “Statistical Models.” In Chambers JM, Hastie TJ (eds.), Statistical Models in S, chapter 2. Wadsworth & Brooks/Cole.
See Also
[contrasts](../../stats/help/contrasts.html)
, [contr.sum](../../stats/help/contr.sum.html)
, etc.
Examples
## reset contrasts to defaults
options(contrasts = c("contr.treatment", "contr.poly"))
tens <- with(warpbreaks, C(tension, poly, 1))
attributes(tens)
## 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)
[Package _stats_ version 4.6.0 Index]