<?xml-stylesheet type="text/xsl" href="../styles/pmathml.xsl"?>
<!-- saved from url=(0014)about:internet -->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:dsi="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xml:space="preserve"><head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"/><title>G02BNF : NAG Library, Mark 23</title><link rel="stylesheet" href="../styles/libdoc.css" type="text/css"/><script type="text/javascript">
   function showLevel(_levelId){
    var thisLevel = document.getElementById(_levelId);
    var thisplus = document.getElementById( _levelId.concat('plus'));
    var thisminus = document.getElementById( _levelId.concat('minus'));
    if(thisLevel.style.display != "block"){
     thisLevel.style.display = "block";
     thisplus.style.display = "none";
     thisminus.style.display = "inline";
     }
    else{
     thisLevel.style.display = "none";
     thisminus.style.display = "none";
     thisplus.style.display = "inline";
     }
    }
  </script></head><body><hr/><div><a class="rout" href="../../pdf/G02/g02bnf.pdf">G02BNF (PDF version)</a></div><div><a class="chap" href="g02conts.xml">G02 Chapter Contents</a></div><div><a class="chapint" href="g02intro.xml">G02 Chapter Introduction</a></div>
<div><a class="htmltoc" href="../FRONTMATTER/manconts.xml">NAG Library Manual</a></div><hr/><h1 class="libdoc">NAG Library Routine Document<br/><br/>G02BNF</h1><div class="paramtext"><div class="header"><b>Note:</b>&#160; before using this routine, please read the Users' Note for your implementation to check the interpretation of <span class="bitalic">bold italicised</span> terms and other implementation-dependent details.</div></div> 
<div class="htmltoc">
<h2 class="htmltoc"><span class="htmltochead" onclick="showLevel('htmltoc');"><span class="htmltocplus" id="htmltocplus">+</span><span class="htmltocminus" id="htmltocminus">&#8722;</span></span>&#160;Contents</h2>
<div class="htmltocitem" id="htmltoc">
<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#purpose">1&#160;&#160;<b>Purpose</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#specification">2&#160;&#160;<b>Specification</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#description">3&#160;&#160;<b>Description</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#references">4&#160;&#160;<b>References</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#parameters">5&#160;&#160;<b>Parameters</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#errors">6&#160;&#160;<b>Error Indicators and Warnings</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#accuracy">7&#160;&#160;<b>Accuracy</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#fcomments">8&#160;&#160;<b>Further Comments</b></a>
</div><div class="htmltoc">
<span class="htmltoc" onclick="showLevel('tocexample');"><span class="htmltocplus" id="tocexampleplus">+</span><span class="htmltocminus" id="tocexampleminus">&#8722;</span></span>
<a class="htmltoc" href="#example">9&#160;&#160;<b>Example</b></a>
<div class="htmltocitem" id="tocexample">
<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#examtext">9.1&#160;&#160;<b>Program Text</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#examdata">9.2&#160;&#160;<b>Program Data</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#examresults">9.3&#160;&#160;<b>Program Results</b></a>
</div>
</div>
</div>
</div>
</div><h2 class="standard"><a class="sec" name="purpose" id="purpose"/>1&#160;&#160;Purpose</h2>
<div class="paramtext">G02BNF computes Kendall and/or Spearman nonparametric rank correlation coefficients for a set of data; the data array is overwritten with the ranks of the observations.</div><h2 class="standard"><a class="sec" name="specification" id="specification"/>2&#160;&#160;Specification</h2><table class="fspec"><tr><td class="tdfspec1">
<div class="left-tablediv"><table class="fspec1"><tbody>
<tr>
<td class="tdfspec1" valign="top" align="left">SUBROUTINE&#160;G02BNF&#160;(</td>
<td class="tdfspec2" valign="top" align="left"><a class="arg" href="#N">N</a>, <a class="arg" href="#M">M</a>, <a class="arg" href="#X">X</a>, <a class="arg" href="#LDX">LDX</a>, <a class="arg" href="#ITYPE">ITYPE</a>, <a class="arg" href="#RR">RR</a>, <a class="arg" href="#LDRR">LDRR</a>, <a class="arg" href="#KWORKA">KWORKA</a>, <a class="arg" href="#KWORKB">KWORKB</a>, <a class="arg" href="#WORK1">WORK1</a>, <a class="arg" href="#WORK2">WORK2</a>, <a class="arg" href="#IFAIL">IFAIL</a>)</td>
</tr>
</tbody>
</table></div>
<div class="left-tablediv"><table class="fspec3"><tbody>
<tr>
<td class="tdfspec1" valign="top" align="left">INTEGER&#160;</td>
<td class="tdfspec2" valign="top" align="left">N, M, LDX, ITYPE, LDRR, KWORKA(N), KWORKB(N), IFAIL</td>
</tr>
<tr>
<td class="tdfspec1" valign="top" align="left">REAL&#160;(KIND=nag_wp)&#160;</td>
<td class="tdfspec2" valign="top" align="left">X(LDX,M), RR(LDRR,M), WORK1(M), WORK2(M)</td>
</tr>
</tbody>
</table></div>
</td></tr></table><h2 class="standard"><a class="sec" name="description" id="description"/>3&#160;&#160;Description</h2>
<div class="paramtext">The input data consists of <m:math><m:mi>n</m:mi></m:math>&#160;observations for each of  <m:math><m:mi>m</m:mi></m:math>&#160;variables, given as an array

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mfenced open="[" close="]" separators=""><m:msub><m:mi>x</m:mi><m:mrow><m:mi>i</m:mi><m:mi>j</m:mi></m:mrow></m:msub></m:mfenced><m:mtext>, &#8195;</m:mtext><m:mi>i</m:mi><m:mo>=</m:mo><m:mn>1</m:mn><m:mo>,</m:mo><m:mn>2</m:mn><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mi>n</m:mi>  <m:mfenced separators=""><m:mi>n</m:mi><m:mo>&#8805;</m:mo><m:mn>2</m:mn></m:mfenced><m:mo>,</m:mo><m:mi>j</m:mi><m:mo>=</m:mo><m:mn>1</m:mn><m:mo>,</m:mo><m:mn>2</m:mn><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mi>m</m:mi><m:mfenced separators=""><m:mi>m</m:mi><m:mo>&#8805;</m:mo><m:mn>2</m:mn></m:mfenced><m:mtext>,</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

