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,
sup_quali = 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.- 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.014189 0.29146993 FALSE
#> 2 -2.149935 0.09359728 FALSE
#> 3 -2.319110 -0.08981404 FALSE
#> 4 -2.320123 -0.21767301 FALSE
#> 5 -2.082062 0.19253361 FALSE
#> 6 -1.557393 0.40767061 FALSE
## Get column coordinates
head(get_coordinates(X, margin = 2))
#> F1 F2 .sup
#> Sepal.Length 0.9283949 0.3706070 FALSE
#> Petal.Length 0.9847166 -0.1166555 FALSE
#> Petal.Width 0.9656401 -0.2373525 FALSE
#> Sepal.Width -0.3250284 0.4777053 TRUE
## Get correlations between variables and dimensions
head(get_correlations(X))
#> F1 F2 .sup
#> Sepal.Length 0.9283949 0.3706070 FALSE
#> Petal.Length 0.9847166 -0.1166555 FALSE
#> Petal.Width 0.9656401 -0.2373525 FALSE
#> Sepal.Width -0.3250284 0.4777053 TRUE
## Get eigenvalues
get_eigenvalues(X)
#> eigenvalues variance cumulative
#> F1 2.7640447 93.023539 93.02354
#> F2 0.2072943 6.976461 100.00000