Description Usage Arguments Value Examples
This function performs PCA with cardinality constraints on the component weights.
1 2 3 4 5 6 7 8 9 10 |
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 |
itr |
The maximum number of iterations (an integer) |
Wstart |
A matrix of |
nStarts |
The number of random starts the analysis should perform. The first start will be performed with the values given by |
tol |
The convergence is determined by comparing the loss function value after each iteration, if the difference is smaller than |
printLoss |
A boolean: |
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.
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])
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.