msPCA

An R Package for Sparse PCA with Multiple Principal Components

Installation

This package can be installed from CRAN directly (pending CRAN registration):

install.packages("msPCA")

Alternatively, it can be installed from this Github repository using the devtools package. You would first need to install devtools:

install.packages("devtools")

and then run the following commands:

library(devtools)
install_github('jeanpauphilet/msPCA')

Getting started

The package consists of one main function, msPCA, which takes as input: - a data matrix (either the correlation or covariance matrix of the dataset), - the number of principal components (PCs) to be computed, r, - a list of r integers corresponding to the sparsity of each PC.

It returns an objecti with 4 fields - x_best (p x r array containing the sparse PCs), - objective_value - orthogonality_violation - runtime.

Here is a short example demonstrating how to use the package. First, you need to load the library.

library(msPCA)

Then, define the input variables.

library(datasets)
df <- datasets::mtcars
TestMat <- cor(df)

And then simply call the function

mspca(TestMat, 2, c(4,4))

Development

Here, we provide more information about the code structure and organization to help developers that would like to improve the method or build up on it.

Files