NAG Library Routine Document
G03ACF
1 Purpose
G03ACF performs a canonical variate (canonical discrimination) analysis.
2 Specification
SUBROUTINE G03ACF ( |
WEIGHT, N, M, X, LDX, ISX, NX, ING, NG, WT, NIG, CVM, LDCVM, E, LDE, NCV, CVX, LDCVX, TOL, IRANKX, WK, IWK, IFAIL) |
INTEGER |
N, M, LDX, ISX(M), NX, ING(N), NG, NIG(NG), LDCVM, LDE, NCV, LDCVX, IRANKX, IWK, IFAIL |
REAL (KIND=nag_wp) |
X(LDX,M), WT(*), CVM(LDCVM,NX), E(LDE,6), CVX(LDCVX,NG-1), TOL, WK(IWK) |
CHARACTER(1) |
WEIGHT |
|
3 Description
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
by
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).
4 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
5 Parameters
- 1: – CHARACTER(1)Input
-
On entry: indicates if weights are to be used.
- No weights are used.
- or
- Weights are used and must be supplied in WT.
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
.
Constraint:
for
NX values of
.
- 7: – INTEGERInput
-
On entry: the number of variables in the analysis, .
Constraint:
.
- 8: – INTEGER arrayInput
-
On entry: indicates which group the th observation is in, for . The effective number of groups is the number of groups with nonzero membership.
Constraint:
, for .
- 9: – INTEGERInput
-
On entry: the number of groups, .
Constraint:
.
- 10: – REAL (KIND=nag_wp) arrayInput
-
Note: the dimension of the array
WT
must be at least
if
or
, and at least
otherwise.
On entry: if
or
, the first
elements of
WT must contain the weights to be used in the analysis.
If , the th observation is not included in the analysis.
If
,
WT is not referenced.
Constraints:
- , for ;
- .
- 11: – INTEGER arrayOutput
-
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
,
. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
.
When the value 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).
6 Error 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, | , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | and , |
or | and , |
or | , or , |
or | . |
-
On entry, | or and a value of . |
-
On entry, | a value of , |
or | a value of . |
-
On entry, the number of variables to be included in the analysis as indicated by
ISX is not equal to
NX.
-
A 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.
-
On entry, | less than two groups have nonzero membership, i.e., the effective number of groups is less than , |
or | the effective number of groups plus the number of variables, NX, is greater than the effective number of observations. |
-
The rank of the variables is . This will happen if all the variables are constants.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.8 in the Essential Introduction for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.7 in the Essential Introduction for further information.
Dynamic memory allocation failed.
See
Section 3.6 in the Essential Introduction for further information.
7 Accuracy
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.
8 Parallelism 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.
None.
10 Example
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.
10.1 Program Text
Program Text (g03acfe.f90)
10.2 Program Data
Program Data (g03acfe.d)
10.3 Program Results
Program Results (g03acfe.r)