Learn R Programming

tidypopgen (version 0.4.3)

augment_gt_pca: Augment data with information from a gt_pca object

Description

Augment for gt_pca accepts a model object and a dataset and adds scores to each observation in the dataset. Scores for each component are stored in a separate column, which is given name with the pattern ".fittedPC1", ".fittedPC2", etc. For consistency with broom::augment.prcomp, a column ".rownames" is also returned; it is a copy of 'id', but it ensures that any scripts written for data augmented with broom::augment.prcomp will work out of the box (this is especially helpful when adapting plotting scripts).

Usage

# S3 method for gt_pca
augment(x, data = NULL, k = NULL, ...)

Value

A gen_tibble containing the original data along with additional columns containing each observation's projection into PCA space.

Arguments

x

A gt_pca object returned by one of the gt_pca_* functions.

data

the gen_tibble used to run the PCA.

k

the number of components to add

...

Not used. Needed to match generic signature only.

See Also

gt_pca_autoSVD() gt_pca_tidiers

Examples

Run this code
# Create a gen_tibble of lobster genotypes
bed_file <-
  system.file("extdata", "lobster", "lobster.bed", package = "tidypopgen")
lobsters <- gen_tibble(bed_file,
  backingfile = tempfile("lobsters"),
  quiet = TRUE
)

# Remove monomorphic loci and impute
lobsters <- lobsters %>% select_loci_if(loci_maf(genotypes) > 0)
lobsters <- gt_impute_simple(lobsters, method = "mode")

# Create PCA object
pca <- gt_pca_partialSVD(lobsters)

# Augment the gen_tibble with PCA scores
augment(pca, data = lobsters)

# Adjust the number of components to add
augment(pca, data = lobsters, k = 2)

Run the code above in your browser using DataLab