elasticnet (version 1.3)

spca: Sparse Principal Components Analysis

Description

Using an alternating minimization algorithm to minimize the SPCA criterion.

Usage

spca(x, K, para, type=c("predictor","Gram"),
     sparse=c("penalty","varnum"), use.corr=FALSE, lambda=1e-6,
     max.iter=200, trace=FALSE, eps.conv=1e-3)

Arguments

x

A matrix. It can be the predictor matrix or the sample covariance/correlation matrix.

K

Number of components

para

A vector of length K. All elements should be positive. If sparse="varnum", the elements integers.

type

If type="predictor", x is the predictor matrix. If type="Gram", the function asks the user to provide the sample covariance or correlation matrix.

sparse

If sparse="penalty", para is a vector of 1-norm penalty parameters. If sparse="varnum", para defines the number of sparse loadings to be obtained. This option is not discussed in the paper given below, but it is convenient in practice.

lambda

Quadratic penalty parameter. Default value is 1e-6.

use.corr

Perform PCA on the correlation matrix? This option is only effective when the argument type is set "data".

max.iter

Maximum number of iterations.

trace

If TRUE, prints out its progress.

eps.conv

Convergence criterion.

Value

A "spca" object is returned. The below are some quantities which the user may be interested in:

loadings

The loadings of the sparse PCs

pev

Percentage of explained variance

var.all

Total variance of the predictors

Details

PCA is shown to be equivalent to a regression-type optimization problem, then sparse loadings are obtained by imposing the 1-norm constraint on the regression coefficients. If x is a microarray matrix, use arrayspc().

References

Zou, H., Hastie, T. and Tibshirani, R. (2006) "Sparse principal component analysis" Journal of Computational and Graphical Statistics, 15 (2), 265--286.

See Also

princomp, arrayspc

Examples

Run this code
# NOT RUN {
data(pitprops)
out1<-spca(pitprops,K=6,type="Gram",sparse="penalty",trace=TRUE,para=c(0.06,0.16,0.1,0.5,0.5,0.5))
## print the object out1
out1
out2<-spca(pitprops,K=6,type="Gram",sparse="varnum",trace=TRUE,para=c(7,4,4,1,1,1))
out2
## to see the contents of out2
names(out2) 
## to get the loadings
out2$loadings
# }

Run the code above in your browser using DataCamp Workspace