Calculates Spearman’s rank correlation coefficient (S.J. Welham, N.M. Maclaren & H.R. Simpson).

### Options

`PRINT` = string tokens |
Output required (`test` , `correlations` , `ranks` ): `test` produces the correlation coefficient/matrix and relevant test statistics, `correlations` prints out just the correlation coefficients for each pair of variates; `ranks` produces the vectors of ranks for each sample; default `test` |
---|---|

`GROUPS` = factor |
Defines the sample membership if only one variate is specified by `DATA` |

`CORRELATION` = scalar or symmetric matrix |
Scalar to save the rank correlation coefficient if there are two samples, or symmetric matrix to save the coefficients between all pairs of samples if there are several |

`T` = scalar or symmetric matrix |
Scalar to save the Student’s t approximation to the correlation coefficient if there are two samples, or symmetric matrix to save the t approximations for all pairs of samples if there are several (calculated only if the sample size is 8 or more) |

`DF` = scalars |
Scalar to save the degrees of freedom for each t-statistic |

### Parameters

`DATA` = variates |
List of variates containing the data for each sample, or a single variate containing the data from all the samples (the `GROUPS` option must then be set to indicate the sample to which each unit belongs) |
---|---|

`RANKS` = variates |
Saves the ranks |

### Description

`SPEARMAN`

calculates Spearman’s rank correlation coefficient between pairs of samples. The samples can be stored in different variates and supplied in a list with the `DATA`

parameter. Alternatively, they can all be placed in a single variate, and the `GROUPS`

option set to a factor to indicate the sample to which each unit belongs.

If the sample size is less than 20, an exact two-sided probability is calculated using the `PRSPEARMAN`

procedure. Note, though, that the probability will be approximate if the variates contain ties; the probability is calculated for the adjusted correlation, but the calculation itself takes no account of the ties. `SPEARMAN`

also calculates a Student’s t approximation if the sample size is 8 or more (i.e. large enough for the approximation to be valid).

Printed output is controlled by the PRINT option, with settings:

`correlation` |
to display correlations; |
---|---|

`test` |
to display tests and correlations; and |

`ranks` |
to display the ranks for each sample. |

The results can also be saved using the `CORRELATION`

, `T`

and `DF`

options and the `RANKS`

parameter.

Options: `PRINT`

, `GROUPS`

, `CORRELATION`

, `T`

, `DF`

.

Parameters: `DATA`

, `RANKS`

.

### Method

Spearman’s rank correlation coefficient is a measure of association between the rankings of two variables measured on *N* individuals (i.e. two vectors of length *N*). The correlation coefficient is calculated from the two vectors of ranks for the samples: let { *X _{i}* ; i=1…

*N*} and {

*Y*; i=1…

_{i}*N*} be the vectors of ranks for sample 1 and sample 2 respectively, then the coefficient

*r*is based on the vector of differences between ranks: {

*D*=

_{i}*X*–

_{i}*Y*; i=1…

_{i}*N*} and is calculated by

*r* = 1 – 6 × ∑_{ i=1…N} *D _{i}*

^{2}/ [

*N*(

*N*

^{2}-1) ].

If ties are present, then the statistic will be biased, and must be recalculated taking account of ties by:

*r* = ( ∑*X _{i}*

^{2 }+ ∑

*Y*

_{i}^{2 }– ∑

*D*

_{i}^{2 }) / ( 2 × √( ∑

*X*

_{i}^{2 }× ∑

*Y*

_{i}^{2 }) )

where ∑*X _{i}*

^{2 }= (

*N*

^{3}–

*N*)/12 –

*T*;

_{x}∑*Y _{i}*

^{2 }= (

*N*

^{3}–

*N*)/12 –

*T*;

_{y}*T _{k}* = ∑ (

*t*

_{j}^{3}–

*t*)/12

_{j}and *t _{j}* is the number of observations in the group with rank

*j*.

The t-approximation for this statistic, *T*, is valid for samples of size 8 upwards, and is calculated by

*T* = *r* × √[ (*N*-2)/(1-*r*^{2}) ].

It has approximately a t-distribution on *N*-2 degrees of freedom, and can be used for a test of the null hypothesis of independance between samples. (See for example Siegel 1956, pages 202-213, or Siegel & Castellan 1988, pages 235-244.)

### Action with `RESTRICT`

If any of the variates in `DATA`

is restricted, the statistic is calculated only for the set of units not excluded by the restriction.

### References

Siegel, S. (1956). *Nonparametric Statistics for the Behavioural Sciences*. McGraw-Hill, New York.

Siegel, S. & Castellan, N.J. (1988). *Nonparametric Statictics for the Behavioural Sciences (second edition)*. McGraw-Hill, New York.

### See also

Procedures: `PRSPEARMAN`

, `CMHTEST`

, `FCORRELATION`

, `KCONCORDANCE`

, `KTAU`

, `LCONCORDANCE`

.

Commands for: Basic and nonparametric statistics.

### Example

CAPTION 'SPEARMAN example',!t(\ 'Data from Siegel (1956), Nonparametric Statistics, p. 205.',\ '2 variables are measured on N individuals.'); STYLE=meta,plain VARIATE [VALUE= 82, 98, 87, 40,116,113,111, 83, 85,126,106,117] Authority & [VALUE= 42, 46, 39, 37, 65, 88, 86, 56, 62, 92, 54, 81] Status PRINT Authority,Status; DECIMALS=0 CAPTION 'Calculate Spearman''s Rank Correlation Coefficient for the samples.' SPEARMAN [PRINT=test,ranks; CORRELATION=Correlation; T=t]\ Authority,Status; RANKS=RAuthority,RStatus PRINT Correlation,t & RAuthority,RStatus; DECIMALS=0