|
NAG[g02bxc] NAG[nag_corr_cov] - Product-moment correlation, unweighted/weighted correlation and covariance matrix, allows variables to be disregarded
|
|
Calling Sequence
g02bxc(x, sw, wmean, std, r, v, 'n'=n, 'm'=m, 'tdx'=tdx, 'sx'=sx, 'wt'=wt, 'tdr'=tdr, 'tdv'=tdv, 'fail'=fail)
nag_corr_cov(. . .)
Parameters
|
x - Matrix(1..n, 1..tdx, datatype=float[8], order=C_order);
|
|
|
|
sw - assignable;
|
|
|
Note: On exit the variable sw will have a value of type float.
|
|
On exit: the sum of weights if wt is not the null pointer, otherwise sw contains the number of observations, .
|
|
|
wmean - Vector(1..m, datatype=float[8]);
|
|
|
On exit: the sample means. contains the mean for the th variable.
|
|
|
std - Vector(1..m, datatype=float[8]);
|
|
|
On exit: the standard deviations. contains the standard deviation for the th variable.
|
|
|
r - Matrix(1..m, 1..tdr, datatype=float[8], order=C_order);
|
|
|
|
v - Matrix(1..m, 1..tdv, datatype=float[8], order=C_order);
|
|
|
|
'n'=n - integer; (optional)
|
|
|
Default value: the first dimension of the arrays x, wt.
|
|
On entry: the number of observations in the data set, .
|
|
Constraint: . .
|
|
|
'm'=m - integer; (optional)
|
|
|
Default value: the first dimension of the arrays sx, wmean, std, r, v and the second dimension of the arrays sx, wmean, std, r, vthe arrays x, r, v.
|
|
On entry: the total number of variables, .
|
|
Constraint: . .
|
|
|
'tdx'=tdx - integer; (optional)
|
|
|
On entry: the second dimension of the array x as declared in the function from which nag_corr_cov (g02bxc) is called.
|
|
Constraint: . .
|
|
|
'sx'=sx - Vector(1..m, datatype=integer[kernelopts('wordsize')/8]); (optional)
|
|
|
On entry: indicates which variables to include in the analysis.
|
|
The th variable is to be included.
|
|
The th variable is not to be included.
|
|
sx is set to the null pointer (Integer *)0 All variables are included in the analysis, i.e., .
|
|
Constraint: , for . .
|
|
|
'wt'=wt - Vector(1..n, datatype=float[8]); (optional)
|
|
|
Constraint: , for . .
|
|
|
'tdr'=tdr - integer; (optional)
|
|
|
On entry: the second dimension of the array r as declared in the function from which nag_corr_cov (g02bxc) is called.
|
|
Constraint: . .
|
|
|
'tdv'=tdv - integer; (optional)
|
|
|
On entry: the second dimension of the array v as declared in the function from which nag_corr_cov (g02bxc) is called.
|
|
Constraint: . .
|
|
|
'fail'=fail - table; (optional)
|
|
|
The NAG error argument, see the documentation for NagError.
|
|
|
|
Description
|
|
|
Purpose
|
|
nag_corr_cov (g02bxc) calculates the Pearson product-moment correlation coefficients and the variance-covariance matrix for a set of data. Weights may be used.
|
|
Description
|
|
For observations on variables a one-pass updating algorithm (see West (1979)) is used to compute the means, the standard deviations, the variance-covariance matrix, and the Pearson product-moment correlation matrix for selected variables. Suitables weights may be used to indicate multiple observations and to remove missing values. The quantities are defined by:
(a) The means
(b) The variance-covariance matrix
(c) The standard deviations
(d) The Pearson product-moment correlation coefficients
where is the value of the th observation on the th variable and is the weight for the th observation which will be 1 in the unweighted case.
Note that the denominator for the variance-covariance is , so the weights should be scaled so that the sum of weights reflects the true sample size.
|
|
Error Indicators and Warnings
|
|
"NE_ALLOC_FAIL"
Dynamic memory allocation failed.
"NE_INT_ARG_LE"
On entry, n must be greater than 1: .
"NE_INT_ARG_LT"
On entry, m must not be less than 1: .
"NE_NEG_SX"
On entry, at least one element of sx is negative.
"NE_NEG_WEIGHT"
On entry, at least one of the weights is negative.
"NE_POS_SX"
On entry, no element of sx is positive.
"NE_SW_LT_ONE"
On entry, the sum of weights is less than 1.0.
"NE_VAR_EQ_ZERO"
A variable has zero variance. At least one variable has zero variance. In this case v and std are as calculated, but r will contain zero for any correlation involving a variable with zero variance.
|
|
Accuracy
|
|
For a discussion of the accuracy of the one pass algorithm see Chan et al. (1982) and West (1979).
|
|
|
Examples
|
|
>
|
n := 3:
m := 3:
tdx := 3:
tdr := 3:
tdv := 3:
x := Matrix([[0.931, 0.09, 0.887], [0.0009, 0.009900000000000001, 0.0999], [0.13, 1.307, 0.37]], datatype=float[8], order='C_order'):
sx := Vector([], datatype=integer[kernelopts('wordsize')/8]):
wt := Vector([9.123100000000001, 3.7011, 4.523], datatype=float[8]):
wmean := Vector(3, datatype=float[8]):
std := Vector(3, datatype=float[8]):
r := Matrix(3, 3, datatype=float[8], order='C_order'):
v := Matrix(3, 3, datatype=float[8], order='C_order'):
NAG:-g02bxc(x, sw, wmean, std, r, v, 'n' = n, 'm' = m, 'tdx' = tdx, 'sx' = sx, 'wt' = wt, 'tdr' = tdr, 'tdv' = tdv):
|
|
|
See Also
|
|
Chan T F, Golub G H and Leveque R J (1982) Updating Formulae and a Pairwise Algorithm for Computing Sample Variances Compstat, Physica-Verlag
West D H D (1979) Updating mean and variance estimates: An improved method Comm. ACM 22 532–555
g02 Chapter Introduction.
NAG Toolbox Overview.
NAG Web Site.
|
|