NAG Library Function Document
nag_ken_spe_corr_coeff (g02brc)
1 Purpose
nag_ken_spe_corr_coeff (g02brc) calculates Kendall and Spearman rank correlation coefficients.
2 Specification
#include <nag.h> |
#include <nagg02.h> |
void |
nag_ken_spe_corr_coeff (Integer n,
Integer m,
const double x[],
Integer tdx,
const Integer svar[],
const Integer sobs[],
double corr[],
Integer tdc,
NagError *fail) |
|
3 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 . |
4 References
Siegel S (1956) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill
5 Arguments
- 1:
n – IntegerInput
On entry: the number of observations in the dataset.
Constraint:
.
- 2:
m – IntegerInput
On entry: the number of variables.
Constraint:
.
- 3:
x[] – const doubleInput
-
On entry: must contain the th observation on the th variable, for and .
- 4:
tdx – IntegerInput
-
On entry: the stride separating matrix column elements in the array
x.
Constraint:
.
- 5:
svar[m] – 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:
sobs[n] – 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:
corr[] – doubleOutput
-
On exit: the upper
by
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:
tdc – IntegerInput
-
On entry: the stride separating matrix column elements in the array
corr.
Constraint:
.
- 9:
fail – NagError *Input/Output
-
The NAG error argument (see
Section 3.6 in the Essential Introduction).
6 Error 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.
7 Accuracy
The computations are believed to be stable.
8 Parallelism and Performance
Not applicable.
None.
10 Example
A program to calculate the Kendall and Spearman rank correlation coefficients from a set of data.
10.1 Program Text
Program Text (g02brce.c)
10.2 Program Data
Program Data (g02brce.d)
10.3 Program Results
Program Results (g02brce.r)