where <m:math><m:msub><m:mi>x</m:mi><m:mrow><m:mi>i</m:mi><m:mi>j</m:mi></m:mrow></m:msub></m:math>&#160;is the <m:math><m:mi>i</m:mi></m:math>th observation of the  <m:math><m:mi>j</m:mi></m:math>th variable.</div><div class="paramtext">The quantities calculated are:
<table class="standard-100"><tr>
<td style="width:2.1em;" valign="baseline">(a)</td>
<td valign="top">Ranks
 <div class="paramtext">For a given variable, <m:math><m:mi>j</m:mi></m:math>&#160;say, each of the <m:math><m:mi>n</m:mi></m:math>&#160;observations, <m:math><m:msub><m:mi>x</m:mi><m:mrow><m:mn>1</m:mn><m:mi>j</m:mi></m:mrow></m:msub><m:mo>,</m:mo><m:msub><m:mi>x</m:mi><m:mrow><m:mn>2</m:mn><m:mi>j</m:mi></m:mrow></m:msub><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:msub><m:mi>x</m:mi><m:mrow><m:mi>n</m:mi><m:mi>j</m:mi></m:mrow></m:msub></m:math>, has associated with it an additional number, the &#8216;rank&#8217; of the observation, which indicates the magnitude of that observation relative to the magnitudes of the other <m:math><m:mi>n</m:mi><m:mo>-</m:mo><m:mn>1</m:mn></m:math>&#160;observations on that same variable.</div>
 <div class="paramtext">The smallest observation for variable <m:math><m:mi>j</m:mi></m:math>&#160;is assigned the rank <m:math><m:mn>1</m:mn></m:math>, the second smallest observation for variable <m:math><m:mi>j</m:mi></m:math>&#160;the rank <m:math><m:mn>2</m:mn></m:math>, the third smallest the rank <m:math><m:mn>3</m:mn></m:math>, and so on until the largest observation for variable <m:math><m:mi>j</m:mi></m:math>&#160;is given the rank <m:math><m:mi>n</m:mi></m:math>.</div>
 <div class="paramtext">If a number of cases all have the same value for the given variable,  <m:math><m:mi>j</m:mi></m:math>, then they are each given an &#8216;average&#8217; rank, e.g., if in attempting to assign the rank <m:math><m:mi>h</m:mi><m:mo>+</m:mo><m:mn>1</m:mn></m:math>,  <m:math><m:mi>k</m:mi></m:math>&#160;observations were found to have the same value, then instead of giving them the ranks

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mi>h</m:mi><m:mo>+</m:mo><m:mn>1</m:mn><m:mo>,</m:mo><m:mi>h</m:mi><m:mo>+</m:mo><m:mn>2</m:mn><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mi>h</m:mi><m:mo>+</m:mo><m:mi>k</m:mi><m:mtext>,</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

all <m:math><m:mi>k</m:mi></m:math>&#160;observations would be assigned the rank

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mfrac><m:mrow><m:mn>2</m:mn><m:mi>h</m:mi><m:mo>+</m:mo><m:mi>k</m:mi><m:mo>+</m:mo><m:mn>1</m:mn></m:mrow><m:mn>2</m:mn></m:mfrac>
</m:math></td><td class="formula2"/></tr></table></div>

