\Header{princomp}{Principal Components Analysis}
\alias{loadings}{princomp}
\alias{plot.princomp}{princomp}
\alias{predict.princomp}{princomp}
\alias{print.princomp}{princomp}
\alias{screeplot}{princomp}
\alias{summary.princomp}{princomp}
\keyword{multivariate}{princomp}
\begin{Description}\relax
\code{princomp} performs a principal components analysis on the given
data matrix and returns the results as an object of class
\code{princomp}.

\code{loadings} extracts the loadings.

\code{screeplot} plots the variances against the number of the
principal component. This is also the \code{plot} method.\end{Description}
\begin{Usage}
\begin{verbatim}
princomp(x, cor = FALSE, scores = TRUE, covmat = NULL,
         subset = rep(TRUE, nrow(as.matrix(x))))
loadings(x)
plot(x, npcs = min(10, length(x$sdev)),
          type = c("barplot", "lines"), ...)
screeplot(x, npcs = min(10, length(x$sdev)),
          type = c("barplot", "lines"), ...)

print(x, ...)  summary(object)  predict(object, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] a matrix (or data frame) which provides the data for the
principal components analysis.
\item[\code{cor}] a logical value indicating whether the calculation should
use the correlation matrix or the covariance matrix.
\item[\code{scores}] a logical value indicating whether the score on each
principal component should be calculated.
\item[\code{covmat}] a covariance matrix, or a covariance list as returned by
\code{\Link{cov.wt}}, \code{\Link{cov.mve}} or \code{\Link{cov.mcd}}.
If supplied, this is used rather than the covariance matrix of
\code{x}.
\item[\code{subset}] a vector used to select rows (observations) of the
data matrix \code{x}.
\item[\code{x, object}] an object of class \code{"princomp"}, as
from \code{princomp()}.
\item[\code{npcs}] the number of principal components to be plotted.
\item[\code{type}] the type of plot.
\item[\code{...}] graphics parameters.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The calculation is done using \code{\Link{eigen}} on the correlation or
covariance matrix, as determined by \code{\Link{cor}}.  This is done for
compatibility with the S-PLUS result.  A preferred method of
calculation is to use svd on \code{x}, as is done in \code{prcomp}.

Note that the default calculation uses divisor \code{N} for the
covariance matrix.

The \code{\Link{print}} method for the these objects prints the
results in a nice format and the \code{\Link{plot}} method produces
a scree plot.\end{Details}
\begin{Value}
\code{princomp} returns a list with class \code{"princomp"}
containing the following components:
\begin{ldescription}
\item[\code{sdev}] the standard deviations of the principal components.
\item[\code{loadings}] the matrix of variable loadings (i.e., a matrix
whose columns contain the eigenvectors).
\item[\code{center}] the means that were subtracted.
\item[\code{scale}] the scalings applied to each variable.
\item[\code{n.obs}] the number of observations.
\item[\code{scores}] if \code{scores = TRUE}, the scores of the supplied
data on the principal components.
\item[\code{call}] the matched call.
\end{ldescription}
\end{Value}
\begin{References}\relax
Mardia, K. V., J. T. Kent and J. M. Bibby (1979).
\emph{Multivariate Analysis}, London: Academic Press.

Venables, W. N. and B. D. Ripley (1997, 9).
\emph{Modern Applied Statistics with S-PLUS}, Springer-Verlag.\end{References}
\begin{SeeAlso}\relax
\code{\Link{prcomp}}, \code{\Link{cor}}, \code{\Link{cov}},
\code{\Link{eigen}}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
## The variances of the variables in the
## USArrests data vary by orders of magnitude
data(USArrests)
(pc.cr <- princomp(USArrests))
princomp(USArrests, cor = TRUE) # =^= prcomp(USArrests, scale=TRUE)
## Similar, but different:
princomp(scale(USArrests, scale = TRUE, center = TRUE), cor = FALSE)

summary(pc.cr <- princomp(USArrests))
loadings(pc.cr)
plot(pc.cr) # does a screeplot.
biplot(pc.cr)
\end{ExampleCode}
\end{Examples}

