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_miss_pair (g02bs)

Purpose

nag_correg_coeffs_kspearman_miss_pair (g02bs) computes Kendall and/or Spearman nonparametric rank correlation coefficients for a set of data omitting cases with missing values from only those calculations involving the variables for which the values are missing; the data array is preserved, and the ranks of the observations are not available on exit from the function.

Syntax

[rr, ncases, cnt, ifail] = g02bs(x, miss, xmiss, itype, 'n', n, 'm', m)
[rr, ncases, cnt, ifail] = nag_correg_coeffs_kspearman_miss_pair(x, miss, xmiss, 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) ​ and ​ j = 1,2,,m   (m2) ,
[ xij ] ,   i=1,2,,n   (n2) ​ and ​ j=1,2,,m   (m2) ,
where xijxij is the iith observation on the jjth variable. In addition each of the mm variables may optionally have associated with it a value which is to be considered as representing a missing observation for that variable; the missing value for the jjth variable is denoted by xmjxmj. Missing values need not be specified for all variables.
Let wij = 0wij=0 if the iith observation for the jjth variable is a missing value, i.e., if a missing value, xmjxmj, has been declared for the jjth variable, and xij = xmjxij=xmj (see also Section [Accuracy]); and wij = 1wij=1 otherwise, for i = 1,2,,ni=1,2,,n and j = 1,2,,mj=1,2,,m.
The observations are first ranked, a pair of variables at a time as follows:
For a given pair of variables, jj and ll say, each of the observations xijxij for which the product wijwil = 1wijwil=1, for i = 1,2,,ni=1,2,,n, 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 observations on variable jj for which wijwil = 1wijwil=1.
The smallest of these valid observations for variable jj is assigned to rank 11, the second smallest valid observation for variable jj the rank 22, the third smallest rank 33, and so on until the largest such observation is given the rank njlnjl, where
n
njl = wijwil.
i = 1
njl=i=1nwijwil.
If a number of cases all have the same value for the variable jj, then they are each given an ‘average’ rank, e.g., if in attempting to assign the rank h + 1h+1, kk observations for which wijwil = 1wijwil=1 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 variable ll is then ranked in a similar way. The process is then repeated for all pairs of variables jj and ll, for j = 1,2,,mj=1,2,,m and l = j,,ml=j,,m. Let yij(l)yij(l) be the rank assigned to the observation xijxij when the jjth and llth variables are being ranked, and yil(j)yil(j) be the rank assigned to the observation xilxil during the same process, for i = 1,2,,ni=1,2,,n, j = 1,2,,mj=1,2,,m and l = j,,ml=j,,m.
The quantities calculated are:
(a) Kendall's tau rank correlation coefficients:
Rjk = (h = 1ni = 1nwhjwhkwijwiksign(yhj(k)yij(k))sign(yhk(j)yik(j)))/(sqrt([njk(njk1)Tj(k)][njk(njk1)Tk(j)])),  j,k = 1,2,,m,
Rjk=h=1ni=1nwhjwhkwijwiksign(yhj(k)-yij(k))sign(yhk(j)-yik(j)) [njk(njk-1)-Tj(k)][njk(njk-1)-Tk(j)] ,  j,k=1,2,,m,
where njk = i = 1nwijwiknjk=i=1nwijwik
and signu = 1signu=1 if u > 0u>0
signu = 0signu=0 if u = 0u=0
signu = 1signu=-1 if u < 0u<0
and Tj(k) = tj(tj1)Tj(k)=tj(tj-1) where tjtj is the number of ties of a particular value of variable jj when the jjth and kkth variables are being ranked, and the summation is over all tied values of variable jj
(b) Spearman's rank correlation coefficients:
Rjk * = ( njk(njk21)6i = 1nwijwik(yij(k)yik(j))2(1/2)(Tj(k) * + Tk(j) * ))/(sqrt([njk(njk21)Tj(k) * ] [njk(njk21)Tk(j) * ])),   j,k = 1,2,,m,
Rjk*= njk(njk2-1)-6i=1nwijwik(yij(k)-yik(j))2-12(Tj(k)*+Tk(j)*) [njk(njk2-1)-Tj(k)*] [njk(njk2-1)-Tk(j)*] ,   j,k=1,2,,m,
where njk = i = 1nwijwiknjk=i=1nwijwik 
and Tj(k) * = tj(tj21)Tj(k)*=tj(tj2-1), where tjtj is the number of ties of a particular value of variable jj when the jjth and kkth variables are being ranked, 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 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:     miss(m) – int64int32nag_int array
m, the dimension of the array, must satisfy the constraint m2m2.
miss(j)missj must be set equal to 11 if a missing value, xmjxmj, is to be specified for the jjth variable in the array x, or set equal to 00 otherwise. Values of miss must be given for all mm variables in the array x.
3:     xmiss(m) – double array
m, the dimension of the array, must satisfy the constraint m2m2.
xmiss(j)xmissj must be set to the missing value, xmjxmj, to be associated with the jjth variable in the array x, for those variables for which missing values are specified by means of the array miss (see Section [Accuracy]).
4:     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 dimension of the arrays miss, xmiss and the second dimension of the array x. (An error is raised if these dimensions are not equal.)
mm, the number of variables.
Constraint: m2m2.

