Learn R Programming

factoextra (version 2.2.0)

get_pca: Extract the results for individuals/variables - PCA

Description

Extract all the results (coordinates, squared cosines, and contributions) for the active individuals/variables from Principal Component Analysis (PCA) outputs.

  • get_pca(): Extract the results for variables and individuals

  • get_pca_ind(): Extract the results for individuals only

  • get_pca_var(): Extract the results for variables only

Read more: Principal Component Analysis (PCA) in R: Compute, Visualize & Interpret.

Usage

get_pca(res.pca, element = c("var", "ind"))

get_pca_ind(res.pca, ...)

get_pca_var(res.pca)

Value

a list of matrices containing all the results for the active individuals/variables including:

coord

coordinates for the individuals/variables

cos2

cos2 for the individuals/variables. For an adapted recipe/workflow object this is NULL when the metric cannot be recovered. For a rank-truncated prcomp object, individual cos2 is the quality within the retained component subspace because the discarded row inertia is not stored in the fitted object.

contrib

contributions of the individuals/variables; contributions to each nonzero-inertia axis sum to 100 percent, while a zero-inertia axis contains zeros

cor

loading-times-component-standard-deviation coordinates for PCA objects from stats; these equal variable-component correlations when the input variables were standardized. Returned for variables; for an adapted recipe/workflow object it is NULL when correlations cannot be recovered.

Arguments

res.pca

an object of class PCA [FactoMineR]; prcomp or princomp [stats]; factoextra_pca; pca, dudi, between, or within [ade4]; or expoOutput/epPCA [ExPosition].

element

the element to subset from the output. Allowed values are "var" (for active variables) or "ind" (for active individuals).

...

not used

Author

Alboukadel Kassambara alboukadel.kassambara@gmail.com

References

https://www.datanovia.com/learn/

See Also

Examples

Run this code
# \donttest{
# Principal Component Analysis
# +++++++++++++++++++++++++++++
 data(iris)
 res.pca <- prcomp(iris[, -5],  scale = TRUE)
 # Extract the results for individuals
 ind <- get_pca_ind(res.pca)
 print(ind)
 head(ind$coord) # coordinates of individuals
 head(ind$cos2) # cos2 of individuals
 head(ind$contrib) # contributions of individuals
 
 # Extract the results for variables
 var <- get_pca_var(res.pca)
 print(var)
 head(var$coord) # coordinates of variables
 head(var$cos2) # cos2 of variables
 head(var$contrib) # contributions of variables
 
 # You can also use the function get_pca()
 get_pca(res.pca, "ind") # Results for individuals
 get_pca(res.pca, "var") # Results for variable categories
 # }

Run the code above in your browser using DataLab