Title: | Yet Another Canonical Correlation Analysis Package |
---|---|
Description: | An alternative canonical correlation/redundancy analysis function, with associated print, plot, and summary methods. A method for generating helio plots is also included. |
Authors: | Carter T. Butts <[email protected]> |
Maintainer: | Carter T. Butts <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.4-2 |
Built: | 2024-11-10 06:28:45 UTC |
Source: | CRAN |
This package provides an alternative canonical correlation/redundancy analysis function, with associated print, plot, and summary methods. A method for generating helio plots is also included.
For details on using the package, see cca
and helio.plot
.
Carter T. Butts <[email protected]>
Maintainer: Carter T. Butts <[email protected]>
Mardia, K. V.; Kent, J. T.; and Bibby, J. M. 1979. Multivariate Analysis. London: Academic Press.
Performs a canonical correlation (and canonical redundancy) analysis on two sets of variables.
cca(x, y, xlab = colnames(x), ylab = colnames(y), xcenter = TRUE, ycenter = TRUE, xscale = FALSE, yscale = FALSE, standardize.scores = TRUE, use = "complete.obs", na.rm = TRUE, use.eigs = FALSE, max.dim = Inf, reg.param = NULL) ## S3 method for class 'cca' plot(x, ...) ## S3 method for class 'cca' print(x, ...) ## S3 method for class 'cca' summary(object, ...)
cca(x, y, xlab = colnames(x), ylab = colnames(y), xcenter = TRUE, ycenter = TRUE, xscale = FALSE, yscale = FALSE, standardize.scores = TRUE, use = "complete.obs", na.rm = TRUE, use.eigs = FALSE, max.dim = Inf, reg.param = NULL) ## S3 method for class 'cca' plot(x, ...) ## S3 method for class 'cca' print(x, ...) ## S3 method for class 'cca' summary(object, ...)
x |
for |
y |
a single vector or a matrix whose columns contain the |
xlab |
an optional vector of |
ylab |
an optional vector of |
xcenter |
boolean; demean the |
ycenter |
boolean; demean the |
xscale |
boolean; scale the |
yscale |
boolean; scale the |
standardize.scores |
boolean; rescale scores (and coefficients) to produce scores of unit variance? |
use |
|
na.rm |
boolean; remove missing values during redundancy analysis? |
use.eigs |
|
max.dim |
maximum number of canonical variates to extract (only relevant if less than the minimum of the number of columns of |
reg.param |
an optional L2 regularization parameter (or vector thereof). |
object |
a |
... |
additional arguments. |
Canonical correlation analysis (CCA) is a form of linear subspace analysis, and involves the projection of two sets of vectors (here, the variable sets x
and y
) onto a joint subspace. The goal of (CCA) is to find a squence of linear transformations of each variable set, such that the correlations between the transformed variables are maximized (under the proviso that each transformed variable must be orthogonal to those preceding it). These transformed variables – known as “canonical variates” (CVs) – can be thought of as expressing the common variation across the data sets, in a manner analogous to the role of principal components in within-set analysis (see, e.g., princomp
). Since the rank of the joint subspace is equal to the minimum of the ranks of the two spaces spanned by the initial data vectors, it follows that the number of CVs will usually be equal to the minimum of the number of x
and y
variables (perhaps fewer, if the sets are not of full rank or if max.dim
is used to constrain the number of variables extracted).
Formally, we may describe the CCA solution as follows. Given data matrices and
, let
,
,
and
be the respective sample covariance matrices for
versus itself,
versus
,
versus
, and
versus itself. Now, for some
less than or equal to the minimum rank of
and
, let
be the
th eigenvector of
, with corresponding eigenvalue
. Then the vector
contains the coefficients projecting
onto the
th canonical variate; the corresponding scores are given by
. Similarly, let
be the
th eigenvector of
. Then
contains the coefficients projecting
onto the
th canonical variate (with scores
). The eigenvalue in the second case will be the same as the first, and corresponds to the square of the
th canonical correlation for the CCA solution – that is, the correlation between the
and
scores on the
th canonical variate. Since the canonical correlation structure is unaffected by rescaling of the canonical variate scores, it is common to adjust the coefficients
and
to ensure that the resulting scores have unit variance; this option is controlled here via the
standardize.scores
argument.
CCA output can be fairly complex. Quantities of particular interest include the correlations between the original variables in each set and their respective canonical variates (structural correlations or loadings), the coefficients which take the original variables into the CVs, and of course the correlations between the CV scores in one set and their corresponding scores in the opposite set (the canonical correlations). The canonical correlations provide a basic measure of concordance between the transformed variables, but are surprisingly uninformative by themselves; canonical redundancies (see below) are of more typical interest. Interpretation of CVs is usually performed by inspection of loadings, which reveal the extent to which each CV is associated with particular variables in each set. The squared loadings, in particular, convey the fraction of variance in each original variable which is accounted for by a given CV (though not necessarily by the variables in the opposite set!).
A common interest in the context of CCA is the extent to which the variance of one set of variables can be accounted for by the other (in the usual least squares sense). While it is tempting to interpret the squared canonical correlations in this manner, this is incorrect: the squared canonical correlations convey the fraction of variance in the CV scores from one variable set which can be accounted for by scores from the other, but say nothing about the extent to which the CVs themselves account for variation in the original variables. The variance in one set explainable by the other is instead expressed via the so-called redundancy index, which combines the squared canonical correlations with the canonical adequacy (within-set variance accounted for) for each CV. The use of the redundancy index in this way is sometimes called “(canonical) redundancy analysis”, although it is simply an alternate means of presenting CCA results.
As the name of the technique implies, CCA is a symmetric procedure: the designation of one variable set as x
and another as y
is arbitrary, and may be reversed without incident. (Note, however, that the coefficients and redundancies are set-specific, and will also be reversed in this case.) CCA with one x
or y
variable is equivalent to OLS regression (with the squared canonical correlation corresponding to the ), and CCA on one variable pair yields the familiar Pearson product-moment correlation. Centering and scaling data prior to analysis is equivalent to working with correlation matrices in the underlying analysis (with interpretation/effects analogous to the principal components case).
Finding the CCA solution can pose numerical challenges, ironically more so when the degree of potential dimension reduction is highest. In recalcitrant cases, it can be useful to apply regularization to the solution for purposes of stabilization. The optional reg.param
can be used for this purpose: if given as a single numeric value, it adds an L2 (aka “ridge”) penalty to each variable set with the corresponding multiplier value. reg.param
can also be given as a vector of length 2, in which case the first value is applied to the x
variables and the second is applied to the y
variables. Relatedly, in high-dimension/low-rank problems it can be useful to extract a much smaller number of canonical variates than the nominal maximum. This can be controlled by max.dim
, though the default diagonalization method computes the entire eigendecomposition prior to canonical variate extraction. In such cases, it can be helpful to employ the alternative diagonalization method controlled by the use.eigs
argument to compute only those dimensions that are actually required. Experience suggests that this method (eigs
) is less stable than the base eigen
, but it can be much faster in high-dimensional settings.
An object of class cca
, whose elements are as follows:
corr |
Canonical correlations. |
corrsq |
Squared canonical correlations (shared variance across canonical variates). |
xcoef |
Coefficients for the |
ycoef |
Coefficients for the |
canvarx |
Canonical variate scores for the |
canvary |
Canonical variate scores for the |
xstructcorr |
Structural correlations (loadings) for |
ystructcorr |
Structural correlations (loadings) for |
xstructcorrsq |
Squared structural correlations for |
ystructcorrsq |
Squared structural correlations for |
xcrosscorr |
Canonical cross-loadings for |
ycrosscorr |
Canonical cross-loadings for |
xcrosscorrsq |
Squared canonical cross-loadings for |
ycrosscorrsq |
Squared canonical cross-loadings for |
xcancom |
Canonical communalities for |
ycancom |
Canonical communalities for |
xcanvad |
Canonical variate adequacies for |
ycanvad |
Canonical variate adequacies for |
xvrd |
Canonical redundancies for |
yvrd |
Canonical redundancies for |
xrd |
Total canonical redundancy for |
yrd |
Total canonical redundancy for |
chisq |
Sequential |
df |
Degrees of freedom for Bartlett's test. |
xlab |
Variable names for |
ylab |
Variable names for |
reg.param |
Regularization parameter (if any). |
Carter T. Butts <[email protected]>
Mardia, K. V.; Kent, J. T.; and Bibby, J. M. 1979. Multivariate Analysis. London: Academic Press.
#Example parallels the R builtin cancor example data(LifeCycleSavings) pop <- LifeCycleSavings[, 2:3] oec <- LifeCycleSavings[, -(2:3)] cca.fit <- cca(pop, oec) cca.regfit <- cca(pop, oec, reg.param=1) # Some minimal regularization #View the results cca.fit summary(cca.fit) plot(cca.fit) cca.regfit #Not a vast difference, usually....
#Example parallels the R builtin cancor example data(LifeCycleSavings) pop <- LifeCycleSavings[, 2:3] oec <- LifeCycleSavings[, -(2:3)] cca.fit <- cca(pop, oec) cca.regfit <- cca(pop, oec, reg.param=1) # Some minimal regularization #View the results cca.fit summary(cca.fit) plot(cca.fit) cca.regfit #Not a vast difference, usually....
Tests a series of canonical correlations (sequentially) against the null hypothesis that the tested coefficient and all succeeding coefficients are zero.
F.test.cca(x, ...) ## S3 method for class 'F.test.cca' print(x, ...)
F.test.cca(x, ...) ## S3 method for class 'F.test.cca' print(x, ...)
x |
a |
... |
additional arguments. |
Several related tests have been proposed for the evaluation of canonical correlations (including Bartlett's Chi-squared test, which is computed by default within cca
). This function employs Rao's statistic (related to Wilks' Lambda) as the basis for an F test of each coefficient (and all others in ascending sequence) against the hypothesis that the associated population correlations are zero.
An object of class F.test.cca
, whose elements are as follows:
corr |
Canonical correlations. |
statistic |
Squared canonical correlations (shared variance across canonical variates). |
parameter |
Coefficients for the |
p.value |
Coefficients for the |
method |
Canonical variate scores for the |
data.name |
Canonical variate scores for the |
Nicholas L. Crookston <[email protected]>
Carter T. Butts <[email protected]>
Mardia, K. V.; Kent, J. T.; and Bibby, J. M. 1979. Multivariate Analysis. London: Academic Press.
#Example: perceived personal attributes versus professional performance #for US Judges data(USJudgeRatings) personal <- USJudgeRatings[,c("INTG","DMNR","DILG","FAMI","PHYS")] performance <- USJudgeRatings[,c("CFMG","DECI","PREP","ORAL","WRIT")] cca.fit <- cca(personal, performance) #Test the canonical correlations (see also summary(cca.fit)) F.test.cca(cca.fit)
#Example: perceived personal attributes versus professional performance #for US Judges data(USJudgeRatings) personal <- USJudgeRatings[,c("INTG","DMNR","DILG","FAMI","PHYS")] performance <- USJudgeRatings[,c("CFMG","DECI","PREP","ORAL","WRIT")] cca.fit <- cca(personal, performance) #Test the canonical correlations (see also summary(cca.fit)) F.test.cca(cca.fit)
Displays data using a circular layout; function is designed to be used with cca
objects, but could perhaps be rigged for use in other circumstances.
helio.plot(c, cv = 1, xvlab = c$xlab, yvlab = c$ylab, x.name = "X Variables", y.name = "Y Variables", lab.cex = 1, wid.fact = 0.75, main = "Helio Plot", sub = paste("Canonical Variate", cv, sep = ""), zero.rad = 30, range.rad = 20, name.padding = 5, name.cex = 1.5, axis.circ = c(-1, 1), x.group = rep(0, dim(c$xstructcorr)[1]), y.group = rep(0, dim(c$ystructcorr)[1]), type = "correlation")
helio.plot(c, cv = 1, xvlab = c$xlab, yvlab = c$ylab, x.name = "X Variables", y.name = "Y Variables", lab.cex = 1, wid.fact = 0.75, main = "Helio Plot", sub = paste("Canonical Variate", cv, sep = ""), zero.rad = 30, range.rad = 20, name.padding = 5, name.cex = 1.5, axis.circ = c(-1, 1), x.group = rep(0, dim(c$xstructcorr)[1]), y.group = rep(0, dim(c$ystructcorr)[1]), type = "correlation")
c |
object to be plotted (generally output from |
cv |
the canonical variate to display. |
xvlab |
X variable labels. |
yvlab |
Y variable labels. |
x.name |
name for the X variable set. |
y.name |
name for the Y variable set. |
lab.cex |
character expansion for plot labels. |
wid.fact |
width multiplier for data bars. |
main |
plot main title. |
sub |
plot subtitle. |
zero.rad |
radius for the zero-value reference circle. |
range.rad |
difference between inner and outer plotting radius. |
name.padding |
offset for variable names. |
name.cex |
character expansion for variable names. |
axis.circ |
location to draw axis circles. |
x.group |
optional grouping vector for X variables. |
y.group |
optional grouping vector for Y variables. |
type |
one of “correlation” or “variance”, depending on the type of data to be displayed. |
Helio plots display data in radial bars, with larger values pointing outward from a base reference circle and smaller (more negative) values pointing inward). Such plots are well-suited to the display of multivariate information with several groups of variables, as with canonical correlation analysis.
None.
Carter T. Butts <[email protected]>
data(LifeCycleSavings) pop <- LifeCycleSavings[, 2:3] oec <- LifeCycleSavings[, -(2:3)] cca.fit <- cca(pop, oec) #Show loadings on first canonical variate helio.plot(cca.fit, x.name="Population Variables", y.name="Economic Variables") #Show variances on second canonical variate helio.plot(cca.fit, cv=2, x.name="Population Variables", y.name="Economic Variables", type="variance")
data(LifeCycleSavings) pop <- LifeCycleSavings[, 2:3] oec <- LifeCycleSavings[, -(2:3)] cca.fit <- cca(pop, oec) #Show loadings on first canonical variate helio.plot(cca.fit, x.name="Population Variables", y.name="Economic Variables") #Show variances on second canonical variate helio.plot(cca.fit, cv=2, x.name="Population Variables", y.name="Economic Variables", type="variance")