Sparse PCA (do.spca
) is a variant of PCA in that each loading - or, principal
component - should be sparse. Instead of using generic optimization package,
we opt for formulating a problem as semidefinite relaxation and utilizing ADMM.
do.spca(
X,
ndim = 2,
preprocess = c("center", "scale", "cscale", "decorrelate", "whiten"),
mu = 1,
rho = 1,
abstol = 1e-04,
reltol = 0.01,
maxiter = 1000
)
an
an integer-valued target dimension.
an additional option for preprocessing the data.
Default is "center"
. See also aux.preprocess
for more details.
an augmented Lagrangian parameter.
a regularization parameter for sparsity.
absolute tolerance stopping criterion.
relative tolerance stopping criterion.
maximum number of iterations.
a named list containing
an
a
a list containing information for out-of-sample prediction.
zou_sparse_2006Rdimtools
daspremont_direct_2007Rdimtools
ma_alternating_2013Rdimtools
# NOT RUN {
## use iris data
data(iris)
set.seed(100)
subid = sample(1:150,50)
X = as.matrix(iris[subid,1:4])
lab = as.factor(iris[subid,5])
## try different regularization parameters for sparsity
out1 <- do.spca(X,ndim=2,rho=0.01)
out2 <- do.spca(X,ndim=2,rho=1)
out3 <- do.spca(X,ndim=2,rho=100)
## embeddings for each procedure
Y1 <- out1$Y; Y2 <- out2$Y; Y3 <- out3$Y
## visualize
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,3))
plot(Y1, col=lab, pch=19, main="SPCA::rho=0.01")
plot(Y2, col=lab, pch=19, main="SPCA::rho=1")
plot(Y3, col=lab, pch=19, main="SPCA::rho=100")
par(opar)
# }
Run the code above in your browser using DataLab