tof_reduce_pca: Perform principal component analysis on single-cell data

View source: R/dimensionality_reduction.R

tof_reduce_pcaR Documentation

Perform principal component analysis on single-cell data

Description

This function calculates principal components using single-cell data from a 'tof_tibble'.

Usage

tof_reduce_pca(
  tof_tibble,
  pca_cols = where(tof_is_numeric),
  num_comp = 5,
  threshold = NA,
  center = TRUE,
  scale = TRUE,
  return_recipe = FALSE
)

Arguments

tof_tibble

A 'tof_tbl' or 'tibble'.

pca_cols

Unquoted column names indicating which columns in 'tof_tibble' to use for computing the principal components. Defaults to all numeric columns. Supports tidyselect helpers.

num_comp

The number of PCA components to calculate. Defaults to 5. See step_pca.

threshold

A double between 0 and 1 representing the fraction of total variance that should be covered by the components returned in the output. See step_pca.

center

A boolean value indicating if each column should be centered to mean 0 before PCA analysis. Defaults to TRUE.

scale

A boolean value indicating if each column should be scaled to standard deviation = 1 before PCA analysis. Defaults to TRUE.

return_recipe

A boolean value indicating if instead of the UMAP result, a prepped recipe object containing the PCA embedding should be returned. Set this option to TRUE if you want to create the PCA embedding using one dataset but also want to project new observations onto the same embedding space later.

Value

A tibble with the same number of rows as 'tof_tibble', each representing a single cell. Each of the ‘num_comp' columns represents each cell’s embedding in the calculated principal component space.

See Also

Other dimensionality reduction functions: tof_reduce_dimensions(), tof_reduce_tsne(), tof_reduce_umap()

Examples

# simulate single-cell data
sim_data <-
    dplyr::tibble(
        cd45 = rnorm(n = 200),
        cd38 = rnorm(n = 200),
        cd34 = rnorm(n = 200),
        cd19 = rnorm(n = 200)
    )
new_data <-
    dplyr::tibble(
        cd45 = rnorm(n = 50),
        cd38 = rnorm(n = 50),
        cd34 = rnorm(n = 50),
        cd19 = rnorm(n = 50)
    )

# calculate pca
tof_reduce_pca(tof_tibble = sim_data, num_comp = 2)

# return recipe instead of embeddings
pca_recipe <- tof_reduce_pca(tof_tibble = sim_data, return_recipe = TRUE)

# apply recipe to new data
recipes::bake(pca_recipe, new_data = new_data)


keyes-timothy/tidytof documentation built on May 7, 2024, 12:33 p.m.