Learn R Programming

specmine (version 4.0.0)

pca_importance: PCA component importance

Description

Calculates the standard deviation, proportion of variance and cumulative proportion of variance explained by selected principal components.

Usage

pca_importance(
  pca.res,
  pcs = 1:length(pca.res$sdev),
  sd = TRUE,
  prop = TRUE,
  cumul = TRUE,
  min.cum = NULL
)

Value

A numeric matrix with one row for each requested measure: Standard deviation, Proportion of Variance and/or Cumulative Proportion. Columns correspond to the selected principal components.

For a prcomp object, the values are calculated from its sdev component. For a princomp object, the same calculation is applied to its sdev component.

Arguments

pca.res

An object inheriting from class prcomp or princomp.

pcs

Integer vector specifying the principal components to return. By default, all available components are returned.

sd

Logical indicating whether the standard deviation row should be returned.

prop

Logical indicating whether the proportion of variance row should be returned.

cumul

Logical indicating whether the cumulative proportion row should be returned.

min.cum

Optional numeric value between 0 and 1. When supplied, components are selected up to the first component whose cumulative proportion is greater than or equal to this value.

Details

The function accepts PCA results generated by pca_analysis_dataset(), stats::prcomp() or stats::princomp().

Examples

Run this code
datamat <- matrix(
  rnorm(40),
  nrow = 4,
  ncol = 10,
  dimnames = list(
    paste0("feature", 1:4),
    paste0("sample", 1:10)
  )
)

dataset <- list(data = datamat)
pca.result <- pca_analysis_dataset(dataset)

pca_importance(
  pca.result,
  pcs = 1:3,
  sd = TRUE,
  prop = TRUE,
  cumul = TRUE
)

pca_importance(
  pca.result,
  min.cum = 0.90,
  sd = FALSE,
  prop = TRUE,
  cumul = TRUE
)

Run the code above in your browser using DataLab