This package contains functions to compute, print and plot Least Squares Sparse Principal Components Analysis (LS-SPCA). Methodological details, references and full presentation can be found in the extended_vignette document.
Installation
You can install the stable release version from CRAN
install.packages("spca") #or https://github.com/merolagio/spca/releases/tag/CRAN_submission
The current development version from GitHub
remotes::install_github("merolagio/spca")
Usage
The main function spca() computes the sparse loadings and various
statistics, such as the variance explained by each sparse component
(sPC). print, summery and plot methods are available. PCA solutions
stored as an *spca* object cn be obtained with the function pca().
Utilities available are
compare_spca()(to compare two or more spca solutions), *aggregate_by_scale()* (to visualize the contribution by scale) and *new.spca()* (to create anspca`
object from a set of loadings).
Example
Load data
The holzinger dataset is the small classic Holzinger-Swineford dataset
with 145 cases on 12 variables grouped in 4 scales.
library(spca) data(holzinger) dim(holzinger) #> [1] 145 12 holzinger_scales #> [1] SPL SPL SPL VBL VBL VBL SPD SPD SPD MTH MTH MTH #> Levels: SPL VBL SPD MTH
Preliminary PCA
ho_pca = pca(holzinger, screeplot = TRUE, qq_plot = TRUE) summary(ho_pca,cols = 10) #> sPC1 sPC2 sPC3 sPC4 sPC5 sPC6 sPC7 sPC8 sPC9 sPC10 #> Vexp 40.2% 13.7% 10.6% 6.4% 5.6% 5.1% 4.3% 3.9% 3.2% 2.6% #> Cvexp 40.2% 53.9% 64.5% 70.9% 76.5% 81.6% 85.9% 89.8% 93.0% 95.6% #> Rvexp 100.0% 100.0% 100.0% 100.0% 100.0% 100.0% 100.0% 100.0% 100.0% 100.0% #> Rcvexp 100.0% 100.0% 100.0% 100.0% 100.0% 100.0% 100.0% 100.0% 100.0% 100.0% #> Card 12 12 12 12 12 12 12 12 12 12
Compute the sparse loadings
Important parameters in the spca() function are: alpha which controls for the minimum


