hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_correg_coeffs_kspearman (g02bq)

Purpose

nag_correg_coeffs_kspearman (g02bq) computes Kendall and/or Spearman nonparametric rank correlation coefficients for a set of data; the data array is preserved, and the ranks of the observations are not available on exit from the function.

Syntax

[rr, ifail] = g02bq(x, itype, 'n', n, 'm', m)
[rr, ifail] = nag_correg_coeffs_kspearman(x, itype, 'n', n, 'm', m)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 22: n has been made optional
.

Description

The input data consists of nn observations for each of mm variables, given as an array
[xij],  i = 1,2,,n(n2),j = 1,2,,m(m2),
[xij],  i=1,2,,n(n2),j=1,2,,m(m2),
where xijxij is the iith observation on the jjth variable.
The observations are first ranked, as follows.
For a given variable, jj say, each of the nn observations, x1j,x2j,,xnjx1j,x2j,,xnj, has associated with it an additional number, the ‘rank’ of the observation, which indicates the magnitude of that observation relative to the magnitude of the other n1n-1 observations on that same variable.
The smallest observation for variable jj is assigned the rank 11, the second smallest observation for variable jj the rank 22, the third smallest the rank 33, and so on until the largest observation for variable jj is given the rank nn.
If a number of cases all have the same value for the given variable, jj, then they are each given an ‘average’ rank – e.g., if in attempting to assign the rank h + 1h+1, kk observations were found to have the same value, then instead of giving them the ranks
h + 1,h + 2,,h + k,
h+1,h+2,,h+k,
all kk observations would be assigned the rank
(2h + k + 1)/2
2h+k+12
and the next value in ascending order would be assigned the rank
h + k + 1.
h+k+ 1.
The process is repeated for each of the mm variables.
Let yijyij be the rank assigned to the observation xijxij when the jjth variable is being ranked.
The quantities calculated are:
(a) Kendall's tau rank correlation coefficients:
Rjk = (h = 1ni = 1nsign(yhjyij)sign(yhkyik))/(sqrt([n(n1)Tj][n(n1)Tk])),  j,k = 1,2,,m,
Rjk=h=1ni=1nsign(yhj-yij)sign(yhk-yik) [n(n-1)-Tj][n(n-1)-Tk] ,  j,k=1,2,,m,
and signu = 1signu=1 if u > 0u>0
signu = 0signu=0 if u = 0u=0
signu = 1signu=-1 if u < 0u<0
and Tj = tj(tj1)Tj=tj(tj-1), tjtj being the number of ties of a particular value of variable jj, and the summation being over all tied values of variable jj
(b) Spearman's rank correlation coefficients:
Rjk * = (n(n21)6i = 1n(yijyik)2(1/2)(Tj * + Tk * ))/(sqrt([n(n21)Tj * ][n(n21)Tk * ])),  j,k = 1,2,,m,
Rjk*=n(n2-1)-6i=1n (yij-yik) 2-12(Tj*+Tk*) [n(n2-1)-Tj*][n(n2-1)-Tk*] ,  j,k=1,2,,m,
where Tj * = tj(tj21)Tj*=tj(tj2-1) where tjtj is the number of ties of a particular value of variable jj, and the summation is over all tied values of variable jj.

References

Siegel S (1956) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill

Parameters

Compulsory Input Parameters

1:     x(ldx,m) – double array
ldx, the first dimension of the array, must satisfy the constraint ldxnldxn.
x(i,j)xij must be set to data value xijxij, the value of the iith observation on the jjth variable, for i = 1,2,,ni=1,2,,n and j = 1,2,,mj=1,2,,m.
2:     itype – int64int32nag_int scalar
The type of correlation coefficients which are to be calculated.
itype = -1itype=-1
Only Kendall's tau coefficients are calculated.
itype = 0itype=0
Both Kendall's tau and Spearman's coefficients are calculated.
itype = 1itype=1
Only Spearman's coefficients are calculated.
Constraint: itype = -1itype=-1, 00 or 11.

Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The first dimension of the array x.
nn, the number of observations or cases.
Constraint: n2n2.
2:     m – int64int32nag_int scalar
Default: The second dimension of the array x.
mm, the number of variables.
Constraint: m2m2.

Input Parameters Omitted from the MATLAB Interface

ldx ldrr kworka kworkb work1 work2

Output Parameters

1:     rr(ldrr,m) – double array
ldrrmldrrm.
The requested correlation coefficients.
If only Kendall's tau coefficients are requested (itype = 1itype=-1), rr(j,k)rrjk contains Kendall's tau for the jjth and kkth variables.
If only Spearman's coefficients are requested (itype = 1itype=1), rr(j,k)rrjk contains Spearman's rank correlation coefficient for the jjth and kkth variables.
If both Kendall's tau and Spearman's coefficients are requested (itype = 0itype=0), the upper triangle of rr contains the Spearman coefficients and the lower triangle the Kendall coefficients. That is, for the jjth and kkth variables, where jj is less than kk, rr(j,k)rrjk contains the Spearman rank correlation coefficient, and rr(k,j)rrkj contains Kendall's tau, for j = 1,2,,mj=1,2,,m and k = 1,2,,mk=1,2,,m.
(Diagonal terms, rr(j,j)rrjj, are unity for all three values of itype.)
2:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,n < 2n<2.
  ifail = 2ifail=2
On entry,m < 2m<2.
  ifail = 3ifail=3
On entry,ldx < nldx<n,
orldrr < mldrr<m.
  ifail = 4ifail=4
On entry,itype < 1itype<-1,
oritype > 1itype>1.

Accuracy

The method used is believed to be stable.

Further Comments

The time taken by nag_correg_coeffs_kspearman (g02bq) depends on nn and mm.

Example

function nag_correg_coeffs_kspearman_example
x = [1.7, 1, 0.5;
     2.8, 4, 3;
     0.6, 6, 2.5;
     1.8, 9, 6;
     0.99, 4, 2.5;
     1.4, 2, 5.5;
     1.8, 9, 7.5;
     2.5, 7, 0;
     0.99, 5, 3];
itype = int64(0);
[rr, ifail] = nag_correg_coeffs_kspearman(x, itype)
 

rr =

    1.0000    0.2246    0.1186
    0.0294    1.0000    0.3814
    0.1176    0.2353    1.0000


ifail =

                    0


function g02bq_example
x = [1.7, 1, 0.5;
     2.8, 4, 3;
     0.6, 6, 2.5;
     1.8, 9, 6;
     0.99, 4, 2.5;
     1.4, 2, 5.5;
     1.8, 9, 7.5;
     2.5, 7, 0;
     0.99, 5, 3];
itype = int64(0);
[rr, ifail] = g02bq(x, itype)
 

rr =

    1.0000    0.2246    0.1186
    0.0294    1.0000    0.3814
    0.1176    0.2353    1.0000


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013