pca: Principal Components Analysis

View source: R/pca.R

pcaR Documentation

Principal Components Analysis


An implementation of several strategies for principal components analysis (PCA), a common preprocessing step. Given a dataset and a desired new dimensionality, this can reduce the dimensionality of the data using the linear transformation determined by PCA.


  decomposition_method = NA,
  new_dimensionality = NA,
  scale = FALSE,
  var_to_retain = NA,
  verbose = FALSE



Input dataset to perform PCA on (numeric matrix).


Method used for the principal components analysis: 'exact', 'randomized', 'randomized-block-krylov', 'quic'. Default value "exact" (character).


Desired dimensionality of output dataset. If 0, no dimensionality reduction is performed. Default value "0" (integer).


If set, the data will be scaled before running PCA, such that the variance of each feature is 1. Default value "FALSE" (logical).


Amount of variance to retain; should be between 0 and 1. If 1, all variance is retained. Overrides -d. Default value "0" (numeric).


Display informational messages and the full list of parameters and timers at the end of execution. Default value "FALSE" (logical).


This program performs principal components analysis on the given dataset using the exact, randomized, randomized block Krylov, or QUIC SVD method. It will transform the data onto its principal components, optionally performing dimensionality reduction by ignoring the principal components with the smallest eigenvalues.

Use the "input" parameter to specify the dataset to perform PCA on. A desired new dimensionality can be specified with the "new_dimensionality" parameter, or the desired variance to retain can be specified with the "var_to_retain" parameter. If desired, the dataset can be scaled before running PCA with the "scale" parameter.

Multiple different decomposition techniques can be used. The method to use can be specified with the "decomposition_method" parameter, and it may take the values 'exact', 'randomized', or 'quic'.


A list with several components:


Matrix to save modified dataset to (numeric matrix).


mlpack developers


# For example, to reduce the dimensionality of the matrix "data" to 5
# dimensions using randomized SVD for the decomposition, storing the output
# matrix to "data_mod", the following command can be used:

## Not run: 
output <- pca(input=data, new_dimensionality=5,
data_mod <- output$output

## End(Not run)

mlpack documentation built on Oct. 29, 2022, 1:06 a.m.

Related to pca in mlpack...