ccpca: ccpca: Sparse pca with cardinality constraints on the...

Description Usage Arguments Value Examples

View source: R/RcppExports.R

Description

This function performs PCA with cardinality constraints on the component weights.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
ccpca(
  X,
  ncomp,
  nzeros,
  itr,
  Wstart,
  nStarts = 1L,
  tol = 1e-07,
  printLoss = TRUE
)

Arguments

X

A data matrix of class 'matrix'

ncomp

The number of components to estimate (an integer)

nzeros

A vector of length ncomp containing the number of desired zeros in the columns of the component weight matrix W

itr

The maximum number of iterations (an integer)

Wstart

A matrix of ncomp columns and nrow(X) rows with starting values for the component weight matrix W, if Wstart only contains zeros, a warm start is used: the first ncomp right singular vectors of X

nStarts

The number of random starts the analysis should perform. The first start will be performed with the values given by Wstart. The consecutive starts will be Wstart plus a matrix with random uniform values times the current start number (the first start has index zero). The default value is 1.

tol

The convergence is determined by comparing the loss function value after each iteration, if the difference is smaller than tol the analysis is converged. The default value is 10e-8

printLoss

A boolean: TRUE will print the loss function value each 10th iteration.

Value

A list containing:
W A matrix containing the component weights
P A matrix containing the loadings
loss A numeric variable containing the minimum loss function value of all the nStarts starts
converged A boolean containing TRUE if converged FALSE if not converged.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
I <- 100
J <- 50 
ncomp <- 3
X <- matrix(rnorm(I*J), I, J)

ccpca(X = X, ncomp = ncomp,  nzeros = c(10, 20, 30), itr = 100000, 
     Wstart = matrix(0, J, ncomp), nStarts = 1, tol = 10^-8, printLoss = TRUE)

# Extended example: Perform CCPCA, with oracle information
# create sample data
ncomp <- 3 
J <- 30
comdis <- matrix(1, J, ncomp)

comdis <- sparsify(comdis, 0.5) #set 10 percent of the 1's to zero
variances <- makeVariance(varianceOfComps = c(100, 80, 90), J = J, error = 0.05) #create realistic eigenvalues
dat <- makeDat(n = 100, comdis = comdis, variances = variances)
X <- dat$X

#check how many zero's are in the data generating model
nzeros <- apply(dat$P[, 1:ncomp], 2, function(x) {return(sum(x == 0))} )
nzeros

#run the analysis with oracle information of the exact number of zero's in the component weights 
results <- ccpca(X = X, ncomp = ncomp,  nzeros = nzeros, itr = 10000000, 
      Wstart = matrix(0, J, ncomp), nStarts = 1, tol = 10^-8, printLoss = TRUE)

#inspect the results
head(results$W) 
head(dat$P[, 1:ncomp])

trbKnl/sparseWeightBasedPCA documentation built on July 22, 2020, 10:29 p.m.