and the next value in ascending order would be assigned the rank

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mi>h</m:mi><m:mo>+</m:mo><m:mi>k</m:mi><m:mo>+</m:mo> <m:mn>1</m:mn><m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

The process is repeated for each of the <m:math><m:mi>m</m:mi></m:math>&#160;variables.</div>
 <div class="paramtext">Let <m:math><m:msub><m:mi>y</m:mi><m:mrow><m:mi>i</m:mi><m:mi>j</m:mi></m:mrow></m:msub></m:math>&#160;be the rank assigned to the observation  <m:math><m:msub><m:mi>x</m:mi><m:mrow><m:mi>i</m:mi><m:mi>j</m:mi></m:mrow></m:msub></m:math>&#160;when the <m:math><m:mi>j</m:mi></m:math>th variable is being ranked.  The actual observations <m:math><m:msub><m:mi>x</m:mi><m:mrow><m:mi>i</m:mi><m:mi>j</m:mi></m:mrow></m:msub></m:math>&#160;are replaced by the ranks <m:math><m:msub><m:mi>y</m:mi><m:mrow><m:mi>i</m:mi><m:mi>j</m:mi></m:mrow></m:msub></m:math>.</div></td>
</tr><tr>
<td style="width:2.1em;" valign="baseline">(b)</td>
<td valign="top">Nonparametric rank correlation coefficients
 <table class="standard-100"><tr>
<td style="width:2.1em;" valign="baseline">(i)</td>
<td valign="top">Kendall's tau:

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:msub><m:mi>R</m:mi><m:mrow><m:mi>j</m:mi><m:mi>k</m:mi></m:mrow></m:msub><m:mo>=</m:mo><m:mfrac><m:mrow><m:munderover><m:mo>&#8721;</m:mo><m:mrow><m:mi>h</m:mi><m:mo>=</m:mo><m:mn>1</m:mn></m:mrow><m:mi>n</m:mi></m:munderover><m:munderover><m:mo>&#8721;</m:mo><m:mrow><m:mi>i</m:mi><m:mo>=</m:mo><m:mn>1</m:mn></m:mrow><m:mi>n</m:mi></m:munderover><m:mrow><m:mi>sign</m:mi><m:mfenced separators=""><m:msub><m:mi>y</m:mi><m:mrow><m:mi>h</m:mi><m:mi>j</m:mi></m:mrow></m:msub><m:mo>-</m:mo><m:msub><m:mi>y</m:mi><m:mrow><m:mi>i</m:mi><m:mi>j</m:mi></m:mrow></m:msub></m:mfenced></m:mrow><m:mrow><m:mi>sign</m:mi><m:mfenced separators=""><m:msub><m:mi>y</m:mi><m:mrow><m:mi>h</m:mi><m:mi>k</m:mi></m:mrow></m:msub><m:mo>-</m:mo><m:msub><m:mi>y</m:mi><m:mrow><m:mi>i</m:mi><m:mi>k</m:mi></m:mrow></m:msub></m:mfenced></m:mrow></m:mrow>
  <m:msqrt><m:mfenced open="[" close="]" separators=""><m:mi>n</m:mi><m:mfenced separators=""><m:mi>n</m:mi><m:mo>-</m:mo><m:mn>1</m:mn></m:mfenced><m:mo>-</m:mo><m:msub><m:mi>T</m:mi><m:mi>j</m:mi></m:msub></m:mfenced><m:mfenced open="[" close="]" separators=""><m:mi>n</m:mi><m:mfenced separators=""><m:mi>n</m:mi><m:mo>-</m:mo><m:mn>1</m:mn></m:mfenced><m:mo>-</m:mo><m:msub><m:mi>T</m:mi><m:mi>k</m:mi></m:msub></m:mfenced></m:msqrt>
 </m:mfrac><m:mtext>, &#8195;</m:mtext><m:mi>j</m:mi><m:mo>,</m:mo><m:mi>k</m:mi><m:mo>=</m:mo><m:mn>1</m:mn><m:mo>,</m:mo><m:mn>2</m:mn><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mi>m</m:mi><m:mtext>,</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div><table class="standard-100"><tr>
