Correlation coefficient calculator (Pearson and Spearman)

Enter your values. The answer and the full worked solution update as you type.

Result

Pearson correlation r0.9733
r²0.9473
Spearman rank correlation ρ0.9762
t statistic for Pearson r10.39
p-value for Pearson r (H₀: no linear correlation)4.657 × 10⁻⁵
p-value for Spearman ρ (t approximation)3.314 × 10⁻⁵
xyrank of xrank of yd²
252110
458220
561341
760431
872550
1075660
1180770
1386880

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

x̄ = 7.5, ȳ = 68, n = 8

Sums of squares and products

Sxx = Σ(x − x̄)² = 98
Syy = Σ(y − ȳ)² = 1002
Sxy = Σ(x − x̄)(y − ȳ) = 305

Pearson correlation

r = Sxy/√(Sxx·Syy) = 305/√(98·1002) = 0.9733
r² = 0.9473

Spearman rank correlation

Rank each list from smallest (1) to largest and square the rank differences d.
Σd² = 2
ρ = 1 − 6Σd²/(n(n² − 1)) = 1 − 6·2/(8·63) = 0.9762

Significance test for Pearson r (H₀: no linear correlation)

t = r·√(n − 2)/√(1 − r²) = 0.9733·√6/√(1 − 0.9473) = 10.39
df = n − 2 = 6
p = 2·P(T > |t|) = 4.657 × 10⁻⁵

Significance of Spearman ρ

t = ρ·√(n − 2)/√(1 − ρ²) = 11.02, p ≈ 3.314 × 10⁻⁵
This t approximation is reasonable for about 10 or more pairs; for small samples use a table of exact critical values for ρ.

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

  1. Compute the means x̄ and ȳ.
  2. Compute the sums Sxx = Σ(x − x̄)², Syy = Σ(y − ȳ)² and Sxy = Σ(x − x̄)(y − ȳ).
  3. Pearson: r = Sxy/√(Sxx·Syy). It always lies between −1 and 1.
  4. 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)).
  5. 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.

</> Embed

Free for teachers and schools: paste this code into your course page, LMS or website. Students can use the calculator and its worked solution without an account.

More calculators