Change language

Learn to calculate by playing with Pearson correlation calculator

A short game to see where the result comes from. Pick a language and start; you can stop halfway and come back.

Loading the game…

← Back to Pearson correlation calculator

What you will practise

Pearson’s r between two variables, with p value, confidence interval, regression line and scatter plot.

How it works

The coefficient r is the covariance of the two variables divided by the product of their standard deviations: a “standardised” version of how much they vary together. It runs from −1 to +1 and does not depend on units.

The p value tests that the true correlation is zero, with a Student’s t on n − 2 degrees of freedom. The confidence interval uses Fisher’s z transformation (r is transformed, the interval is worked out on that scale, where it is nearly normal, and the transformation is undone), so it is not symmetric.

Formula

r = Σ(xᵢ − x̄)(yᵢ − ȳ) / √( Σ(xᵢ − x̄)² · Σ(yᵢ − ȳ)² )
t = r · √( (n − 2) / (1 − r²) ), df = n − 2
CI: z = atanh(r); limits = tanh( z ± critical z / √(n − 3) )
r² = proportion of one variable’s variation shared with the other
Line: y = a + b·x with b = Σ(xᵢ − x̄)(yᵢ − ȳ) / Σ(xᵢ − x̄)², a = ȳ − b·x̄
Guide (Cohen): |r| ≈ 0.1 small · 0.3 medium · 0.5 large

Worked example

Example 1. An almost linear relationship.
With X = 1 to 8 and Y = 2.1, 3.9, 6.2, 7.8, 10.1, 12.2, 13.8, 16.1, the correlation is r = .999 (95% CI .997 to 1.000), p < .001, r² = .999. The line is y = 0.036 + 1.998x: each unit of X goes with almost two of Y.

Example 2. A curved relationship.
With y = x² for x = 1 to 10, r = .975 (CI .893 to .994): a very high correlation, but the relationship is a curve, not a line; the scatter plot shows it and the line fits the ends poorly. Always look at the chart.

Example 3. An outlier.
Ten points rising from 2 to 10 (Y = 2, 3, …, 10) and one that shoots up to 60. r drops to .644 (p = .045; CI .024 to .906): a single point changes the reading entirely. Spearman’s correlation does detect that the relationship is perfectly monotonic (ρ = 1).

How to play

First pick your language. Then work through the challenges one by one: each sets out a case with real numbers and, if you get stuck, you can ask for a hint. When you answer, you see whether you got it right and why. Progress is saved only in your browser, so you can stop halfway and carry on another day.