Skip to contents

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 a data.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. If NULL (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. If NULL (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. If NULL (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.

See also

svd()

Other multivariate analysis: ca(), mca(), pcoa(), predict()

Author

N. Frerebeau

Examples

## Load data
data("iris")

## Compute principal components analysis
X <- pca(iris)
#> 1 qualitative variable was removed: Species.

## Get eigenvalues
get_eigenvalues(X)
#>    eigenvalues  variance cumulative
#> F1   2.9184978 73.342264   73.34226
#> F2   0.9140305 22.969715   96.31198
#> F3   0.1467569  3.688021  100.00000

## Get individual cos2
head(get_cos2(X, margin = 1))
#>          F1         F2           F3  .sup
#> 1 0.9539975 0.04286032 0.0030335249 FALSE
#> 2 0.8927725 0.09369248 0.0113475382 FALSE
#> 3 0.9790410 0.02047578 0.0003422122 FALSE
#> 4 0.9346682 0.06308947 0.0014732682 FALSE
#> 5 0.9315095 0.06823959 0.0000403979 FALSE
#> 6 0.6600989 0.33978301 0.0001114335 FALSE

## Get variable contributions
get_contributions(X, margin = 2)
#>                     F1          F2        F3
#> Sepal.Length 27.150969 14.24440565 51.777574
#> Sepal.Width   7.254804 85.24748749  5.972245
#> Petal.Length 33.687936  0.05998389  2.019990
#> Petal.Width  31.906291  0.44812296 40.230191

## Get correlations between variables and dimensions
get_correlations(X)
#>                      F1         F2          F3  .sup
#> Sepal.Length  0.8901688 0.36082989 -0.27565767 FALSE
#> Sepal.Width  -0.4601427 0.88271627  0.09361987 FALSE
#> Petal.Length  0.9915552 0.02341519  0.05444699 FALSE
#> Petal.Width   0.9649790 0.06399985  0.24298265 FALSE