Correlation coefficient calculator (Pearson and Spearman)
Enter your values. The answer and the full worked solution update as you type.
Result
| x | y | rank of x | rank of y | d² |
|---|---|---|---|---|
| 2 | 52 | 1 | 1 | 0 |
| 4 | 58 | 2 | 2 | 0 |
| 5 | 61 | 3 | 4 | 1 |
| 7 | 60 | 4 | 3 | 1 |
| 8 | 72 | 5 | 5 | 0 |
| 10 | 75 | 6 | 6 | 0 |
| 11 | 80 | 7 | 7 | 0 |
| 13 | 86 | 8 | 8 | 0 |
Measure how strongly two variables move together. Enter paired x and y values to get Pearson’s correlation coefficient r, the coefficient of determination r² and Spearman’s rank correlation ρ, with tied values given their average rank. The calculator also tests Pearson’s r for a linear correlation, with the t statistic and the two-tailed p-value, and gives an approximate p-value for Spearman’s ρ.
Step-by-step solution
Means
Sums of squares and products
Pearson correlation
Spearman rank correlation
Significance test for Pearson r (H₀: no linear correlation)
Significance of Spearman ρ
Key formulas
- Sums of squares
- Sxx = Σ(x − x̄)² = Σx² − (Σx)²/n, Sxy = Σxy − ΣxΣy/n
- Correlation
- r = Sxy/√(SxxSyy)
How to calculate a correlation coefficient
- Compute the means x̄ and ȳ.
- Compute the sums Sxx = Σ(x − x̄)², Syy = Σ(y − ȳ)² and Sxy = Σ(x − x̄)(y − ȳ).
- Pearson: r = Sxy/√(Sxx·Syy). It always lies between −1 and 1.
- Spearman: rank each variable from smallest to largest, give tied values the average of their ranks and compute Pearson’s r of the ranks. Without ties this equals 1 − 6Σd²/(n(n² − 1)).
- Test Pearson’s r for a linear correlation (H₀: no linear correlation) with t = r√(n − 2)/√(1 − r²) and n − 2 degrees of freedom.
Questions and answers
When should I use Spearman instead of Pearson?
Pearson measures a straight-line relationship and is sensitive to outliers. Spearman only uses the order of the values, so it measures any relationship that keeps rising (or falling) and is robust to outliers and skewed data. Use Spearman for ranked or ordinal data.
What does r² mean?
r² is the fraction of the variation in y that a straight line in x explains. With r = 0.9733, r² = 0.9473, so the line explains about 95% of the variation.
Does a strong correlation prove that x causes y?
No. Both variables may depend on a third one, or the effect may run the other way. A correlation only describes how the values move together.
What counts as a strong correlation?
Rough guidelines are |r| below 0.3 weak, 0.3 to 0.7 moderate and above 0.7 strong, but it depends on the field: in a physics experiment 0.9 may be poor, in social science 0.5 may be large. Always look at the scatter plot as well.
Why does the p-value depend on n?
With few points a high r can easily happen by chance; with many points even a small r is unlikely under H₀. The t statistic r√(n − 2)/√(1 − r²) grows with the number of points.
Practise it yourself
Practise Linear regression & correlation
A calculator gives the answer. In the exam you need the method: practise it with new problems, hints and worked solutions.