nscancor {nscancor} | R Documentation |
Non-Negative and Sparse CCA
Description
Performs a canonical correlation analysis (CCA) where constraints such as
non-negativity or sparsity are enforced on the canonical vectors. The result
of the analysis is returned as a list of class nscancor
, which
contains a superset of the elements returned by cancor
.
Usage
nscancor(
x,
y,
xcenter = TRUE,
ycenter = TRUE,
xscale = FALSE,
yscale = FALSE,
nvar = min(dim(x), dim(y)),
xpredict,
ypredict,
cor_tol = NULL,
nrestart = 10,
iter_tol = 0,
iter_max = 50,
partial_model = NULL,
verbosity = 0
)
Arguments
x |
a numeric matrix which provides the data from the first domain |
y |
a numeric matrix which provides the data from the second domain |
xcenter |
a logical value indicating whether the empirical mean of (each
column of) |
ycenter |
analogous to |
xscale |
a logical value indicating whether the columns of |
yscale |
analogous to |
nvar |
the number of canonical variables to be computed for each domain.
With the default setting, canonical variables are computed until either
|
xpredict |
the regression function to predict the canonical variable for
|
ypredict |
analogous to |
cor_tol |
a threshold indicating the magnitude below which canonical
variables should be omitted. Variables are omitted if their explained
correlations are less than or equal to |
nrestart |
the number of random restarts for computing the canonical variables via iterated regression steps. The solution achieving maximum explained correlation over all random restarts is kept. A value greater than one can help to avoid poor local maxima. |
iter_tol |
If the relative change of the objective is less than
|
iter_max |
the maximum number of iterations to be performed. The
procedure is terminated if either the |
partial_model |
|
verbosity |
an integer specifying the verbosity level. Greater values result in more output, the default is to be quiet. |
Details
nscancor
computes the canonical vectors (called xcoef
and
ycoef
) using iterated regression steps, where the constraints suitable
for each domain are enforced by choosing the appropriate regression method.
See Sigg et al. (2007) for an early application of the principle (not yet
including generalized deflation).
Because constrained canonical vectors no longer correspond to true
eigenvectors of the cross-covariance matrix and are usually not pairwise
conjugate (i.e. the canonical variables are not uncorrelated), special
attention needs to be paid when computing more than a single pair of
canonical vectors. nscancor
implements a generalized deflation (GD)
scheme which builds on GD for PCA as proposed by Mackey (2009). For each
domain, a basis of the space spanned by the previous canonical variables is
computed. Then, the correlation of the current pair of canonical variables is
maximized after projecting each current canonical vector to the
ortho-complement space of its respective basis. This procedure maximizes the
additional correlation not explained by previous canonical variables, and is
identical to standard CCA if the canonical vectors are the eigenvectors of
the cross-covariance matrix.
See the references for further details.
Value
A list of class nscancor
containing
the following elements:
cor |
the additional correlation explained by
each pair of canonical variables, see |
xcoef |
the
matrix containing the canonical vectors related to |
ycoef |
analogous to |
xcenter |
if |
ycenter |
analogous to |
xscale |
if |
yscale |
analogous to |
xp |
the deflated
data matrix corresponding to |
yp |
analogous to |
References
Sigg, C. and Fischer, B. and Ommer, B. and Roth, V. and Buhmann, J. (2007) Nonnegative CCA for Audiovisual Source Separation. In Proceedings of the 2007 IEEE Workshop on Machine Learning for Signal Processing (pp. 253–258).
Mackey, L. (2009) Deflation Methods for Sparse PCA. In Advances in Neural Information Processing Systems (pp. 1017–1024).
See Also
Examples
data(nutrimouse, package = "CCA")
set.seed(1)
###
# Unconstrained CCA, produces results close to calling
# cancor(nutrimouse$gene[ , 1:5], nutrimouse$lipid)
ypredict <- function(x, yc, cc) {
return(MASS::ginv(x)%*%yc)
}
xpredict <- function(y, xc, cc) {
return(MASS::ginv(y)%*%xc)
}
cc <- nscancor(nutrimouse$gene[ , 1:5], nutrimouse$lipid, xpredict = xpredict,
ypredict = ypredict)
print(cc$cor)
###
# Non-negative sparse CCA using glmnet() as the regression function, where
# different regularizers are enforced on the different data domains and pairs
# of canonical variables.
dfmax_w <- c(40, 15, 10)
ypredict <- function(x, yc, cc) {
en <- glmnet::glmnet(x, yc, alpha = 0.5, intercept = FALSE,
dfmax = dfmax_w[cc], lower.limits = 0)
W <- coef(en)
return(W[2:nrow(W), ncol(W)])
}
dfmax_v <- c(7, 5, 5)
xpredict <- function(y, xc, cc) {
en <- glmnet::glmnet(y, xc, alpha = 0.5, intercept = FALSE,
dfmax = dfmax_v[cc])
V <- coef(en)
return(V[2:nrow(V), ncol(V)])
}
nscc <- nscancor(nutrimouse$gene, nutrimouse$lipid, nvar = 2,
xpredict = xpredict, ypredict = ypredict)
# continue the computation of canonical variables from a partial model
nscc <- nscancor(nutrimouse$gene, nutrimouse$lipid, nvar = 3,
xpredict = xpredict, ypredict = ypredict,
partial_model = nscc)
print(nscc$cor)
print(nscc$xcoef)
print(nscc$ycoef)