<td style="width:3.3em;" valign="baseline">where</td>
<td valign="top"><m:math><m:mrow><m:mi>sign</m:mi><m:mo>&#8289;</m:mo><m:mi>u</m:mi></m:mrow><m:mo>=</m:mo><m:mn>1</m:mn></m:math>&#160;if <m:math><m:mi>u</m:mi><m:mo>&gt;</m:mo><m:mn>0</m:mn></m:math>,</td>
</tr><tr>
<td style="width:3.3em;" valign="baseline"/>
<td valign="top"><m:math><m:mrow><m:mi>sign</m:mi><m:mo>&#8289;</m:mo><m:mi>u</m:mi></m:mrow><m:mo>=</m:mo><m:mn>0</m:mn></m:math>&#160;if <m:math><m:mi>u</m:mi><m:mo>=</m:mo><m:mn>0</m:mn></m:math>,</td>
</tr><tr>
<td style="width:3.3em;" valign="baseline"/>
<td valign="top"><m:math><m:mrow><m:mi>sign</m:mi><m:mo>&#8289;</m:mo><m:mi>u</m:mi></m:mrow><m:mo>=</m:mo><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow></m:math>&#160;if <m:math><m:mi>u</m:mi><m:mo>&lt;</m:mo><m:mn>0</m:mn></m:math>,</td>
</tr></table>
and <m:math><m:msub><m:mi>T</m:mi><m:mi>j</m:mi></m:msub><m:mo>=</m:mo><m:mo>&#8721;</m:mo><m:msub><m:mi>t</m:mi><m:mi>j</m:mi></m:msub><m:mfenced separators=""><m:msub><m:mi>t</m:mi><m:mi>j</m:mi></m:msub><m:mo>-</m:mo><m:mn>1</m:mn></m:mfenced></m:math>, where <m:math><m:msub><m:mi>t</m:mi><m:mi>j</m:mi></m:msub></m:math>&#160;is the number of ties of a particular value of variable <m:math><m:mi>j</m:mi></m:math>, and the summation is over all tied values of variable <m:math><m:mi>j</m:mi></m:math>.</td>
</tr><tr>
<td style="width:2.1em;" valign="baseline">(ii)</td>
<td valign="top">Spearman's:

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:msubsup><m:mi>R</m:mi><m:mrow><m:mi>j</m:mi><m:mi>k</m:mi></m:mrow><m:mo>*</m:mo></m:msubsup><m:mo>=</m:mo><m:mfrac><m:mrow><m:mi>n</m:mi><m:mfenced separators=""><m:msup><m:mi>n</m:mi><m:mn>2</m:mn></m:msup><m:mo>-</m:mo><m:mn>1</m:mn></m:mfenced><m:mo>-</m:mo><m:mn>6</m:mn><m:munderover><m:mo>&#8721;</m:mo><m:mrow><m:mi>i</m:mi><m:mo>=</m:mo><m:mn>1</m:mn></m:mrow><m:mi>n</m:mi></m:munderover><m:msup>
<m:mfenced separators=""><m:msub><m:mi>y</m:mi><m:mrow><m:mi>i</m:mi><m:mi>j</m:mi></m:mrow></m:msub><m:mo>-</m:mo><m:msub><m:mi>y</m:mi><m:mrow><m:mi>i</m:mi><m:mi>k</m:mi></m:mrow></m:msub></m:mfenced>
<m:mn>2</m:mn></m:msup><m:mo>-</m:mo><m:mfrac other="small"><m:mn>1</m:mn><m:mn>2</m:mn></m:mfrac><m:mfenced separators=""><m:msubsup><m:mi>T</m:mi><m:mi>j</m:mi><m:mo>*</m:mo></m:msubsup><m:mo>+</m:mo><m:msubsup><m:mi>T</m:mi><m:mi>k</m:mi><m:mo>*</m:mo></m:msubsup></m:mfenced></m:mrow>
  <m:msqrt><m:mfenced open="[" close="]" separators=""><m:mi>n</m:mi><m:mfenced separators=""><m:msup><m:mi>n</m:mi><m:mn>2</m:mn></m:msup><m:mo>-</m:mo><m:mn>1</m:mn></m:mfenced><m:mo>-</m:mo><m:msubsup><m:mi>T</m:mi><m:mi>j</m:mi><m:mo>*</m:mo></m:msubsup></m:mfenced><m:mfenced open="[" close="]" separators=""><m:mi>n</m:mi><m:mfenced separators=""><m:msup><m:mi>n</m:mi><m:mn>2</m:mn></m:msup><m:mo>-</m:mo><m:mn>1</m:mn></m:mfenced><m:mo>-</m:mo><m:msubsup><m:mi>T</m:mi><m:mi>k</m:mi><m:mo>*</m:mo></m:msubsup></m:mfenced></m:msqrt>
 </m:mfrac><m:mtext>, &#8195;</m:mtext><m:mi>j</m:mi><m:mo>,</m:mo><m:mi>k</m:mi><m:mo>=</m:mo><m:mn>1</m:mn><m:mo>,</m:mo><m:mn>2</m:mn><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mi>m</m:mi><m:mtext>,</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

