Computes a principal components analysis based on the singular value decomposition.
Usage
pca(object, ...)
# S4 method for class 'data.frame'
pca(
object,
center = TRUE,
scale = TRUE,
rank = NULL,
sup_row = NULL,
sup_col = NULL,
sup_quali = NULL,
weight_row = NULL,
weight_col = NULL
)
# S4 method for class 'matrix'
pca(
object,
center = TRUE,
scale = TRUE,
rank = NULL,
sup_row = NULL,
sup_col = NULL,
weight_row = NULL,
weight_col = NULL
)
Arguments
- object
A \(m \times p\) numeric
matrix
or adata.frame
.- ...
Currently not used.
- center
A
logical
scalar: should the variables be shifted to be zero centered?- scale
A
logical
scalar: should the variables be scaled to unit variance?- rank
An
integer
value specifying the maximal number of components to be kept in the results. IfNULL
(the default), \(p - 1\) components will be returned.- sup_row
A
vector
specifying the indices of the supplementary rows.- sup_col
A
vector
specifying the indices of the supplementary columns.- sup_quali
A
vector
specifying the indices of the supplementary qualitative columns.- weight_row
A
numeric
vector specifying the active row (individual) weights. IfNULL
(the default), uniform weights are used. Row weights are internally normalized to sum 1- weight_col
A
numeric
vector specifying the active column (variable) weights. IfNULL
(the default), uniform weights (1) are used.
Value
A PCA
object.
References
Lebart, L., Piron, M. and Morineau, A. Statistique exploratoire multidimensionnelle: visualisation et inférence en fouille de données. Paris: Dunod, 2006.
Examples
## Load data
data("iris")
## Compute principal components analysis
X <- pca(iris, scale = TRUE, sup_row = sample(150, 10), sup_col = 2)
#> 1 qualitative variable was removed: Species.
## Get row coordinates
head(get_coordinates(X, margin = 1))
#> F1 F2 .sup
#> 1 -2.119908 0.30504514 FALSE
#> 2 -2.258782 0.10373707 FALSE
#> 3 -2.431802 -0.08324361 FALSE
#> 4 -2.432948 -0.21255244 FALSE
#> 5 -2.189345 0.20439110 FALSE
#> 6 -1.655423 0.42376563 FALSE
## Get column coordinates
head(get_coordinates(X, margin = 2))
#> F1 F2 .sup
#> Sepal.Length 0.9309472 0.3639030 FALSE
#> Petal.Length 0.9843042 -0.1113731 FALSE
#> Petal.Width 0.9650983 -0.2374364 FALSE
#> Sepal.Width -0.3010865 0.4476798 TRUE
## Get correlations between variables and dimensions
head(get_correlations(X))
#> F1 F2 .sup
#> Sepal.Length 0.9309472 0.3639030 FALSE
#> Petal.Length 0.9843042 -0.1113731 FALSE
#> Petal.Width 0.9650983 -0.2374364 FALSE
#> Sepal.Width -0.3010865 0.4476798 TRUE
## Get eigenvalues
get_eigenvalues(X)
#> eigenvalues variance cumulative
#> F1 2.7669322 93.221156 93.22116
#> F2 0.2012054 6.778844 100.00000