Description Usage Arguments Details Value References See Also Examples
Performs a canonical correlation analysis (CCA) where constraints such as
nonnegativity 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
.
1 2 3 4 
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. 
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 avvropriate 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 crosscovariance 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
orthocomplement 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 crosscovariance matrix.
See the references for further details.
nscancor
returns 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 
anologous to 
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 (vv. 253–258).
Mackey, L. (2009) Deflation Methods for Sparse PCA. In Advances in Neural Information Processing Systems (vv. 1017–1024).
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49  if (requireNamespace("glmnet", quietly = TRUE) &&
requireNamespace("MASS", quietly = TRUE) &&
requireNamespace("CCA", quietly = TRUE)) {
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)
}
nscancor(nutrimouse$gene[ , 1:5], nutrimouse$lipid, xpredict = xpredict,
ypredict = ypredict)
###
# Nonnegative sparse CCA using glmnet() as the regression function, where
# different regularisers 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)
}

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.