\Header{C}{Sets Contrasts for a Factor}
\keyword{models}{C}
\begin{Usage}
\begin{verbatim}
C(object, contr, how.many, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\texttt{object}] a factor or ordered factor
\item[\texttt{contr}] which contrasts to use. Can be a matrix with one row for
each level of the factor or a suitable function like
\texttt{contr.poly} or a character string giving the name of the function
\item[\texttt{how.many}] the number of contrasts to set, by default one less
than \texttt{nlevels(object)}.
\item[\texttt{...}] Addtional arguments for the function \texttt{contr}.
\end{ldescription}
\end{Arguments}
\begin{Description}
Sets the \texttt{"contrasts"} attribute for the factor.\end{Description}
\begin{Details}
For compatibility with S, \texttt{contr} can be \texttt{treatment},
\texttt{helmert}, \texttt{sum} or \texttt{poly} (without quotes) as shorthand
for \texttt{contr.treatment} and so on.\end{Details}
\begin{Value}
The factor \texttt{object} with the \texttt{"contrasts"} attribute set.\end{Value}
\begin{Author}
B.D. Ripley\end{Author}
\begin{SeeAlso}
\texttt{\Link{contrasts}}, \texttt{\Link{contr.sum}}, etc.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
## reset contrasts to defaults
options(contrasts=c("contr.treatment", "contr.poly"))
data(warpbreaks)
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))

data(esoph) # 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}

