📚 Spearman's Rank Correlation Coefficient | 斯皮尔曼等级相关系数
Spearman's rank correlation coefficient is a non-parametric measure of the strength and direction of association that exists between two variables. It is designed to assess how well the relationship between the variables can be described using a monotonic function, without requiring the data to be normally distributed or linearly related. The coefficient is based on the ranked values for each variable rather than the raw data, making it robust to outliers and particularly useful for ordinal data or non-linear monotonic trends.
斯皮尔曼等级相关系数是一种非参数统计量,用于衡量两个变量之间关联的强度与方向。它用于评估变量间的关系能否用单调函数描述,而不要求数据呈正态分布或满足线性关系。该系数基于每个变量的排序值(等级)而非原始数据,因此对异常值不敏感,尤其适用于顺序数据或非线性单调趋势。
1. Introduction to Rank Correlation | 等级相关简介
In many real-world situations, variables do not follow a perfect linear pattern but still move together in a consistent direction. Spearman's rank correlation, denoted by rs or the Greek letter ρ (rho), captures this monotonic relationship. Instead of using actual measurements, each data point is replaced by its rank within the sample, after which the correlation between the two sets of ranks is computed. A rank of 1 is assigned to the smallest value, 2 to the next, and so on.
在许多实际情形中,变量并不遵循完全线性的模式,但仍会朝一致的方向变动。斯皮尔曼等级相关系数(记作 rs 或希腊字母 ρ)捕捉的正是这种单调关系。我们不用原始观测值,而是将每个数据点替换为其在样本中的等级(秩),再计算两组等级之间的相关性。最小的值赋予等级 1,次小的赋予 2,以此类推。
2. Why Use Spearman's Rank? | 为何使用斯皮尔曼等级相关系数?
Spearman's coefficient is preferred when the assumptions of the Pearson product-moment correlation coefficient are violated. Pearson's r requires both variables to be normally distributed and measures only linear correlation. Spearman's rs, on the other hand, works with ordinal data, non-normal continuous data, and any monotonic relationship (whether linear or curved). It is also less affected by extreme outliers, as ranking reduces their influence.
当皮尔逊积矩相关系数的假设条件不成立时,斯皮尔曼系数更为适用。皮尔逊 r 要求两个变量均为正态分布,且只能度量线性相关性。而斯皮尔曼 rs 可用于顺序数据、非正态连续数据以及任何单调关系(线性或曲线均可)。此外,由于排序削弱了极端值的影响,该系数受异常值的干扰更小。
3. Assumptions for Spearman's Rank | 使用斯皮尔曼系数的前提
Although Spearman's rs is less restrictive, it still relies on a few key assumptions. First, the data must consist of paired observations. Second, the variables should be measured on at least an ordinal scale, meaning the values can be meaningfully ranked. Third, the relationship between the two variables is assumed to be monotonic; if the direction of association changes (e.g., a U-shaped curve), Spearman's coefficient may be misleading. Additionally, the standard hypothesis test assumes that the sample is a random selection from the population.
尽管斯皮尔曼 rs 的限制较少,但仍有一些关键前提。首先,数据必须是成对观测值。其次,变量至少得在顺序量表上测量,即其值可以有意义地排序。第三,假设两变量之间的关系是单调的;若关联方向发生改变(例如 U 形曲线),斯皮尔曼系数可能会产生误导。此外,标准假设检验要求样本是从总体中随机抽取的。
4. Notation and the Process of Ranking | 符号与排序过程
Let (xi, yi) represent a pair of observations for n cases. Rank the x-values from 1 to n, giving rank Ri to each xi. Do the same for the y-values, producing rank Si. If there are ties (equal values), assign each tied observation the average of the ranks they would have occupied. The difference for each pair is then di = Ri - Si. The sum of these differences squared, Σdi², forms the core of the calculation.
用 (xi, yi) 表示 n 对观测值。将 x 值按从小到大的顺序赋予等级 1 至 n,每个 xi 得到等级 Ri。对 y 值同样操作,得到等级 Si。若存在并列(相等值),则给每个并列的观测值分配它们本应占据的等级的平均值。每一对的等级差为 di = Ri - Si,这些差值的平方和 Σdi² 是计算的核心。
5. The Spearman's Rank Formula (No Ties) | 斯皮尔曼等级相关系数公式(无并列情形)
When there are no tied ranks, Spearman's rs can be computed directly from the sum of squared rank differences using the simplified formula:
rs = 1 - (6 Σdi²) / (n(n² - 1))
where n is the number of data pairs and Σdi² is the sum of squared differences between the paired ranks. The value of rs always lies between -1 and +1. A value of +1 indicates a perfect positive monotonic association, -1 indicates a perfect negative monotonic association, and 0 suggests no monotonic association.
在没有并列等级的情况下,可以直接利用等级差的平方和,通过简化公式计算斯皮尔曼 rs:
rs = 1 - (6 Σdi²) / (n(n² - 1))
其中 n 为数据对数,Σdi² 为成对等级差的平方和。rs 的值始终介于 -1 和 +1 之间。+1 表示完全的正单调相关,-1 表示完全的负单调相关,0 表示没有单调相关。
6. Tied Ranks and the Correction Factor | 并列等级及其校正
If tied ranks are present, the simple formula becomes inaccurate. Instead, we can calculate rs pute T = Σ(t³ - t) / 12, where t is the number of observations tied at a given rank. Let Tx be the correction for x-ranks and Ty for y-ranks. The adjusted formula is:
rs = [ (n³ - n)/6 - Σdi² - Tx - Ty ] / √[ ((n³ - n)/6 - 2Tx) ((n³ - n)/6 - 2Ty) ]
In A-Level examinations, when ties are few, examiners often accept using the average rank and the simple formula as a reasonable approximation. However, for precise hypothesis testing, the corrected formula or the use of Pearson's r on ranks is recommended.
当存在并列等级时,简化公式会变得不准确。此时,我们可以对排序后的数据使用皮尔逊相关公式,或者用校正项调整简化公式。针对每个变量,计算 T = Σ(t³ - t) / 12,其中 t 是在某个等级上并列的观测值个数。设 Tx 为 x 变量等级的校正项,Ty 为 y 变量等级的校正项。校正后的公式为:
rs = [ (n³ - n)/6 - Σdi² - Tx - Ty ] / √[ ((n³ - n)/6 - 2Tx) ((n³ - n)/6 - 2Ty) ]
在 A-Level 考试中,若并列情形较少,通常允许使用平均等级并代入简化公式作为一种合理的近似。但若要精确进行假设检验,则建议使用校正公式或对等级数据直接计算皮尔逊 r。
7. Hypothesis Testing for ρ | 关于 ρ 的假设检验
We often test whether there is statistically significant evidence of a monotonic association in the population. The null hypothesis is H0: ρ = 0 (no monotonic correlation), while the alternative hypothesis can be two-tailed (H1: ρ ≠ 0) or one-tailed (H1: ρ > 0 or H1: ρ < 0). The test statistic is the sample Spearman's rank correlation coefficient rs. We compare |rs| (or rs directly for one-tailed tests) against a critical value obtained from the Spearman's rank correlation table.
我们常需检验总体中是否存在统计显著的单调相关。原假设为 H0: ρ = 0(无单调相关),备择假设可以是双尾(H1: ρ ≠ 0)或单尾(H1: ρ > 0 或 H1: ρ < 0)。检验统计量为样本斯皮尔曼等级相关系数 rs。我们将 |rs|(单尾检验时直接用 rs)与从斯皮尔曼等级相关系数表中查得的临界值进行比较。
8. Critical Values and Significance | 临界值与显著性
Critical values for Spearman's rs depend on the sample size n and the significance level α (commonly 5% or 1%). For a given n and α, the table provides the minimum absolute value of rs required to reject H0. For example, if n = 10 at the 5% two-tailed level, the critical value is approximately 0.648. If the calculated |rs| exceeds the critical value, we reject H0 and conclude there is significant evidence of a monotonic relationship. Remember that a one-tailed test uses a lower critical value for the same α.
斯皮尔曼 rs 的临界值取决于样本容量 n 和显著性水平 α(通常为 5% 或 1%)。根据给定的 n 和 α,可以查出拒绝 H0 所需的最小 |rs|。例如,当 n = 10、双尾 5% 水平时,临界值约为 0.648。若计算所得的 |rs| 大于临界值,则拒绝 H0,并得出存在显著单调关系证据的结论。需要注意,同一 α 水平下,单尾检验所用的临界值会更小。
9. Worked Example: Calculating rs and Performing a Test | 计算实例
A teacher wants to see if students' scores in a maths quiz and a logic puzzle are related. The scores for 8 students are:
一位老师想了解学生的数学测验成绩与逻辑谜题得分是否相关。8 位学生的成绩如下:
| Student | Maths (x) | Logic (y) | Rank x | Rank y | di | di² |
|---|---|---|---|---|---|---|
| A | 17 | 14 | 3 | 5 | -2 | 4 |
| B | 22 | 13 | 7 | 4 | 3 | 9 |
| C | 15 | 16 | 1 | 7 | -6 | 36 |
| D | 16 | 12 | 2 | 3 | -1 | 1 |
| E | 20 | 19 | 5 | 8 | -3 | 9 |
| F | 21 | 11 | 6 | 2 | 4 | 16 |
| G | 19 | 15 | 4 | 6 | -2 | 4 |
| H | 23 | 9 | 8 | 1 | 7 | 49 |
From the table, n = 8, Σdi² = 4+9+36+1+9+16+4+49 = 128. Then:
rs = 1 - (6 × 128) / (8(64 - 1)) = 1 - 768 / (8 × 63) = 1 - 768/504 ≈ 1 - 1.5238 = -0.5238.
Suppose we test for any association at the 5% two-tailed significance level. For n=8, the critical value is 0.738. Since |rs| = 0.5238 < 0.738, we fail to reject H0. There is insufficient evidence of a monotonic relationship between maths and logic scores.
由上表,n = 8,Σdi² = 4+9+36+1+9+16+4+49 = 128。则:
rs = 1 - (6 × 128) / (8(64 - 1)) = 1 - 768 / (8 × 63) = 1 - 768/504 ≈ 1 - 1.5238 = -0.5238。
假设在 5% 双尾显著性水平上检验是否存在任何关联。对于 n=8,临界值为 0.738。由于 |rs| = 0.5238 < 0.738,我们不能拒绝 H0。即没有足够证据表明数学和逻辑得分之间存在单调关系。
10. Interpretation and Real-World Context | 结果解释与现实背景
When interpreting rs, always place the result in context. A strong positive rs (close to +1) means that as one variable increases, the other tends to increase in rank. A strong negative rs (close to -1) means high ranks for one variable correspond to low ranks for the other. However, a significant rs does not imply causation; it only indicates an association. Additionally, consider the sample size: with very small n, even a large |rs| may not be significant, while with large n, a very small rs can be statistically significant yet practically irrelevant.
解释 rs 时,务必结合具体背景。正的 rs 值较大(接近 +1)意味着一个变量增大时,另一个变量的等级也倾向于增大。负的 rs 值较大(接近 -1)意味着一个变量的高等级与另一个变量的低等级相关联。但显著的 rs 并不代表因果关系,只能说明存在关联。此外还要考虑样本大小:样本量极小时,即使 |rs| 很大也可能不显著;而样本极大时,很小的 rs 也可能统计显著却缺乏实际意义。
Published by TutorHao | Mathematics Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)

或截图后用「扫一扫 → 相册」选择本图