spca: Sparse Principal Components Analysis

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/enet_funcs.R

Description

Using an alternating minimization algorithm to minimize the SPCA criterion.

Usage

1
2
3
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.

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().

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

Author(s)

Hui Zou and Trevor Hastie

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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

Example output

Loading required package: lars
Loaded lars 1.2

iterations 10
iterations 20
iterations 30
iterations 40
iterations 50
iterations 60

Call:
spca(x = pitprops, K = 6, para = c(0.06, 0.16, 0.1, 0.5, 0.5, 
    0.5), type = "Gram", sparse = "penalty", trace = TRUE)

6 sparse PCs 
Pct. of exp. var. : 28.0 14.0 13.3  7.4  6.8  6.2 
Num. of non-zero loadings :  7 4 4 1 1 1 
Sparse loadings 
           PC1    PC2    PC3 PC4 PC5 PC6
topdiam -0.477  0.000  0.000   0   0   0
length  -0.476  0.000  0.000   0   0   0
moist    0.000  0.785  0.000   0   0   0
testsg   0.000  0.619  0.000   0   0   0
ovensg   0.177  0.000  0.641   0   0   0
ringtop  0.000  0.000  0.589   0   0   0
ringbut -0.250  0.000  0.492   0   0   0
bowmax  -0.344 -0.021  0.000   0   0   0
bowdist -0.416  0.000  0.000   0   0   0
whorls  -0.400  0.000  0.000   0   0   0
clear    0.000  0.000  0.000  -1   0   0
knots    0.000  0.013  0.000   0  -1   0
diaknot  0.000  0.000 -0.016   0   0   1
iterations 10
iterations 20
iterations 30
iterations 40

Call:
spca(x = pitprops, K = 6, para = c(7, 4, 4, 1, 1, 1), type = "Gram", 
    sparse = "varnum", trace = TRUE)

6 sparse PCs 
Pct. of exp. var. : 28.2 13.9 13.1  7.4  6.8  6.3 
Num. of non-zero loadings :  7 4 4 1 1 1 
Sparse loadings 
           PC1    PC2    PC3 PC4 PC5 PC6
topdiam -0.477  0.003  0.000   0   0   0
length  -0.469  0.000  0.000   0   0   0
moist    0.000  0.785  0.000   0   0   0
testsg   0.000  0.619  0.000   0   0   0
ovensg   0.180  0.000  0.656   0   0   0
ringtop  0.000  0.000  0.589   0   0   0
ringbut -0.290  0.000  0.470   0   0   0
bowmax  -0.343 -0.029 -0.048   0   0   0
bowdist -0.414  0.000  0.000   0   0   0
whorls  -0.383  0.000  0.000   0   0   0
clear    0.000  0.000  0.000  -1   0   0
knots    0.000  0.000  0.000   0  -1   0
diaknot  0.000  0.000  0.000   0   0   1
[1] "call"     "type"     "K"        "loadings" "pev"      "var.all"  "vn"      
[8] "para"     "lambda"  
               PC1         PC2         PC3 PC4 PC5 PC6
topdiam -0.4774878  0.00273577  0.00000000   0   0   0
length  -0.4691409  0.00000000  0.00000000   0   0   0
moist    0.0000000  0.78520583  0.00000000   0   0   0
testsg   0.0000000  0.61854739  0.00000000   0   0   0
ovensg   0.1797963  0.00000000  0.65551907   0   0   0
ringtop  0.0000000  0.00000000  0.58924631   0   0   0
ringbut -0.2898492  0.00000000  0.46990985   0   0   0
bowmax  -0.3425338 -0.02904206 -0.04762634   0   0   0
bowdist -0.4138718  0.00000000  0.00000000   0   0   0
whorls  -0.3833453  0.00000000  0.00000000   0   0   0
clear    0.0000000  0.00000000  0.00000000  -1   0   0
knots    0.0000000  0.00000000  0.00000000   0  -1   0
diaknot  0.0000000  0.00000000  0.00000000   0   0   1

elasticnet documentation built on July 1, 2020, 11:48 p.m.

Related to spca in elasticnet...