naginterfaces.library.mv.canon_​corr

naginterfaces.library.mv.canon_corr(z, isz, nx, ny, mcv, tol, wt=None)[source]

canon_corr performs canonical correlation analysis upon input data matrices.

For full information please refer to the NAG Library document for g03ad

https://www.nag.com/numeric/nl/nagdoc_28.5/flhtml/g03/g03adf.html

Parameters
zfloat, array-like, shape

must contain the th observation for the th variable, for , for .

Both and variables are to be included in , the indicator array, , being used to assign the variables in to the or sets as appropriate.

iszint, array-like, shape

indicates whether or not the th variable is included in the analysis and to which set of variables it belongs.

The variable contained in the th column of is included as an variable in the analysis.

The variable contained in the th column of is included as a variable in the analysis.

The variable contained in the th column of is not included in the analysis.

nxint

The number of variables in the analysis, .

nyint

The number of variables in the analysis, .

mcvint

An upper limit to the number of canonical variates.

tolfloat

The value of is used to decide if the variables are of full rank and, if not, what is the rank of the variables. The smaller the value of the stricter the criterion for selecting the singular value decomposition. If a non-negative value of less than machine precision is entered, the square root of machine precision is used instead.

wtNone or float, array-like, shape , optional

The elements of must contain the weights to be used in the analysis. The effective number of observations is the sum of the weights. If then the th observation is not included in the analysis.

If weights are not provided then must be set to None and the effective number of observations is .

Returns
efloat, ndarray, shape

The statistics of the canonical variate analysis.

The canonical correlations, , for .

The eigenvalues of , , for .

The proportion of variation explained by the th canonical variate, for .

The statistic for the th canonical variate, for .

The degrees of freedom for statistic for the th canonical variate, for .

The significance level for the statistic for the th canonical variate, for .

ncvint

The number of canonical correlations, . This will be the minimum of the rank of and the rank of .

cvxfloat, ndarray, shape

The canonical variate loadings for the variables. contains the loading coefficient for the th variable on the th canonical variate.

cvyfloat, ndarray, shape

The canonical variate loadings for the variables. contains the loading coefficient for the th variable on the th canonical variate.

Raises
NagValueError
(errno )

On entry, and .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: or .

(errno )

On entry, and .

Constraint: .

(errno )

On entry, and .

Constraint: .

(errno )

On entry, and .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, and .

Constraint: .

(errno )

On entry, , expected .

Constraint: must be consistent with .

(errno )

On entry, , expected .

Constraint: must be consistent with .

(errno )

On entry, the effective number of observations is less than .

(errno )

The singular value decomposition has failed to converge.

Warns
NagAlgorithmicWarning
(errno )

A canonical correlation is equal to .

(errno )

On entry, the rank of the matrix is .

(errno )

On entry, the rank of the matrix is .

Notes

In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.

Let there be two sets of variables, and . For a sample of observations on variables in a data matrix and variables in a data matrix , canonical correlation analysis seeks to find a small number of linear combinations of each set of variables in order to explain or summarise the relationships between them. The variables thus formed are known as canonical variates.

Let the variance-covariance matrix of the two datasets be

and let

then the canonical correlations can be calculated from the eigenvalues of the matrix . However, canon_corr calculates the canonical correlations by means of a singular value decomposition (SVD) of a matrix . If the rank of the data matrix is and the rank of the data matrix is , and both and have had variable (column) means subtracted then the matrix is given by:

where is the first columns of the orthogonal matrix either from the decomposition of if is of full column rank, i.e., :

or from the SVD of if :

Similarly is the first columns of the orthogonal matrix either from the decomposition of if is of full column rank, i.e., :

or from the SVD of if :

Let the SVD of be:

then the nonzero elements of the diagonal matrix , , for , are the canonical correlations associated with the canonical variates, where .

The eigenvalues, , of the matrix are given by:

The value of gives the proportion of variation explained by the th canonical variate. The values of the ’s give an indication as to how many canonical variates are needed to adequately describe the data, i.e., the dimensionality of the problem.

To test for a significant dimensionality greater than the statistic:

can be used. This is asymptotically distributed as a -distribution with degrees of freedom. If the test for is not significant, then the remaining tests for should be ignored.

The loadings for the canonical variates are calculated from the matrices and respectively. These matrices are scaled so that the canonical variates have unit variance.

References

Hastings, N A J and Peacock, J B, 1975, Statistical Distributions, Butterworth

Kendall, M G and Stuart, A, 1976, The Advanced Theory of Statistics (Volume 3), (3rd Edition), Griffin

Morrison, D F, 1967, Multivariate Statistical Methods, McGraw–Hill