naginterfaces.library.mv.canon_var¶
- naginterfaces.library.mv.canon_var(weight, x, isx, ing, ng, wt, tol)[source]¶
canon_var
performs a canonical variate (canonical discrimination) analysis.For full information please refer to the NAG Library document for g03ac
https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/g03/g03acf.html
- Parameters
- weightstr, length 1
Indicates if weights are to be used.
No weights are used.
or
Weights are used and must be supplied in .
If , the weights are treated as frequencies and the effective number of observations is the sum of the weights.
If , the weights are treated as being inversely proportional to the variance of the observations and the effective number of observations is the number of observations with nonzero weights.
- xfloat, array-like, shape
must contain the th observation for the th variable, for , for .
- isxint, array-like, shape
indicates whether or not the th variable is to be included in the analysis.
If , the variables contained in the th column of is included in the canonical variate analysis, for .
- ingint, array-like, shape
indicates which group the th observation is in, for . The effective number of groups is the number of groups with nonzero membership.
- ngint
The number of groups, .
- wtfloat, array-like, shape
Note: the required length for this argument is determined as follows: if : ; otherwise: .
If or , the first elements of must contain the weights to be used in the analysis.
If , the th observation is not included in the analysis.
If , is not referenced.
- 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.
- Returns
- nigint, ndarray, shape
gives the number of observations in group , for .
- cvmfloat, ndarray, shape
contains the mean of the th canonical variate for the th group, for , for ; the remaining columns, if any, are used as workspace.
- efloat, ndarray, shape
The statistics of the canonical variate analysis.
The canonical correlations, , for .
The eigenvalues of the within-group sum of squares matrix, , 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 variates, . This will be the minimum of and the rank of .
- cvxfloat, ndarray, shape
The canonical variate loadings. contains the loading coefficient for the th variable on the th canonical variate, for , for ; the remaining columns, if any, are used as workspace.
- irankxint
The rank of the dependent variables.
If the variables are of full rank then .
If the variables are not of full rank then is an estimate of the rank of the dependent variables. is calculated as the number of singular values greater than .
- Raises
- NagValueError
- (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, , and .
Constraint: .
- (errno )
On entry, , expected .
Constraint: must be consistent with .
- (errno )
The singular value decomposition has failed to converge.
- (errno )
The effective number of observations is less than the effective number of groups plus number of variables.
- (errno )
Less than groups have nonzero membership.
- Warns
- NagAlgorithmicWarning
- (errno )
A canonical correlation is equal to .
- (errno )
The rank of 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 a sample of observations on variables in a data matrix come from groups with observations in each group, . Canonical variate analysis finds the linear combination of the variables that maximizes the ratio of between-group to within-group variation. The variables formed, the canonical variates can then be used to discriminate between groups.
The canonical variates can be calculated from the eigenvectors of the within-group sums of squares and cross-products matrix. However,
canon_var
calculates the canonical variates by means of a singular value decomposition (SVD) of a matrix . Let the data matrix with variable (column) means subtracted be , and let its rank be ; then the by () matrix is given by:where is an orthogonal matrix that defines the groups and is the first rows of the orthogonal matrix either from the decomposition of :
if is of full column rank, i.e., , else from the SVD of :
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 within-group sums of squares matrix are given by:
and 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 matrix . This matrix is scaled so that the canonical variates have unit within-group variance.
In addition to the canonical variates loadings the means for each canonical variate are calculated for each group.
Weights can be used with the analysis, in which case the weighted means are subtracted from each column and then each row is scaled by an amount , where is the weight for the th observation (row).
- References
Chatfield, C and Collins, A J, 1980, Introduction to Multivariate Analysis, Chapman and Hall
Gnanadesikan, R, 1977, Methods for Statistical Data Analysis of Multivariate Observations, Wiley
Hammarling, S, 1985, The singular value decomposition in multivariate statistics, SIGNUM Newsl. (20(3)), 2–25
Kendall, M G and Stuart, A, 1969, The Advanced Theory of Statistics (Volume 1), (3rd Edition), Griffin