HomeStatistics & Probability › Spearman Rank Correlation Calculator

Spearman Rank Correlation Calculator

Computes Spearman's rank correlation coefficient ρ between two paired lists (Pearson correlation of average ranks, so ties are handled), the t-approximation test statistic and its two-sided p-value, with a strength interpretation.

When to use

You want to measure a monotonic (not necessarily linear) association, the data are ordinal or ranked, or outliers make Pearson's r unreliable.

Do not use when: You need the linear correlation, covariance or a fitted line (use correlation or linear-regression), or the sample is very small (n < 5 gives unreliable p-values with the t approximation).

Formula

ρ = Pearson r of rank(x) and rank(y), ties receiving the mean of the ranks they occupy (equals 1 − 6Σd² / (n(n² − 1)) when there are no ties); t = ρ√((n − 2)/(1 − ρ²)), df = n − 2

The t approximation for the p-value is adequate for n of about 10 or more; exact permutation tables are preferable for smaller samples. ρ is undefined when all x or all y values are equal.

Inputs

ParameterTypeUnitRequiredDescription
x_valuesnumber_listyesIndependent (explanatory) variable, one number per observation.
y_valuesnumber_listyesDependent (response) variable, in the same order as x_values.

Outputs

OutputTypeUnitDescription
sample_sizeintegerNumber of (x, y) pairs.
spearman_rhonumberRank correlation between −1 and 1.
t_statisticnumberρ · √((n − 2) / (1 − ρ²)), approximately t-distributed with n − 2 df under H0: ρ = 0.
degrees_of_freedomintegern − 2.
p_valuenumberP(|T_{n−2}| ≥ |t|); omitted when |ρ| = 1.
has_tiesbooleantrue when either variable contains repeated values (average ranks were used).
interpretationstringStrength (very weak < 0.2, weak < 0.4, moderate < 0.6, strong < 0.8, very strong ≥ 0.8 in |ρ|) and direction of the monotonic association.

Example

IQ vs hours of TV per week, n = 10 (Wikipedia example): {"x_values":[106,100,86,101,99,103,97,113,112,110],"y_values":[7,27,2,50,28,29,20,12,6,17]}{"sample_size":10,"spearman_rho":-0.1758,"t_statistic":-0.505,"degrees_of_freedom":8,"p_value":0.627188,"has_ties":false,"interpretation":"Very weak negative monotonic correlation"}

x = 1..5, y = 2, 4, 5, 4, 5 (ties in y): {"x_values":[1,2,3,4,5],"y_values":[2,4,5,4,5]}{"spearman_rho":0.7379,"t_statistic":1.8935,"degrees_of_freedom":3,"p_value":0.154619,"has_ties":true}

GET https://tttkmbb.com/api/v1/calculate/spearman-correlation?x_values=106%2C100%2C86%2C101%2C99%2C103%2C97%2C113%2C112%2C110&y_values=7%2C27%2C2%2C50%2C28%2C29%2C20%2C12%2C6%2C17

Machine access

Sources

FAQ

Spearman or Pearson?

Pearson measures linear association of interval data; Spearman measures whether y tends to increase with x in any monotonic way, is robust to outliers and works for ordinal data.

Why does my result differ from the 1 − 6Σd²/(n(n² − 1)) formula?

That shortcut is exact only without ties. With ties this calculator uses the Pearson correlation of average ranks, which is the standard tie-corrected definition.

Related calculators