tidy_pca: PCA in a tidyverse framework

Description Usage Arguments Value See Also Examples

View source: R/tidy_pca.R

Description

A simple wrapper for pca on a data frame

Usage

1
tidy_pca(data, ..., doCenter = TRUE, doScale = TRUE)

Arguments

data

input data frame

...

variables to include in PCA

doCenter

passed to prcomp, center the data? TRUE / FALSE

doScale

passed to prcomp, scale the data? TRUE / FALSE

Value

nested tibble with entries:
pca = prcomp() output
data_aug = original data with bound PC scores
pc_weights = tibble of PCA vector weights
pc_frac = tibble of PCA eigenvalues and their cumulative (normalized) sum

See Also

prcomp which this function wraps

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
df_pca <-
  iris %>%
  tidy_pca(
    Sepal.Length,
    Sepal.Width,
    Petal.Length,
    Petal.Width
  )

df_pca %>%
  unnest(pc_frac) %>%
  knitr::kable()

df_pca %>%
  unnest(data_aug) %>%
  ggplot(aes(PC1, PC2, color = Species)) +
  geom_point()

zdelrosario/tidyPca documentation built on May 29, 2019, 9:32 a.m.