A wrapper which carries out sparse PCA analysis on a Spectra object. The user can select various options for scaling. There is no normalization by rows - do this manually using normSpectra. The data will be centered, as is required by PCA.

s_pcaSpectra(spectra, choice = "noscale", K = 3, para = rep(0.5, K), ...)

Arguments

spectra

An object of S3 class Spectra().

choice

A character string indicating the choice of scaling. One of c("noscale", "autoscale", "Pareto"). "autoscale" is called "standard normal variate" or "correlation matrix PCA" in some literature.

K

Integer. The number of components desired.

para

A vector of length(K) giving the tuning parameters.

...

Other parameters to be passed to arrayspc.

Value

An object of class prcomp and converted_from_arrayspc, which includes a list element called $method, a character string describing the pre-processing carried out and the type of PCA performed (used to annotate plots). A check is carried out to see if the computation was successful and a warning issued if it failed.

Details

The scale choice autoscale scales the columns by their standard deviation. Pareto scales by the square root of the standard deviation.

References

H. Zou, T. Hastie and R. Tibshirani "Sparse Principal Components Analysis" J. Comp. Stat. Graphics vol. 15 no. 2 pgs. 265-286 (2006).

See also

arrayspc for the underlying function, c_pcaSpectra for classical PCA calculations, r_pcaSpectra for robust PCA calculations, irlba_pcaSpectra for PCA via the IRLBA algorithm. Additional documentation at https://bryanhanson.github.io/ChemoSpec/

For displaying the results, ChemoSpecUtils::plotScree(), ChemoSpecUtils::plotScores(), plotLoadings(), plot2Loadings(), sPlotSpectra().

Author

Bryan A. Hanson (DePauw University).

Examples

if (FALSE) {
# This example assumes the graphics output is set to ggplot2 (see ?GraphicsOptions).
library("ggplot2")
data(SrE.NMR)
pca <- s_pcaSpectra(SrE.NMR)

p1 <- plotScree(pca)
p1

p2 <- plotScores(SrE.NMR, pca, pcs = c(1, 2), ellipse = "cls", tol = 0.05)
p2 <- p2 + ggtitle("Scores: SrE NMR Data")
p2

p3 <- plotLoadings(SrE.NMR, pca, loads = 1:2, ref = 1)
p3 <- p3 + ggtitle("Loadings: SrE NMR Data")
p3
}