Computes a principal components analysis based on the singular value decomposition.
Usage
pca(object, ...)
# S4 method for data.frame
pca(
object,
center = TRUE,
scale = TRUE,
rank = NULL,
sup_row = NULL,
sup_col = NULL,
weight_row = NULL,
weight_col = NULL
)
# S4 method for 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.- 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.071210 0.30628230 FALSE
#> 2 -2.205873 0.11088123 FALSE
#> 3 -2.374237 -0.07036696 FALSE
#> 4 -2.374166 -0.19637325 FALSE
#> 5 -2.138542 0.20858176 FALSE
#> 6 -1.613606 0.41615798 FALSE
## Get column coordinates
head(get_coordinates(X, margin = 2))
#> F1 F2 .sup
#> Sepal.Length 0.9306562 0.3647468 FALSE
#> Petal.Length 0.9849858 -0.1117255 FALSE
#> Petal.Width 0.9655250 -0.2375970 FALSE
#> Sepal.Width -0.3327152 0.4554679 TRUE
## Get correlations between variables and dimensions
head(get_correlations(X))
#> F1 F2 .sup
#> Sepal.Length 0.9306562 0.3647468 FALSE
#> Petal.Length 0.9849858 -0.1117255 FALSE
#> Petal.Width 0.9655250 -0.2375970 FALSE
#> Sepal.Width -0.3327152 0.4554679 TRUE
## Get eigenvalues
get_eigenvalues(X)
#> eigenvalues variance cumulative
#> F1 2.7685566 93.200706 93.20071
#> F2 0.2019752 6.799294 100.00000