|
NAG[g02brc] NAG[nag_ken_spe_corr_coeff] - Kendall and/or Spearman non-parametric rank correlation coefficients, allows variables and observations to be selectively disregarded
|
|
Calling Sequence
g02brc(x, svar, sobs, corr, 'n'=n, 'm'=m, 'tdx'=tdx, 'tdc'=tdc, 'fail'=fail)
nag_ken_spe_corr_coeff(. . .)
Parameters
|
x - Matrix(1..n, 1..tdx, datatype=float[8], order=C_order);
|
|
|
|
svar - Vector(1..m, datatype=integer[kernelopts('wordsize')/8]);
|
|
|
Constraint: , for and there is at least 1 positive element. .
|
|
|
sobs - Vector(1..n, datatype=integer[kernelopts('wordsize')/8]);
|
|
|
Constraint: , for and there are at least 2 positive elements. .
|
|
|
corr - Matrix(1..m, 1..tdc, datatype=float[8], order=C_order);
|
|
|
|
'n'=n - integer; (optional)
|
|
|
Default value: the first dimension of the arrays x, sobs.
|
|
On entry: the number of observations in the data set.
|
|
Constraint: . .
|
|
|
'm'=m - integer; (optional)
|
|
|
Default value: the first dimension of the arrays svar, corr and the second dimension of the arrays svar, corrthe arrays x, corr.
|
|
On entry: the 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_ken_spe_corr_coeff (g02brc) is called.
|
|
Constraint: . .
|
|
|
'tdc'=tdc - integer; (optional)
|
|
|
On entry: the second dimension of the array corr as declared in the function from which nag_ken_spe_corr_coeff (g02brc) is called.
|
|
Constraint: . .
|
|
|
'fail'=fail - table; (optional)
|
|
|
The NAG error argument, see the documentation for NagError.
|
|
|
|
Description
|
|
|
Purpose
|
|
nag_ken_spe_corr_coeff (g02brc) calculates Kendall and Spearman rank correlation coefficients.
|
|
Description
|
|
nag_ken_spe_corr_coeff (g02brc) calculates both the Kendall rank correlation coefficients and the Spearman rank correlation coefficients.
The data consists of observations for each of variables:
where is the th observation on the th variable. The function eliminates any variable for where the argument , and any observation for where the argument .
The observations are first ranked as follows:
For a given variable, say, each of the observations for which , for has associated with it an additional number, the rank of the observation, which indicates the magnitude of that observation relative to the magnitudes of the other observations on that same variable for which .
The smallest of these valid observations for variable is assigned the rank 1, the second smallest observation for variable the rank 2, and so on until the largest such observation is given the rank , where is the number of observations for which .
If a number of cases all have the same value for a given variable, , then they are each given an "average" rank — e.g. if in attempting to assign the rank , observations for which were found to have the same value, then instead of giving them the ranks all observations would be assigned the rank and the next value in ascending order would be assigned the rank The process is repeated for each of the variables for which .
Let be the rank assigned to the observation when the th variable is being ranked. For those observations, , for which , , for .
For variables the following are computed:
(a) Kendall's tau correlation coefficients:
where is the number of observations for which ,
and
|
sign if ,
|
|
sign if ,
|
|
sign if ,
|
|
|
and where is the number of ties of a particular value of variable , and the summation is over all tied values of variable .
(b) Spearman's rank correlation coefficients:
where is the number of observations for which ,
and where is the number of ties of a particular value of variable , and the summation is over all tied values of variable .
|
|
Error Indicators and Warnings
|
|
"NE_ALLOC_FAIL"
Dynamic memory allocation failed.
"NE_INT_ARG_LT"
On entry, n must not be less than 2: .
"NE_INT_ARRAY_1"
Value given to not valid. Correct range for elements of svar is .
"NE_INTERNAL_ERROR"
An initial error has occurred in this function. Check the function call and any array sizes.
"NE_SOBS_LOW"
Too few observations have been selected.
"NE_SVAR_LOW"
No variables have been selected.
|
|
Accuracy
|
|
The computations are believed to be stable.
|
|
|
Examples
|
|
>
|
n := 7:
m := 3:
tdx := 3:
tdc := 3:
x := Matrix([[1, 2, 4], [7, 7, 3], [2, 3, 4], [4, 4, 5], [5, 6, 7], [3, 1, 3], [6, 5, 5]], datatype=float[8], order='C_order'):
svar := Vector([1, 1, 1], datatype=integer[kernelopts('wordsize')/8]):
sobs := Vector([1, 1, 1, 1, 1, 1, 1], datatype=integer[kernelopts('wordsize')/8]):
corr := Matrix(3, 3, datatype=float[8], order='C_order'):
NAG:-g02brc(x, svar, sobs, corr, 'n' = n, 'm' = m, 'tdx' = tdx, 'tdc' = tdc):
|
|
|