\Header{Contrast}{Contrast Matrices}
\alias{contr.helmert}{Contrast}
\alias{contr.poly}{Contrast}
\alias{contr.sum}{Contrast}
\alias{contr.treatment}{Contrast}
\keyword{design}{Contrast}
\keyword{regression}{Contrast}
\keyword{array}{Contrast}
\begin{Usage}
\begin{verbatim}
contr.helmert(n, contrasts=TRUE)
contr.poly(n, contrasts=TRUE)
contr.sum(n, contrasts=TRUE)
contr.treatment(n, base=1, contrasts=TRUE)
\end{verbatim}
\end{Usage}
\begin{Value}
A matrix with \texttt{n} rows and \texttt{k} columns,
with \texttt{k=n-1} if \texttt{contrasts} is \texttt{TRUE}
and \texttt{k=n} if \texttt{contrasts} is \texttt{FALSE}.

The base argument to \texttt{contr.treatment()} allows you to specify
which group is considered the baseline group.

These functions are used for creating contrast matrices
for use in fitting analysis of variance and regression models.
The columns of the resulting matrices contain contrasts
which can be used for coding a factor with \texttt{n} levels.
The returned value contains the computed contrasts.
If the argument \texttt{contrasts} is \texttt{FALSE} then an
additional column of ones is prepended to the matrix.

Note that as from \R\ version 0.62.2, \texttt{contr.poly} returns contrasts
based on orthogonal (rather than raw) polynomials.\end{Value}
\begin{SeeAlso}
\texttt{\Link{contrasts}}, \texttt{\Link{C}}, and
\texttt{\Link{aov}}, \texttt{\Link{glm}}, \texttt{\Link{lm}}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
(cH <- contr.helmert(4))
apply(cH, 2,sum)# column sums are 0!
crossprod(cH)# diagonal -- columns are orthogonal

(cT <- contr.treatment(5))
all(crossprod(cT) == diag(4))# TRUE: even orthonormal

(cP <- contr.poly(3))# Linear and Quadratic
zapsmall(crossprod(cP), dig=15) # orthonormal up to fuzz
\end{ExampleCode}
\end{Examples}

