\HeaderA{C}{Sets Contrasts for a Factor}{C}
\keyword{models}{C}
\begin{Description}\relax
Sets the \code{"contrasts"} attribute for the factor.
\end{Description}
\begin{Usage}
\begin{verbatim}
C(object, contr, how.many, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{object}] a factor or ordered factor
\item[\code{contr}] which contrasts to use. Can be a matrix with one row for
each level of the factor or a suitable function like
\code{contr.poly} or a character string giving the name of the function
\item[\code{how.many}] the number of contrasts to set, by default one less
than \code{nlevels(object)}.
\item[\code{...}] additional arguments for the function \code{contr}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
For compatibility with S, \code{contr} can be \code{treatment},
\code{helmert}, \code{sum} or \code{poly} (without quotes) as shorthand
for \code{contr.treatment} and so on.
\end{Details}
\begin{Value}
The factor \code{object} with the \code{"contrasts"} attribute set.
\end{Value}
\begin{References}\relax
Chambers, J. M. and Hastie, T. J. (1992)
\emph{Statistical models.}
Chapter 2 of \emph{Statistical Models in S}
eds J. M. Chambers and T. J. Hastie, Wadsworth \& Brooks/Cole.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{contrasts}{contrasts}}, \code{\LinkA{contr.sum}{contr.sum}}, etc.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
## reset contrasts to defaults
options(contrasts=c("contr.treatment", "contr.poly"))
attach(warpbreaks)
tens <- C(tension, poly, 1)
attributes(tens)
detach()
## 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)
\end{ExampleCode}
\end{Examples}

