The function may be called by the names: g02brc, nag_correg_coeffs_kspearman_miss_case or nag_ken_spe_corr_coeff.
3Description
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 , the second smallest observation for variable the rank , 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 .
4References
Siegel S (1956) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill
5Arguments
1: – IntegerInput
On entry: the number of observations in the dataset.
Constraint:
.
2: – IntegerInput
On entry: the number of variables.
Constraint:
.
3: – const doubleInput
On entry: must contain the th observation on the th variable, for and .
4: – IntegerInput
On entry: the stride separating matrix column elements in the array x.
Constraint:
.
5: – const IntegerInput
On entry: indicates which variables are to be included, for the th variable to be included, . If all variables are to be included then a NULL pointer (Integer *)0 may be supplied.
Constraint:
, and there is at least one positive element, for .
6: – const IntegerInput
On entry: indicates which observations are to be included, for the th observation to be included, . If all observations are to be included then a NULL pointer (Integer *)0 may be supplied.
Constraint:
, and there are at least two positive elements, for .
7: – doubleOutput
On exit: the upper part of corr contains the correlation coefficients, the upper triangle contains the Spearman coefficients and the lower triangle, the Kendall coefficients. That is, for the th and th variables, where is less than , contains the Spearman rank correlation coefficient, and contains Kendall's tau, for . The diagonal will be set to 1.
8: – IntegerInput
On entry: the stride separating matrix column elements in the array corr.
Constraint:
.
9: – NagError *Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).
6Error Indicators and Warnings
NE_2_INT_ARG_LT
On entry, while . These arguments must satisfy .
On entry, while . These arguments must satisfy .
NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_INT_ARG_LT
On entry, .
Constraint: .
On entry, .
Constraint: .
NE_INT_ARRAY_1
Value given to not valid. Correct range for elements of sobs is .
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
On entry, sobs must contain at least 2 positive elements.
Too few observations have been selected.
NE_SVAR_LOW
No variables have been selected.
On entry, svar must contain at least 1 positive element.
7Accuracy
The computations are believed to be stable.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
g02brc is not threaded in any implementation.
9Further Comments
None.
10Example
A program to calculate the Kendall and Spearman rank correlation coefficients from a set of data.