PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_mv_canon_var (g03ac)
Purpose
nag_mv_canon_var (g03ac) performs a canonical variate (canonical discrimination) analysis.
Syntax
[
nig,
cvm,
e,
ncv,
cvx,
irankx,
ifail] = g03ac(
weight,
x,
isx,
nx,
ing,
ng,
wt,
tol, 'n',
n, 'm',
m)
[
nig,
cvm,
e,
ncv,
cvx,
irankx,
ifail] = nag_mv_canon_var(
weight,
x,
isx,
nx,
ing,
ng,
wt,
tol, 'n',
n, 'm',
m)
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,
nag_mv_canon_var (g03ac) 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).
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
Parameters
Compulsory Input Parameters
- 1:
– string (length ≥ 1)
-
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:
– double array
-
ldx, the first dimension of the array, must satisfy the constraint
.
must contain the th observation for the th variable, for and .
- 3:
– int64int32nag_int array
-
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
.
- 4:
– int64int32nag_int scalar
-
The number of variables in the analysis, .
Constraint:
.
- 5:
– int64int32nag_int array
-
indicates which group the th observation is in, for . The effective number of groups is the number of groups with nonzero membership.
Constraint:
, for .
- 6:
– int64int32nag_int scalar
-
The number of groups, .
Constraint:
.
- 7:
– double array
-
The dimension of the array
wt
must be at least
if
or
, and at least
otherwise
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 ;
- .
- 8:
– double scalar
-
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:
.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the array
ing and the first dimension of the array
x. (An error is raised if these dimensions are not equal.)
, the number of observations.
Constraint:
.
- 2:
– int64int32nag_int scalar
-
Default:
the dimension of the array
isx and the second dimension of the array
x. (An error is raised if these dimensions are not equal.)
, the total number of variables.
Constraint:
.
Output Parameters
- 1:
– int64int32nag_int array
-
gives the number of observations in group , for .
- 2:
– double array
-
contains the mean of the th canonical variate for the th group, for and ; the remaining columns, if any, are used as workspace.
- 3:
– double array
-
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 .
- 4:
– int64int32nag_int scalar
-
The number of canonical variates,
. This will be the minimum of
and the rank of
x.
- 5:
– double array
-
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.
- 6:
– int64int32nag_int scalar
-
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
.
- 7:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
-
-
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.
- W
-
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. |
- W
-
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.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
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, nag_mv_canon_var (g03ac) should be less affected by ill-conditioned problems.
Further Comments
None.
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.
Open in the MATLAB editor:
g03ac_example
function g03ac_example
fprintf('g03ac example results\n\n');
x = [13.3, 10.6, 21.2;
13.6, 10.2, 21.0;
14.2, 10.7, 21.1;
13.4, 9.4, 21.0;
13.2, 9.6, 20.1;
13.9, 10.4, 19.8;
12.9, 10.0, 20.5;
12.2, 9.9, 20.7;
13.9, 11.0, 19.1];
n = size(x,2);
weight = 'U';
isx = ones(n,1,'int64');
nx = int64(n);
ing = [int64(1);2;3; 1;2;3; 1;2;3];
ng = int64(n);
wt = [];
tol = 1e-06;
[nig, cvm, e, ncv, cvx, irankx, ifail] = ...
g03ac( ...
weight, x, isx, nx, ing, ng, wt, tol);
fprintf('Rank of x = %d\n\n', irankx);
fprintf('Canonical Eigenvalues Percentage Chisq DF Sig\n');
fprintf('correlations variation\n');
fprintf('%11.4f%12.4f%12.4f%10.4f%8.1f%8.4f\n',e');
fprintf('\n');
mtitle = 'Canonical Coefficients for x';
matrix = 'General';
diag = ' ';
[ifail] = x04ca( ...
matrix, diag, cvx, mtitle);
fprintf('\n');
mtitle = 'Canonical variate means';
[ifail] = x04ca( ...
matrix, diag, cvm(:,1:ncv), mtitle);
g03ac example results
Rank of x = 3
Canonical Eigenvalues Percentage Chisq DF Sig
correlations variation
0.8826 3.5238 0.9795 7.9032 6.0 0.2453
0.2623 0.0739 0.0205 0.3564 2.0 0.8368
Canonical Coefficients for x
1 2
1 -1.7070 0.7277
2 -1.3481 0.3138
3 0.9327 1.2199
Canonical variate means
1 2
1 0.9841 0.2797
2 1.1805 -0.2632
3 -2.1646 -0.0164
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015