# 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.

- Calculator id: `spearman-correlation` · Category: Statistics & Probability (`statistics`) · Tool name: `calculate_spearman_correlation`
- Canonical page: https://tttkmbb.com/statistics/spearman-correlation · This document: https://tttkmbb.com/statistics/spearman-correlation.md · JSON definition: https://tttkmbb.com/statistics/spearman-correlation.json

## Purpose

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.

**Use when:** 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).

## Input

| Parameter | Type | Unit | Required | Description |
| --- | --- | --- | --- | --- |
| `x_values` | number_list |  | required | Independent (explanatory) variable, one number per observation. |
| `y_values` | number_list |  | required | Dependent (response) variable, in the same order as x_values. |

## Output

| Field | Type | Unit | Description |
| --- | --- | --- | --- |
| `sample_size` | integer |  | Number of (x, y) pairs. |
| `spearman_rho` | number |  | Rank correlation between −1 and 1. |
| `t_statistic` | number |  | ρ · √((n − 2) / (1 − ρ²)), approximately t-distributed with n − 2 df under H0: ρ = 0. |
| `degrees_of_freedom` | integer |  | n − 2. |
| `p_value` | number |  | P(\|T_{n−2}\| ≥ \|t\|); omitted when \|ρ\| = 1. |
| `has_ties` | boolean |  | true when either variable contains repeated values (average ranks were used). |
| `interpretation` | string |  | Strength (very weak < 0.2, weak < 0.4, moderate < 0.6, strong < 0.8, very strong ≥ 0.8 in \|ρ\|) and direction of the monotonic association. |

## 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.

## Data Sources

- Wikipedia – Spearman's rank correlation coefficient — https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient (reference, retrieved 2026-09-24)
- Spearman C (1904) The proof and measurement of association between two things, Am J Psychol 15:72-101 — https://doi.org/10.2307/1412159 (peer_reviewed, retrieved 2026-09-24)

Data freshness: `static`. Deterministic formula with fixed constants; results never go stale. Inputs supplied by the caller determine the output.

## API

- `GET https://tttkmbb.com/api/v1/calculate/spearman-correlation?x_values=…&y_values=…`
- `POST https://tttkmbb.com/api/v1/calculate/spearman-correlation` with JSON body `{"inputs": {…}}`
- Response: unified envelope (`success`, `request`, `result.values`, `result.units`, `sources`, `freshness`, `timestamp`, `next_actions`, `links`); see https://tttkmbb.com/docs/response-format.md
- Schema: https://tttkmbb.com/api/v1/calculators/spearman-correlation · OpenAPI operationId `calculate_spearman_correlation` in https://tttkmbb.com/openapi.json
- Authentication: none. Rate limit: fair use, see https://tttkmbb.com/docs/rate-limits.md.

## MCP

- Server: `https://tttkmbb.com/mcp` (Streamable HTTP, JSON-RPC 2.0, no auth)
- Tool:  `run_calculator` with `{"calculator_id": "spearman-correlation", "inputs": {…}}`

## Example

- IQ vs hours of TV per week, n = 10 (Wikipedia example): inputs `{"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): inputs `{"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
```

## Limitations

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). 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. All values are computed from the formula above; no measurement or live data is involved.

## 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

- [Correlation Coefficient Calculator](https://tttkmbb.com/statistics/correlation.md) — Pearson's linear correlation coefficient.
- [Linear Regression Calculator](https://tttkmbb.com/statistics/linear-regression.md) — Fit a line when the relationship is linear.
