PCA {jvcoords} | R Documentation |
Perform Principal Component Analysis (PCA)
Description
Perform principal components analysis on a data
matrix and return the results as an object of class coords
.
Usage
PCA(x, n.comp, scale = FALSE, compute.scores = TRUE)
Arguments
x |
A data matrix, rows are observations, columns are variables. |
n.comp |
How many principal components to compute. |
scale |
Whether to standardize the columns before doing PCA. |
compute.scores |
Whether to compute the scores (i.e. x in the new basis). |
Details
This function performs Principal Component Analysis (PCA) on the
data. Variables are always centred before
the PCA is performed and, if scale
is set, the variables
will also be rescaled to unit variance.
If compute.scores
is set to FALSE
, only the information
required for the toPC()
and fromPC()
to work is stored
in the returned coords
object; otherwise the scores will
be stored in the $y
field of the coords
object.
The PCA()
function is an alternative to
the prcomp()
command from the standard library.
The main advantage of PCA()
is that the coords
class provides functions to convert between the original basis and the
principal component basis.
Value
An object of class coords
, with the following
additional components added:
loadings |
the loadings, each column is one of the new basis vectors |
y |
if |
var |
the variance of the data along each of the new basis vectors |
total.var |
the total variance of the data |
Author(s)
Jochen Voss <voss@seehuhn.de>
See Also
coords
;
alternative implementations: prcomp
, princomp
Examples
pc <- PCA(iris[, 1:4], scale = TRUE, n.comp = 2)
pc
plot(pc$y, col=iris$Species)