Skip to contents

L1-penalised alternating maximisation: soft-threshold Sigma %*% v, then renormalise, with later components on the deflated covariance. Ordinary PCA loadings are almost never zero, so every component mixes all p variables; the L1 penalty zeroes loadings outright. The cost, which must be stated: sparse components are NOT orthogonal, so their variances do not sum to the total and "percent variance explained" is not additive. adjusted_variance applies the Zou-Hastie-Tibshirani correction.

Usage

morie_esl_sparse_pca(
  X,
  k = 2,
  lambda_ = 0.1,
  max_iter = 500L,
  tol = 1e-08,
  center = TRUE,
  scale = FALSE
)

Arguments

X

Data, n by p.

k

Number of components.

lambda_

Soft-threshold level; zero recovers ordinary PCA.

max_iter, tol

Power-iteration controls.

center, scale

Centre columns, optionally scale to unit variance.

Value

List with loadings, scores, sparsity, adjusted_variance, explained, n_iter.

References

Zou, H., Hastie, T., & Tibshirani, R. (2006). Sparse principal component analysis. JCGS 15(2), 265-286.

Examples

set.seed(1)
X <- matrix(rnorm(1200), ncol = 6) %*% diag(c(5, 3, 1, 1, 1, 1))
morie_esl_sparse_pca(X, k = 1, lambda_ = 2)$sparsity > 0
#> [1] TRUE