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_case (g02br)

Purpose

nag_correg_coeffs_kspearman_miss_case (g02br) computes Kendall and/or Spearman nonparametric rank correlation coefficients for a set of data, omitting completely any cases with a missing observation for any variable; the data array is preserved, and the ranks of the observations are not available on exit from the function.

Syntax

[rr, ncases, incase, ifail] = g02br(x, miss, xmiss, itype, 'n', n, 'm', m)
[rr, ncases, incase, ifail] = nag_correg_coeffs_kspearman_miss_case(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; miss, xmiss no longer output
.

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. 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 wi = 0wi=0 if observation ii contains a missing value for any of those variables for which missing values have been declared, i.e., if xij = xmjxij=xmj for any jj for which an xmjxmj has been assigned (see also Section [Accuracy]); and wi = 1wi=1 otherwise, for i = 1,2,,ni=1,2,,n.
The observations are first ranked as follows.
For a given variable, jj say, each of the observations xijxij for which wi = 1wi=1, (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 magnitudes of the other observations on that same variable for which wi = 1wi=1.
The smallest of these valid observations 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 such observation is given the rank ncnc, where nc = i = 1nwinc=i=1nwi.
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 for which wi = 1wi=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+1 2
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. For those observations, ii, for which wi = 0wi=0, yij = 0yij=0, for j = 1,2,,mj=1,2,,m.
The quantities calculated are:
(a) Kendall's tau rank correlation coefficients:
Rjk = ( h = 1n i = 1n wh wi sign(yhjyij) sign(yhkyik) )/(sqrt([nc(nc1)Tj][nc(nc1)Tk])) ,   j,k = 1,2,,m ,
Rjk = h=1 n i=1 n wh wi sign(yhj-yij) sign(yhk-yik) [nc(nc-1)-Tj][nc(nc-1)-Tk] ,   j,k=1,2,,m ,
where nc = i = 1nwinc=i=1nwi
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) 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.
(b) Spearman's rank correlation coefficients:
Rjk * = (nc(nc21)6i = 1nwi(yijyik)2(1/2)(Tj * + Tk * ))/(sqrt([nc(nc21)Tj * ][nc(nc21)Tk * ])),  j,k = 1,2,,m,
Rjk*=nc(nc2-1)-6i=1nwi (yij-yik) 2-12(Tj*+Tk*) [nc(nc2-1)-Tj*][nc(nc2-1)-Tk*] ,  j,k=1,2,,m,
where nc = i = 1nwinc=i=1nwi and 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 xijxij, the value of the iith observation on the jjth variable, where i = 1,2,,ni=1,2,,n and j = 1,2,,m.j=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 kworka kworkb kworkc 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 number of cases, ncnc, actually used in the calculations (when cases involving missing values have been eliminated).
3:     incase(n) – int64int32nag_int array
incase(i)incasei holds the value 11 if the iith case was included in the calculations, and the value 00 if the iith case contained a missing value for at least one variable. That is, incase(i) = wiincasei=wi (see Section [Description]), for i = 1,2,,ni=1,2,,n.
4:     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.
  ifail = 5ifail=5
After observations with missing values were omitted, fewer than 22 cases remained.

Accuracy

You are warned of the need to exercise extreme care in your selection of missing values. nag_correg_coeffs_kspearman_miss_case (g02br) 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_case (g02br) depends on nn and mm, and the occurrence of missing values.

Example

function nag_correg_coeffs_kspearman_miss_case_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);0;1];
xmiss = [0.99;
     0;
     0];
itype = int64(0);
[rr, ncases, incase, ifail] = nag_correg_coeffs_kspearman_miss_case(x, miss, xmiss, itype)
 

rr =

    1.0000    0.2941    0.4058
    0.1429    1.0000    0.7537
    0.2760    0.5521    1.0000


ncases =

                    6


incase =

                    1
                    1
                    1
                    1
                    0
                    1
                    1
                    0
                    0


ifail =

                    0


function g02br_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);0;1];
xmiss = [0.99;
     0;
     0];
itype = int64(0);
[rr, ncases, incase, ifail] = g02br(x, miss, xmiss, itype)
 

rr =

    1.0000    0.2941    0.4058
    0.1429    1.0000    0.7537
    0.2760    0.5521    1.0000


ncases =

                    6


incase =

                    1
                    1
                    1
                    1
                    0
                    1
                    1
                    0
                    0


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