pca_data: Extract PCA data and grouping for further analysis or...

View source: R/pca_functions.R

pca_dataR Documentation

Extract PCA data and grouping for further analysis or publication-quality plots.

Description

Extract PCA data and grouping for further analysis or publication-quality plots.

Usage

pca_data(data, vars, samples = "rowname", scale = T, var_scaling = 5)

Arguments

data

Input dataset.

vars

Selection of columns from input dataset to perform the PCA on. All data within these columns be numerical. Any rows with missing values will be dropped. Accepts the following input types:

  • A numerical vector specifying the columns to use (i.e., c(2,3,8) uses columns 2, 3 and 8).

  • A character vector specifyiny the names of the columns to use.

  • A character vector of length 2. This will select the two named columns and all columns between them.

samples

Optional column to provide unique sample identifier. Otherwise, rownames are used.

scale

Boolean. If TRUE, then correlation PCA. if FALSE, then covariance PCA.

var_scaling

Multiplier for raw variable loadings. Helps scale them to similar values as sample loadings most of the time. Set to FALSE for raw output.

Value

This returns a named list of data frames:

  • pervar contains the percent variance explained by each principal component.

  • vars contains the variable loadings on each principal component. These may have been scaled by var_scaling for easier plotting.

  • samples contains the sample loadings on each principal component.


JackAHutchings/jahrfun documentation built on June 8, 2025, 3:09 a.m.