Learn R Programming

cpca (version 0.1.2)

cpc: Function cpc.

Description

This function computes the CPCA from a given set of covariance matrices (of different groups).

Usage

cpc(X, method = "stepwise", k = 0, iter = 30, threshold = 0, ...)

Arguments

X
An array of three dimensions: the 3rd dimension encodes the groups and the first two dimension contain the covariance matrices.
method
The name of the method for computing the CPCA. The default value is "stepwise", which is the stepwise algorithm by Trendafilov.
k
The number of components to be computed (all if it is 0). This paramter is valid if the given method supports built-in ordering of the eigvenvectors. The default value is 0, that means computing of all the components.
iter
The maximum number of iterations. The parameter is valid for the stepwise algorithm by Trendafilov, that is applied in the power algorithm for estimation a single component. The default value is 30.
threshold
The threshold value of the captured variance, which is reserved for further extensions.
...
Other parameters.

Value

A list several slots: CPC rotation matrix with eigenvectors in columns; ncomp the number of components evaluated (equal to the number of columns in CPC).

Details

Currently, the only the stepwise algorithm by Trendafilov is supported.

References

Trendafilov (2010). Stepwise estimation of common principal components. Computational Statistics & Data Analysis, 54(12), 3446-3457. doi:10.1016/j.csda.2010.03.010

Examples

Run this code
require(plyr)
require(abind)

data(iris)

C <- daply(iris, "Species", function(x) cov(x[, -ncol(x)]))
C <- aperm(C, c(2, 3, 1)) # put the 1st dimension to the end

# default call
mod1 <- cpc(C)
round(mod1$CPC, 2)

# compute only first two CPCs
mod2 <- cpc(C, k = 2)
round(mod2$CPC, 2)

Run the code above in your browser using DataLab