Extracts a per-component variance summary from a PCA fit. Accepts either an
existing prcomp object or raw data, in which case
prcomp is run first.
Value
A tibble with one row per component: `component`, `eigenvalue`, `difference`, `proportion`, `variance_pct`, `cum_variance_pct`.
Examples
run_pca(prcomp(mtcars[, 1:4], scale. = TRUE))
#> # A tibble: 4 × 6
#> component eigenvalue difference proportion variance_pct cum_variance_pct
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 PC1 3.50 3.26 0.876 87.6 87.6
#> 2 PC2 0.239 0.0742 0.0599 5.99 93.5
#> 3 PC3 0.165 0.0721 0.0413 4.13 97.7
#> 4 PC4 0.0931 NA 0.0233 2.33 100
# Or fit the PCA in one step
run_pca(mtcars[, 1:4], scale = TRUE)
#> # A tibble: 4 × 6
#> component eigenvalue difference proportion variance_pct cum_variance_pct
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 PC1 3.50 3.26 0.876 87.6 87.6
#> 2 PC2 0.239 0.0742 0.0599 5.99 93.5
#> 3 PC3 0.165 0.0721 0.0413 4.13 97.7
#> 4 PC4 0.0931 NA 0.0233 2.33 100
