Learn R Programming

rsvd (version 2.0.0)

ggscreeplot: PCA scree plot and explained variance

Description

Show how much variation each retained principal component from rpca captures in the processed data. Plot individual component variances, their proportions of total variance, or the cumulative proportion to assess how much variation the retained representation captures. The optional ggplot2 package is required.

Usage

ggscreeplot(rpcaObj, type = c("var", "ratio", "cum", "eigenvals"))

Value

A ggplot2 plot object. Print the object to draw the plot, or add layers, labels, and themes with ggplot2.

Arguments

rpcaObj

An object returned by rpca. Scores are not needed, so fits made with retx = FALSE are supported. The variance quantities are real-valued for both real and complex PCA.

type

Character string selecting the vertical-axis quantity. "var" (the default) plots sdev^2; "ratio" plots sdev^2 / var; "cum" plots the cumulative sum of those ratios; and "eigenvals" plots eigvals. For an rpca object, "var" and "eigenvals" give the same values with different axis labels. Unambiguous partial matches are accepted.

Author

N. Benjamin Erichson

Details

The horizontal axis follows the retained components in their fitted order. The variance and eigenvalue views show how much variation each component captures, in squared units of the processed input. The ratio view expresses each amount as a proportion of total variance; the cumulative view adds those proportions through each displayed component.

Both proportion views use rpcaObj$var as their denominator. This total includes energy outside the retained components, so the cumulative curve can end below one when the fit retains only a low-rank approximation. The proportions lie between zero and one when total processed variance is positive. They are undefined for an input with zero total processed variance.

Interpretation follows the preprocessing used in rpca. With center = FALSE, the quantities use uncentered sums of squares, which include the contribution of any nonzero column means. They need not equal variances computed after subtracting the means of the fitted score columns.

See Also

rpca, ggbiplot, ggcorplot, ggindplot, ggplot

Examples

Run this code
if (requireNamespace("ggplot2", quietly = TRUE)) {
  set.seed(42)
  fit <- rpca(iris[, 1:4], k = 2, retx = FALSE)
  # The curve uses all processed variance, including omitted components.
  print(ggscreeplot(fit, type = "cum"))
}

Run the code above in your browser using DataLab