Input Parameters Omitted from the MATLAB Interface

ldx ldrr ldcnt kworka kworkb kworkc kworkd 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:     ncases – int64int32nag_int scalar
The minimum number of cases used in the calculation of any of the correlation coefficients (when cases involving missing values have been eliminated).
3:     cnt(ldcnt,m) – double array
ldcntmldcntm.
The number of cases, njknjk, actually used in the calculation of the rank correlation coefficient for the jjth and kkth variables, for j = 1,2,,mj=1,2,,m and k = 1,2,,mk=1,2,,m.
4:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Note: nag_correg_coeffs_kspearman_miss_pair (g02bs) may return useful information for one or more of the following detected errors or 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,
orldcnt < mldcnt<m.
  ifail = 4ifail=4
On entry,itype < 1itype<-1,
oritype > 1itype>1.
  ifail = 5ifail=5
After observations with missing values were omitted, fewer than two cases remained for at least one pair of variables. (The pairs of variables involved can be determined by examination of the contents of the array cnt.) All correlation coefficients based on two or more cases are returned by the function even if ifail = 5ifail=5.

Accuracy

You are warned of the need to exercise extreme care in your selection of missing values. nag_correg_coeffs_kspearman_miss_pair (g02bs) treats all values in the inclusive range (1 ± 0.1(x02be2)) × xmj(1±0.1(x02be-2))×xmj, where xmjxmj is the missing value for variable jj specified in xmiss.
You must therefore ensure that the missing value chosen for each variable is sufficiently different from all valid values for that variable so that none of the valid values fall within the range indicated above.

Further Comments

The time taken by nag_correg_coeffs_kspearman_miss_pair (g02bs) depends on nn and mm, and the occurrence of missing values.

Example

function nag_correg_coeffs_kspearman_miss_pair_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];
miss = [int64(1);1;1];
xmiss = [0.99;
     9;
     0];
itype = int64(0);
[rr, ncases, count, ifail] = nag_correg_coeffs_kspearman_miss_pair(x, miss, xmiss, itype)
 

rr =

    1.0000    0.1000    0.4058
         0    1.0000    0.0896
    0.2760         0    1.0000


ncases =

                    5


count =

     7     5     6
     5     7     6
     6     6     8


ifail =

                    0


function g02bs_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];
miss = [int64(1);1;1];
xmiss = [0.99;
     9;
     0];
itype = int64(0);
[rr, ncases, count, ifail] = g02bs(x, miss, xmiss, itype)
 

rr =

    1.0000    0.1000    0.4058
         0    1.0000    0.0896
    0.2760         0    1.0000


ncases =

                    5


count =

     7     5     6
     5     7     6
     6     6     8


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