|
NAG[g03dac] NAG[nag_mv_discrim] - Test for equality of within-group covariance matrices
|
|
Calling Sequence
g03dac(x, isx, ing, nig, gmean, det, gcov, stat, df, sig, 'n'=n, 'm'=m, 'tdx'=tdx, 'nvar'=nvar, 'ng'=ng, 'wt'=wt, 'tdg'=tdg, 'fail'=fail)
nag_mv_discrim(. . .)
Parameters
|
x - Matrix(1..n, 1..tdx, datatype=float[8], order=C_order);
|
|
|
|
isx - Vector(1..m, datatype=integer[kernelopts('wordsize')/8]);
|
|
|
On entry: indicates whether or not the th variable in x is to be included in the variance-covariance matrices.
|
|
Constraint: for nvar values of .
|
|
|
ing - Vector(1..n, datatype=integer[kernelopts('wordsize')/8]);
|
|
|
Constraint: , for .
|
|
The values of ing must be such that each group has at least nvar members
|
|
|
nig - Vector(1..ng, datatype=integer[kernelopts('wordsize')/8]);
|
|
|
|
gmean - Matrix(1..ng, 1..tdg, datatype=float[8], order=C_order);
|
|
|
|
det - Vector(1..ng, datatype=float[8]);
|
|
|
On exit: the logarithm of the determinants of the within-group variance-covariance matrices.
|
|
|
gcov - Vector(1.., datatype=float[8]);
|
|
|
Note: the dimension, dim, of the array gcov must be at least .
|
|
|
stat - assignable;
|
|
|
Note: On exit the variable stat will have a value of type float.
|
|
On exit: the likelihood-ratio test static, .
|
|
|
df - assignable;
|
|
|
Note: On exit the variable df will have a value of type float.
|
|
On exit: the degrees of freedom for the distribution of .
|
|
|
sig - assignable;
|
|
|
Note: On exit the variable sig will have a value of type float.
|
|
On exit: the significance level for .
|
|
|
'n'=n - integer; (optional)
|
|
|
Default value: the first dimension of the arrays x, ing, wt.
|
|
On entry: the number of observations, .
|
|
Constraint: . .
|
|
|
'm'=m - integer; (optional)
|
|
|
Default value: the first dimension of the array isx and the second dimension of the array isxthe array x.
|
|
On entry: the number of variables in the data array x.
|
|
Constraint: . .
|
|
|
'tdx'=tdx - integer; (optional)
|
|
|
On entry: the second dimension of the array x as declared in the function from which nag_mv_discrim (g03dac) is called.
|
|
Constraint: . .
|
|
|
'nvar'=nvar - integer; (optional)
|
|
|
Default value: the second dimension of the array gmean.
|
|
On entry: the number of variables in the variance-covariance matrices, .
|
|
Constraint: . .
|
|
|
'ng'=ng - integer; (optional)
|
|
|
Default value: the first dimension of the arrays nig, gmean, det.
|
|
On entry: the number of groups, .
|
|
Constraint: . .
|
|
|
'wt'=wt - Vector(1..n, datatype=float[8]); (optional)
|
|
|
On entry: the elements of wt must contain the weights to be used in the analysis and the effective number of observations for a group is the sum of the weights of the observations in that group. If then the th observation is excluded from the calculations.
|
|
, for ;
|
|
The effective number of observations for each group must be greater than 1.
|
|
Note: If wt is set to the null pointer NULL, i.e., (double *)0, then wt is not referenced and the effective number of observations for a group is the number of observations in that group.
|
|
|
'tdg'=tdg - integer; (optional)
|
|
|
On entry: the second dimension of the array gmean as declared in the function from which nag_mv_discrim (g03dac) is called.
|
|
Constraint: . .
|
|
|
'fail'=fail - table; (optional)
|
|
|
The NAG error argument, see the documentation for NagError.
|
|
|
|
Description
|
|
|
Purpose
|
|
nag_mv_discrim (g03dac) computes a test statistic for the equality of within-group covariance matrices and also computes matrices for use in discriminant analysis.
|
|
Description
|
|
Let a sample of observations on variables come from groups with observations in the th group and . If the data is assumed to follow a multivariate Normal distribution with the variance-covariance matrix of the th group , then to test for equality of the variance-covariance matrices between groups, that is, , the following likelihood-ratio test statistic, , can be used;
where
and are the within-group variance-covariance matrices and is the pooled variance-covariance matrix given by
For large , is approximately distributed as a variable with degrees of freedom, see Morrison (1967) for further comments. If weights are used, then and are the weighted pooled and within-group variance-covariance matrices and is the effective number of observations, that is, the sum of the weights.
Instead of calculating the within-group variance-covariance matrices and then computing their determinants in order to calculate the test statistic, nag_mv_discrim (g03dac) uses a decomposition. The group means are subtracted from the data and then for each group, a decomposition is computed to give an upper triangular matrix . This matrix can be scaled to give a matrix such that . The pooled matrix is then computed from the matrices. The values of and the can then be calculated from the diagonal elements of and the .
This approach means that the Mahalanobis squared distances for a vector observation can be computed as , where , being the vector of means of the th group. These distances can be calculated by g03dbc (nag_mv_discrim_mahaldist). The distances are used in discriminant analysis and g03dcc (nag_mv_discrim_group) uses the results of nag_mv_discrim (g03dac) to perform several different types of discriminant analysis. The differences between the discriminant methods are, in part, due to whether or not the within-group variance-covariance matrices are equal.
|
|
Error Indicators and Warnings
|
|
"NE_2_INT_ARG_LT"
On entry, while . These arguments must satisfy .
"NE_ALLOC_FAIL"
Dynamic memory allocation failed.
"NE_GROUP_OBSERV"
On entry, group has effective observations. Constraint: in each group the effective number of observations must be .
"NE_GROUP_VAR"
On entry, group has members, while . Constraint: number of members in each group
"NE_GROUP_VAR_RANK"
The variables in group are not of full rank.
"NE_INT_ARG_LT"
On entry, n must not be less than 1: .
"NE_INTARR_INT"
On entry, , . Constraint: , .
"NE_INTERNAL_ERROR"
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please consult NAG for assistance.
"NE_NEG_WEIGHT_ELEMENT"
On entry, . Constraint: when referenced, all elements of wt must be non-negative.
"NE_VAR_INCL_INDICATED"
The number of variables, nvar in the analysis , while number of variables included in the analysis via array . Constraint: these two numbers must be the same.
"NE_VAR_RANK"
The variables are not of full rank.
|
|
Accuracy
|
|
The accuracy is dependent on the accuracy of the computation of the decomposition. See f01qcc (nag_real_qr) for further details.
|
|
Further Comments
|
|
The time will be approximately proportional to .
|
|
|
Examples
|
|
>
|
n := 21:
m := 2:
tdx := 2:
nvar := 2:
ng := 3:
tdg := 2:
x := Matrix([[1.1314, 2.4596], [1.0986, 0.2624], [0.6419, -2.3026], [1.335, -3.2189], [1.411, 0.0953], [0.6419, -0.9163], [2.1163, 0], [1.335, -1.6094], [1.361, -0.5108], [2.0541, 0.1823], [2.2083, -0.5108], [2.7344, 1.2809], [2.0412, 0.47], [1.8718, -0.9163], [1.7405, -0.9163], [2.6101, 0.47], [2.3224, 1.8563], [2.2192, 2.0669], [2.2618, 1.1314], [3.9853, 0.9163], [2.76, 2.0281]], datatype=float[8], order='C_order'):
isx := Vector([1, 1], datatype=integer[kernelopts('wordsize')/8]):
ing := Vector([1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3], datatype=integer[kernelopts('wordsize')/8]):
wt := Vector([], datatype=float[8]):
nig := Vector(3, datatype=integer[kernelopts('wordsize')/8]):
gmean := Matrix(3, 2, datatype=float[8], order='C_order'):
det := Vector(3, datatype=float[8]):
gcov := Vector(12, datatype=float[8]):
NAG:-g03dac(x, isx, ing, nig, gmean, det, gcov, stat, df, sig, 'n' = n, 'm' = m, 'tdx' = tdx, 'nvar' = nvar, 'ng' = ng, 'wt' = wt, 'tdg' = tdg):
|
|
|
See Also
|
|
Aitchison J and Dunsmore I R (1975) Statistical Prediction Analysis Cambridge
Kendall M G and Stuart A (1976) The Advanced Theory of Statistics (Volume 3) (3rd Edition) Griffin
Krzanowski W J (1990) Principles of Multivariate Analysis Oxford University Press
Morrison D F (1967) Multivariate Statistical Methods McGraw–Hill
g03 Chapter Introduction.
NAG Toolbox Overview.
NAG Web Site.
|
|