| Line 1... |
Line 1... |
| 1 |
% File src/library/stats/man/princomp.Rd
|
1 |
% File src/library/stats/man/princomp.Rd
|
| 2 |
% Part of the R package, https://www.R-project.org
|
2 |
% Part of the R package, https://www.R-project.org
|
| 3 |
% Copyright 1995-2014 R Core Team
|
3 |
% Copyright 1995-2018 R Core Team
|
| 4 |
% Distributed under GPL 2 or later
|
4 |
% Distributed under GPL 2 or later
|
| 5 |
|
5 |
|
| 6 |
\name{princomp}
|
6 |
\name{princomp}
|
| 7 |
\alias{princomp}
|
7 |
\alias{princomp}
|
| 8 |
\alias{princomp.formula}
|
8 |
\alias{princomp.formula}
|
| Line 16... |
Line 16... |
| 16 |
princomp(x, \dots)
|
16 |
princomp(x, \dots)
|
| 17 |
|
17 |
|
| 18 |
\method{princomp}{formula}(formula, data = NULL, subset, na.action, \dots)
|
18 |
\method{princomp}{formula}(formula, data = NULL, subset, na.action, \dots)
|
| 19 |
|
19 |
|
| 20 |
\method{princomp}{default}(x, cor = FALSE, scores = TRUE, covmat = NULL,
|
20 |
\method{princomp}{default}(x, cor = FALSE, scores = TRUE, covmat = NULL,
|
| 21 |
subset = rep_len(TRUE, nrow(as.matrix(x))), \dots)
|
21 |
subset = rep_len(TRUE, nrow(as.matrix(x))), fix_sign = TRUE, \dots)
|
| 22 |
|
22 |
|
| 23 |
\method{predict}{princomp}(object, newdata, \dots)
|
23 |
\method{predict}{princomp}(object, newdata, \dots)
|
| 24 |
}
|
24 |
}
|
| 25 |
\arguments{
|
25 |
\arguments{
|
| 26 |
\item{formula}{a formula with no response variable, referring only to
|
26 |
\item{formula}{a formula with no response variable, referring only to
|
| Line 46... |
Line 46... |
| 46 |
\item{covmat}{a covariance matrix, or a covariance list as returned by
|
46 |
\item{covmat}{a covariance matrix, or a covariance list as returned by
|
| 47 |
\code{\link{cov.wt}} (and \code{\link[MASS:cov.rob]{cov.mve}} or
|
47 |
\code{\link{cov.wt}} (and \code{\link[MASS:cov.rob]{cov.mve}} or
|
| 48 |
\code{\link[MASS:cov.rob]{cov.mcd}} from package \CRANpkg{MASS}).
|
48 |
\code{\link[MASS:cov.rob]{cov.mcd}} from package \CRANpkg{MASS}).
|
| 49 |
If supplied, this is used rather than the covariance matrix of
|
49 |
If supplied, this is used rather than the covariance matrix of
|
| 50 |
\code{x}.}
|
50 |
\code{x}.}
|
| - |
|
51 |
\item{fix_sign}{Should the signs of the loadings and scores be chosen
|
| - |
|
52 |
so that the first element of each loading is non-negative?}
|
| 51 |
\item{\dots}{arguments passed to or from other methods. If \code{x} is
|
53 |
\item{\dots}{arguments passed to or from other methods. If \code{x} is
|
| 52 |
a formula one might specify \code{cor} or \code{scores}.}
|
54 |
a formula one might specify \code{cor} or \code{scores}.}
|
| 53 |
\item{object}{Object of class inheriting from \code{"princomp"}}
|
55 |
\item{object}{Object of class inheriting from \code{"princomp"}.}
|
| 54 |
\item{newdata}{An optional data frame or matrix in which to look for
|
56 |
\item{newdata}{An optional data frame or matrix in which to look for
|
| 55 |
variables with which to predict. If omitted, the scores are used.
|
57 |
variables with which to predict. If omitted, the scores are used.
|
| 56 |
If the original fit used a formula or a data frame or a matrix with
|
58 |
If the original fit used a formula or a data frame or a matrix with
|
| 57 |
column names, \code{newdata} must contain columns with the same
|
59 |
column names, \code{newdata} must contain columns with the same
|
| 58 |
names. Otherwise it must contain the same number of columns, to be
|
60 |
names. Otherwise it must contain the same number of columns, to be
|
| Line 111... |
Line 113... |
| 111 |
variables. For Q-mode PCA use \code{\link{prcomp}}.
|
113 |
variables. For Q-mode PCA use \code{\link{prcomp}}.
|
| 112 |
}
|
114 |
}
|
| 113 |
\note{
|
115 |
\note{
|
| 114 |
The signs of the columns of the loadings and scores are arbitrary, and
|
116 |
The signs of the columns of the loadings and scores are arbitrary, and
|
| 115 |
so may differ between different programs for PCA, and even between
|
117 |
so may differ between different programs for PCA, and even between
|
| 116 |
different builds of \R.
|
118 |
different builds of \R: \code{fix_sign = TRUE} alleviates that.
|
| 117 |
}
|
119 |
}
|
| 118 |
\references{
|
120 |
\references{
|
| 119 |
Mardia, K. V., J. T. Kent and J. M. Bibby (1979).
|
121 |
Mardia, K. V., J. T. Kent and J. M. Bibby (1979).
|
| 120 |
\emph{Multivariate Analysis}, London: Academic Press.
|
122 |
\emph{Multivariate Analysis}, London: Academic Press.
|
| 121 |
|
123 |
|
| Line 138... |
Line 140... |
| 138 |
## Similar, but different:
|
140 |
## Similar, but different:
|
| 139 |
## The standard deviations differ by a factor of sqrt(49/50)
|
141 |
## The standard deviations differ by a factor of sqrt(49/50)
|
| 140 |
|
142 |
|
| 141 |
summary(pc.cr <- princomp(USArrests, cor = TRUE))
|
143 |
summary(pc.cr <- princomp(USArrests, cor = TRUE))
|
| 142 |
loadings(pc.cr) # note that blank entries are small but not zero
|
144 |
loadings(pc.cr) # note that blank entries are small but not zero
|
| 143 |
## The signs of the columns are arbitrary
|
145 |
## The signs of the columns of the loadings are arbitrary
|
| 144 |
plot(pc.cr) # shows a screeplot.
|
146 |
plot(pc.cr) # shows a screeplot.
|
| 145 |
biplot(pc.cr)
|
147 |
biplot(pc.cr)
|
| 146 |
|
148 |
|
| 147 |
## Formula interface
|
149 |
## Formula interface
|
| 148 |
princomp(~ ., data = USArrests, cor = TRUE)
|
150 |
princomp(~ ., data = USArrests, cor = TRUE)
|