where <m:math><m:msubsup><m:mi>T</m:mi><m:mi>j</m:mi><m:mo>*</m:mo></m:msubsup><m:mo>=</m:mo><m:mo>&#8721;</m:mo><m:msub><m:mi>t</m:mi><m:mi>j</m:mi></m:msub><m:mfenced separators=""><m:msubsup><m:mi>t</m:mi><m:mi>j</m:mi><m:mn>2</m:mn></m:msubsup><m:mo>-</m:mo><m:mn>1</m:mn></m:mfenced></m:math>, <m:math><m:msub><m:mi>t</m:mi><m:mi>j</m:mi></m:msub></m:math>&#160;being the number of ties of a particular value of variable <m:math><m:mi>j</m:mi></m:math>, and the summation being over all tied values of variable <m:math><m:mi>j</m:mi></m:math>.</td>
</tr></table></td>
</tr></table>
</div><h2 class="standard"><a class="sec" name="references" id="references"/>4&#160;&#160;References</h2><div class="paramtext"><a name="ref135" id="ref135"/>Siegel S (1956)  <i>Non-parametric Statistics for the Behavioral Sciences</i> McGraw&#8211;Hill </div><h2 class="standard"><a class="sec" name="parameters" id="parameters"/>5&#160;&#160;Parameters</h2>
<dl><dt class="paramhead"><a name="N" id="N"/>1: &#160;&#160;&#8194; N &#8211; INTEGER<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: 

<m:math><m:mi>n</m:mi></m:math>, the number of observations or cases.</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction><m:mo>&#8805;</m:mo><m:mn>2</m:mn></m:math>.
</div></dd><dt class="paramhead"><a name="M" id="M"/>2: &#160;&#160;&#8194; M &#8211; INTEGER<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: 

<m:math><m:mi>m</m:mi></m:math>, the number of variables.</div>
<div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#M"><m:mi mathcolor="#EE0000" mathvariant="bold">M</m:mi></m:maction><m:mo>&#8805;</m:mo><m:mn>2</m:mn></m:math>.
</div></dd><dt class="paramhead"><a name="X" id="X"/>3: &#160;&#160;&#8194; X(<a class="arg" href="#LDX">LDX</a>,<a class="arg" href="#M">M</a>) &#8211; REAL&#160;(KIND=nag_wp)&#160;array<span class="pclass">Input/Output</span></dt><dd><div class="paramtext"><i>On entry</i>: <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#X"><m:mi mathcolor="#EE0000" mathvariant="bold">X</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi mathvariant="italic">i</m:mi><m:mi mathvariant="italic">j</m:mi></m:mfenced></m:mrow></m:math>&#160;must be set to <m:math><m:msub><m:mi>x</m:mi><m:mrow><m:mi mathvariant="italic">i</m:mi><m:mi mathvariant="italic">j</m:mi></m:mrow></m:msub></m:math>, the value of the <m:math><m:mi mathvariant="italic">i</m:mi></m:math>th observation on the <m:math><m:mi mathvariant="italic">j</m:mi></m:math>th variable, for <m:math><m:mi mathvariant="italic">i</m:mi><m:mo>=</m:mo><m:mn>1</m:mn><m:mo>,</m:mo><m:mn>2</m:mn><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mi>n</m:mi></m:math>&#160;and <m:math><m:mi mathvariant="italic">j</m:mi><m:mo>=</m:mo><m:mn>1</m:mn><m:mo>,</m:mo><m:mn>2</m:mn><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mi>m</m:mi></m:math>.</div>
<div class="paramtext"><i>On exit</i>: <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#X"><m:mi mathcolor="#EE0000" mathvariant="bold">X</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi mathvariant="italic">i</m:mi><m:mi mathvariant="italic">j</m:mi></m:mfenced></m:mrow></m:math>&#160;contains the rank <m:math><m:msub><m:mi>y</m:mi><m:mrow><m:mi mathvariant="italic">i</m:mi><m:mi mathvariant="italic">j</m:mi></m:mrow></m:msub></m:math>&#160;of the observation <m:math><m:msub><m:mi>x</m:mi><m:mrow><m:mi mathvariant="italic">i</m:mi><m:mi mathvariant="italic">j</m:mi></m:mrow></m:msub></m:math>, for <m:math><m:mi mathvariant="italic">i</m:mi><m:mo>=</m:mo><m:mn>1</m:mn><m:mo>,</m:mo><m:mn>2</m:mn><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mi>n</m:mi></m:math>&#160;and <m:math><m:mi mathvariant="italic">j</m:mi><m:mo>=</m:mo><m:mn>1</m:mn><m:mo>,</m:mo><m:mn>2</m:mn><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mi>m</m:mi></m:math>.</div></dd><dt class="paramhead"><a name="LDX" id="LDX"/>4: &#160;&#160;&#8194; LDX &#8211; INTEGER<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: the first dimension of the array <a class="arg" href="#X">X</a> as declared in the (sub)program from which G02BNF is called.</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#LDX"><m:mi mathcolor="#EE0000" mathvariant="bold">LDX</m:mi></m:maction><m:mo>&#8805;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction></m:math>.
</div></dd><dt class="paramhead"><a name="ITYPE" id="ITYPE"/>5: &#160;&#160;&#8194; ITYPE &#8211; INTEGER<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: the type of correlation coefficients which are to be calculated.

