The routine may be called by the names g03acf or nagf_mv_canon_var.
3Description
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, g03acf 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).
4References
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
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.
Constraint:
, or .
2: – IntegerInput
On entry: , the number of observations.
Constraint:
.
3: – IntegerInput
On entry: , the total number of variables.
Constraint:
.
4: – Real (Kind=nag_wp) arrayInput
On entry: must contain the th observation for the th variable, for and .
5: – IntegerInput
On entry: the first dimension of the array x as declared in the (sub)program from which g03acf is called.
Constraint:
.
6: – Integer arrayInput
On entry: indicates whether or not the th variable is to be included in the analysis.
If
, the variables contained in the th column of x is included in the canonical variate analysis, for .
On exit: gives the number of observations in group , for .
12: – Real (Kind=nag_wp) arrayOutput
On exit: contains the mean of the th canonical variate for the th group, for and ; the remaining columns, if any, are used as workspace.
13: – IntegerInput
On entry: the first dimension of the array cvm as declared in the (sub)program from which g03acf is called.
Constraint:
.
14: – Real (Kind=nag_wp) arrayOutput
On exit: 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 .
15: – IntegerInput
On entry: the first dimension of the array e as declared in the (sub)program from which g03acf is called.
Constraint:
.
16: – IntegerOutput
On exit: the number of canonical variates, . This will be the minimum of and the rank of x.
17: – Real (Kind=nag_wp) arrayOutput
On exit: the canonical variate loadings.
contains the loading coefficient for the th variable on the th canonical variate, for and ; the remaining columns, if any, are used as workspace.
18: – IntegerInput
On entry: the first dimension of the array cvx as declared in the (sub)program from which g03acf is called.
Constraint:
.
19: – Real (Kind=nag_wp)Input
On entry: the value of tol 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 tol the stricter the criterion for selecting the singular value decomposition. If a non-negative value of tol less than machine precision is entered, the square root of machine precision is used instead.
Constraint:
.
20: – IntegerOutput
On exit: the rank of the dependent variables.
If the variables are of full rank then .
If the variables are not of full rank then irankx is an estimate of the rank of the dependent variables. irankx is calculated as the number of singular values greater than .
21: – Real (Kind=nag_wp) arrayWorkspace
22: – IntegerInput
On entry: the dimension of the array wk as declared in the (sub)program from which g03acf is called.
Constraints:
if , ;
if , .
23: – IntegerInput/Output
On entry: ifail must be set to , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended. When the value or is used it is essential to test the value of ifail on exit.
On exit: unless the routine detects an error or a warning has been flagged (see Section 6).
6Error Indicators and Warnings
If on entry or , explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
On entry,
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: , or .
On entry, and .
Constraint: .
On entry, , and .
Constraint: .
On entry, , expected .
Constraint: must be consistent with isx.
The singular value decomposition has failed to converge. This is an unlikely error exit.
A canonical correlation is equal to . This will happen if the variables provide an exact indication as to which group every observation is allocated.
Less than groups have nonzero membership.
The effective number of observations is less than the effective number of groups plus number of variables.
The rank of x is . This will happen if all the variables are constants.
An unexpected error has been triggered by this routine. Please
contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
7Accuracy
As the computation involves the use of orthogonal matrices and a singular value decomposition rather than the traditional computing of a sum of squares matrix and the use of an eigenvalue decomposition, g03acf should be less affected by ill-conditioned problems.
8Parallelism and Performance
g03acf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g03acf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.
9Further Comments
None.
10Example
This example uses a sample of nine observations, each consisting of three variables plus a group indicator. There are three groups. An unweighted canonical variate analysis is performed and the results printed.