\Header{cancor}{Canonical Correlations}
\keyword{multivariate}{cancor}
\begin{Usage}
\begin{verbatim}
cancor(x, y, xcenter=TRUE, ycenter=TRUE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\texttt{x}] numeric matrix (\eqn{n \times p_1}{n * p1}), containing the x
coordinates.
\item[\texttt{y}] numeric matrix (\eqn{n \times p_2}{n * p2}) of y coordinates.
\item[\texttt{xcenter}] logical or numeric vector of length \eqn{p_1}{p1},
describing any centering to be done on the x values before the
analysis.  If \texttt{TRUE} (default), subtract the column means,
If \texttt{FALSE}, do not adjust the columns.
Otherwise, a vector of values to be subtracted from the columns.
\item[\texttt{ycenter}] analogous to \texttt{xcenter}, but for the y values.
\end{ldescription}
\end{Arguments}
\begin{Description}
Compute the canonical correlations between \texttt{x} and \texttt{y}.
The canonical correlation analysis seeks
linear combinations of the y variables which are
well explained by linear combinations of the x variables.\end{Description}
\begin{Value}
A list containing the following components:
\begin{ldescription}
\item[\texttt{cor}] correlations.
\item[\texttt{xcoef}] estimated coefficients for the x variables.
\item[\texttt{ycoef}] estimated coefficients for the y variables.
\item[\texttt{xcenter}] the values used to adjust the x variables.
\item[\texttt{ycenter}] the values used to adjust the x variables.
\end{ldescription}
\end{Value}
\begin{References}
Hotelling H. (1936).
``Relations between two sets of variables''.
\emph{Biometrika}, \bold{28}, 321-327.

Seber, G. A. F. (1984).
\emph{Multivariate Analysis}. New York: Wiley, p. 506f.\end{References}
\begin{SeeAlso}
\texttt{\Link{qr}}, \texttt{\Link{svd}}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
data(savings)
pop <- savings[, 2:3]
oec <- savings[,-(2:3)]
str(cancor(pop, oec))

x <- matrix(rnorm(150), 50, 3)
y <- matrix(rnorm(250), 50, 5)
str(cxy <- cancor(x, y))
all(abs(cor(x %*% cxy$xcoef,
            y %*% cxy$ycoef)[,1:3] - diag(cxy $ cor)) < 1e-15)
all(abs(cor(x %*% cxy$xcoef) - diag(3)) < 1e-15)
all(abs(cor(y %*% cxy$ycoef) - diag(5)) < 1e-15)
\end{ExampleCode}
\end{Examples}