<dl>
<dt class="paramval"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#ITYPE"><m:mi mathcolor="#EE0000" mathvariant="bold">ITYPE</m:mi></m:maction><m:mo>=</m:mo><m:mn>-1</m:mn></m:math></dt>
<dd>Only Kendall's tau coefficients are calculated.</dd>
<dt class="paramval"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#ITYPE"><m:mi mathcolor="#EE0000" mathvariant="bold">ITYPE</m:mi></m:maction><m:mo>=</m:mo><m:mn>0</m:mn></m:math></dt>
<dd>Both Kendall's tau and Spearman's coefficients are calculated.</dd>
<dt class="paramval"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#ITYPE"><m:mi mathcolor="#EE0000" mathvariant="bold">ITYPE</m:mi></m:maction><m:mo>=</m:mo><m:mn>1</m:mn></m:math></dt>
<dd>Only Spearman's coefficients are calculated.</dd></dl>
</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#ITYPE"><m:mi mathcolor="#EE0000" mathvariant="bold">ITYPE</m:mi></m:maction><m:mo>=</m:mo><m:mn>-1</m:mn></m:math>, <m:math><m:mn>0</m:mn></m:math>&#160;or <m:math><m:mn>1</m:mn></m:math>.
</div></dd><dt class="paramhead"><a name="RR" id="RR"/>6: &#160;&#160;&#8194; RR(<a class="arg" href="#LDRR">LDRR</a>,<a class="arg" href="#M">M</a>) &#8211; REAL&#160;(KIND=nag_wp)&#160;array<span class="pclass">Output</span></dt><dd>
<div class="paramtext"><i>On exit</i>: the requested correlation coefficients.
<div class="paramtext">If only Kendall's tau coefficients are requested (<m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#ITYPE"><m:mi mathcolor="#EE0000" mathvariant="bold">ITYPE</m:mi></m:maction><m:mo>=</m:mo><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow></m:math>), <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#RR"><m:mi mathcolor="#EE0000" mathvariant="bold">RR</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>j</m:mi><m:mi>k</m:mi></m:mfenced></m:mrow></m:math>&#160;contains Kendall's tau for the <m:math><m:mi>j</m:mi></m:math>th and <m:math><m:mi>k</m:mi></m:math>th variables.</div>
<div class="paramtext">If only Spearman's coefficients are requested (<m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#ITYPE"><m:mi mathcolor="#EE0000" mathvariant="bold">ITYPE</m:mi></m:maction><m:mo>=</m:mo><m:mn>1</m:mn></m:math>), <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#RR"><m:mi mathcolor="#EE0000" mathvariant="bold">RR</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>j</m:mi><m:mi>k</m:mi></m:mfenced></m:mrow></m:math>&#160;contains Spearman's rank correlation coefficient for the <m:math><m:mi>j</m:mi></m:math>th and <m:math><m:mi>k</m:mi></m:math>th variables.</div>
<div class="paramtext">If both Kendall's tau and Spearman's coefficients are requested (<m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#ITYPE"><m:mi mathcolor="#EE0000" mathvariant="bold">ITYPE</m:mi></m:maction><m:mo>=</m:mo><m:mn>0</m:mn></m:math>), the upper triangle of <a class="arg" href="#RR">RR</a> contains the Spearman coefficients and the lower triangle the Kendall coefficients. That is, for the <m:math><m:mi mathvariant="italic">j</m:mi></m:math>th and <m:math><m:mi mathvariant="italic">k</m:mi></m:math>th variables, where <m:math><m:mi mathvariant="italic">j</m:mi></m:math>&#160;is less than <m:math><m:mi mathvariant="italic">k</m:mi></m:math>, <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#RR"><m:mi mathcolor="#EE0000" mathvariant="bold">RR</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi mathvariant="italic">j</m:mi><m:mi mathvariant="italic">k</m:mi></m:mfenced></m:mrow></m:math>&#160;contains the Spearman rank correlation coefficient, and <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#RR"><m:mi mathcolor="#EE0000" mathvariant="bold">RR</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi mathvariant="italic">k</m:mi><m:mi mathvariant="italic">j</m:mi></m:mfenced></m:mrow></m:math>&#160;contains Kendall's tau, for <m:math><m:mi mathvariant="italic">j</m:mi><m:mo>=</m:mo><m:mn>1</m:mn><m:mo>,</m:mo><m:mn>2</m:mn><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mi>m</m:mi></m:math>&#160;and <m:math><m:mi mathvariant="italic">k</m:mi><m:mo>=</m:mo><m:mn>1</m:mn><m:mo>,</m:mo><m:mn>2</m:mn><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mi>m</m:mi></m:math>.</div>
<div class="paramtext">(Diagonal terms, <m:math><m:mrow><m:maction actiontype="link" dsi:type="simple" dsi:href="#RR"><m:mi mathcolor="#EE0000" mathvariant="bold">RR</m:mi></m:maction><m:mfenced separators="," open="(" close=")"><m:mi>j</m:mi><m:mi>j</m:mi></m:mfenced></m:mrow></m:math>, are unity for all three values of <a class="arg" href="#ITYPE">ITYPE</a>.)</div>
</div></dd><dt class="paramhead"><a name="LDRR" id="LDRR"/>7: &#160;&#160;&#8194; LDRR &#8211; INTEGER<span class="pclass">Input</span></dt><dd>
<div class="paramtext"><i>On entry</i>: the first dimension of the array <a class="arg" href="#RR">RR</a> as declared in the (sub)program from which G02BNF is called.</div>
<div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#LDRR"><m:mi mathcolor="#EE0000" mathvariant="bold">LDRR</m:mi></m:maction><m:mo>&#8805;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#M"><m:mi mathcolor="#EE0000" mathvariant="bold">M</m:mi></m:maction></m:math>.
</div></dd><dt class="paramhead"><a name="KWORKA" id="KWORKA"/>8: &#160;&#160;&#8194; KWORKA(<a class="arg" href="#N">N</a>) &#8211; INTEGER&#160;array<span class="pclass">Workspace</span></dt><dt class="multi-paramhead"><a name="KWORKB" id="KWORKB"/>9: &#160;&#160;&#8194; KWORKB(<a class="arg" href="#N">N</a>) &#8211; INTEGER&#160;array<span class="pclass">Workspace</span></dt><dt class="multi-paramhead"><a name="WORK1" id="WORK1"/>10: &#8194; WORK1(<a class="arg" href="#M">M</a>) &#8211; REAL&#160;(KIND=nag_wp)&#160;array<span class="pclass">Workspace</span></dt><dt class="multi-paramhead"><a name="WORK2" id="WORK2"/>11: &#8194; WORK2(<a class="arg" href="#M">M</a>) &#8211; REAL&#160;(KIND=nag_wp)&#160;array<span class="pclass">Workspace</span></dt><dt class="paramhead"><a name="IFAIL" id="IFAIL"/>12: &#8194; IFAIL &#8211; INTEGER<span class="pclass">Input/Output</span></dt><dd>
<div class="paramtext"><i>On entry</i>: <a class="arg" href="#IFAIL">IFAIL</a> must be set to <m:math><m:mn>0</m:mn></m:math>, <m:math><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow><m:mtext>&#8203; or &#8203;</m:mtext><m:mn>1</m:mn></m:math>. If you are unfamiliar with this parameter you should refer to <a class="sec" href="../GENINT/essint.xml#errorhandling">Section 3.3</a> in  the Essential Introduction for details.</div>
<div class="paramtext"><i>On exit</i>: <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#errors"><m:mn mathcolor="#003399" mathvariant="bold">0</m:mn></m:maction></m:math>&#160;unless the routine detects an error or a warning has been flagged (see <a class="sec" href="#errors">Section 6</a>). <div class="paramtext">For environments where it might be inappropriate to halt program execution when an error is detected, the value <m:math><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow><m:mtext>&#8203; or &#8203;</m:mtext><m:mn>1</m:mn></m:math>&#160;is recommended.  If the output of error messages is undesirable, then the value <m:math><m:mn>1</m:mn></m:math>&#160;is recommended.  Otherwise, if you are not familiar with this parameter, the recommended value is <m:math><m:mn>0</m:mn></m:math>.  <b>When the value <m:math><m:mrow><m:mo>-</m:mo><m:mn mathvariant="bold">1</m:mn></m:mrow><m:mtext>&#8203; or &#8203;</m:mtext><m:mn mathvariant="bold">1</m:mn></m:math>&#160;is used it is essential to test the value of <a class="arg" href="#IFAIL">IFAIL</a> on exit.</b></div></div></dd></dl><h2 class="standard"><a class="sec" name="errors" id="errors"/>6&#160;&#160;Error Indicators and Warnings</h2>
<div class="paramtext">If on entry <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#errors"><m:mn mathcolor="#003399" mathvariant="bold">0</m:mn></m:maction></m:math>&#160;or <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#errors"><m:mn mathcolor="#003399" mathvariant="bold">-1</m:mn></m:maction></m:math>, explanatory error messages are output on the current error message unit (as defined by <a class="rout" href="../X04/x04aaf.xml">X04AAF</a>).</div><div class="paramtext">Errors or warnings detected by the routine:</div>
<dl class="ifail">
<dt class="errorhead"><a name="IFeq1" id="IFeq1"/><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:mn>1</m:mn></m:math></dt>
<dd>
<table class="ifail"><tr><td class="ifail1">On&#160;entry,</td><td class="ifail2-90"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction><m:mo>&lt;</m:mo><m:mn>2</m:mn></m:math>.</td></tr></table></dd>
</dl><dl class="ifail">
<dt class="errorhead"><a name="IFeq2" id="IFeq2"/><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:mn>2</m:mn></m:math></dt>
<dd>
<table class="ifail"><tr><td class="ifail1">On&#160;entry,</td><td class="ifail2-90"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#M"><m:mi mathcolor="#EE0000" mathvariant="bold">M</m:mi></m:maction><m:mo>&lt;</m:mo><m:mn>2</m:mn></m:math>.</td></tr></table></dd>
</dl><dl class="ifail">
<dt class="errorhead"><a name="IFeq3" id="IFeq3"/><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:mn>3</m:mn></m:math></dt>
<dd>
<table class="ifail"><tr><td class="ifail1">On&#160;entry,</td><td class="ifail2-90"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#LDX"><m:mi mathcolor="#EE0000" mathvariant="bold">LDX</m:mi></m:maction><m:mo>&lt;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction></m:math>,</td></tr><tr><td class="ifail1">or</td><td class="ifail2-90"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#LDRR"><m:mi mathcolor="#EE0000" mathvariant="bold">LDRR</m:mi></m:maction><m:mo>&lt;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#M"><m:mi mathcolor="#EE0000" mathvariant="bold">M</m:mi></m:maction></m:math>.</td></tr></table></dd>
</dl><dl class="ifail">
<dt class="errorhead"><a name="IFeq4" id="IFeq4"/><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:mn>4</m:mn></m:math></dt>
<dd>
<table class="ifail"><tr><td class="ifail1">On&#160;entry,</td><td class="ifail2-90"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#ITYPE"><m:mi mathcolor="#EE0000" mathvariant="bold">ITYPE</m:mi></m:maction><m:mo>&lt;</m:mo><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow></m:math>,</td></tr><tr><td class="ifail1">or</td><td class="ifail2-90"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#ITYPE"><m:mi mathcolor="#EE0000" mathvariant="bold">ITYPE</m:mi></m:maction><m:mo>&gt;</m:mo><m:mn>1</m:mn></m:math>.</td></tr></table></dd>
</dl><h2 class="standard"><a class="sec" name="accuracy" id="accuracy"/>7&#160;&#160;Accuracy</h2>
<div class="paramtext">The method used is believed to be stable.</div><h2 class="standard"><a class="sec" name="fcomments" id="fcomments"/>8&#160;&#160;Further Comments</h2>
<div class="paramtext">The time taken by G02BNF depends on <m:math><m:mi>n</m:mi></m:math>&#160;and <m:math><m:mi>m</m:mi></m:math>.</div><h2 class="standard"><a class="sec" name="example" id="example"/>9&#160;&#160;Example</h2>
<div class="paramtext">This example reads in a set of data consisting of nine observations on each of three variables.  The program then calculates and prints the rank of each observation, and both Kendall's tau and Spearman's rank correlation coefficients for all three variables.</div><h3 class="standard"><a class="sec" name="examtext" id="examtext"/>9.1&#160;&#160;Program Text</h3>
<p><a class="verbatimref" href="../../examples/source/g02bnfe.f90">Program Text (g02bnfe.f90)</a></p><h3 class="standard"><a class="sec" name="examdata" id="examdata"/>9.2&#160;&#160;Program Data</h3>
<p><a class="verbatimref" href="../../examples/data/g02bnfe.d">Program&#160;Data (g02bnfe.d)</a></p><h3 class="standard"><a class="sec" name="examresults" id="examresults"/>9.3&#160;&#160;Program Results</h3>
<p><a class="verbatimref" href="../../examples/baseresults/g02bnfe.r">Program Results (g02bnfe.r)</a></p>
<hr/><div><a class="rout" href="../../pdf/G02/g02bnf.pdf">G02BNF (PDF version)</a></div><div><a class="chap" href="g02conts.xml">G02 Chapter Contents</a></div><div><a class="chapint" href="g02intro.xml">G02 Chapter Introduction</a></div>
<div><a class="htmltoc" href="../FRONTMATTER/manconts.xml">NAG Library Manual</a></div>
<div><hr/><a class="genint" href="../FRONTMATTER/copyright.xml">&#169; The Numerical Algorithms Group Ltd, Oxford, UK. 2011</a></div></body></html>