R/calc_expvar.R

Defines functions calc_expvar

Documented in calc_expvar

#' Explained variance of a principal component
#'
#' This function calculates the explained variance of a given principal component in a PCA.
#'
#' @param pca A \code{prcomp} object.
#' @param n An integer: what principal component?
#' @return A numeric, the proportion of variance in the dataset explained by the principal component.
#' @author Raphael Scherrer
#' @export

calc_expvar <- function(pca, n) pca$sdev[n] / sum(pca$sdev)
rscherrer/sagreicolor documentation built on March 24, 2019, 8:34 p.m.