Skip to contents

Converts a table to a numeric matrix, filters foods with too many NAs, imputes remaining NAs, and runs prcomp().

Usage

run_pca(
  table,
  drop_cols = NULL,
  min_obs = NULL,
  impute = c("median", "zero"),
  name_col = "Food name",
  group_col = TRUE
)

Arguments

table

IFCT table name.

drop_cols

Columns to exclude (in addition to id columns).

min_obs

Minimum non-NA values per food. Defaults to half the number of nutrient columns.

impute

"median" (default) or "zero".

name_col

Column to use as food label (default "Food name").

group_col

If TRUE (default), attach food group via decode_food_code().

Value

A list with pca, scores, loadings, and var_exp.

Examples

pca <- run_pca("amino_acids")
plot_pca(pca)
#> Warning: Removed 3 rows containing missing values or values outside the scale range
#> (`geom_label_repel()`).