Correlation Coefficient Calculator
Paste paired X and Y data for Pearson r, r², Spearman ρ, the t statistic and two-tailed p-value, a strength rating and a scatter plot with fitted line.
Separate values with spaces, commas or new lines. The first X pairs with the first Y, and so on.
Least-squares line: y = 3.0001 + 0.5001x. Means: x̄ = 9, ȳ = 7.5009. Sample SDs: sx = 3.3166, sy = 2.0316.
Show the ranks used for Spearman ρ
| # | X | Y | Rank X | Rank Y |
|---|---|---|---|---|
| 1 | 10 | 8.04 | 7 | 7 |
| 2 | 8 | 6.95 | 5 | 4 |
| 3 | 13 | 7.58 | 10 | 6 |
| 4 | 9 | 8.81 | 6 | 9 |
| 5 | 11 | 8.33 | 8 | 8 |
| 6 | 14 | 9.96 | 11 | 10 |
| 7 | 6 | 7.24 | 3 | 5 |
| 8 | 4 | 4.26 | 1 | 1 |
| 9 | 12 | 10.84 | 9 | 11 |
| 10 | 7 | 4.82 | 4 | 2 |
| 11 | 5 | 5.68 | 2 | 3 |
Tied values share the average of the ranks they cover. ρ is the Pearson correlation of these two rank columns.
What Correlation Coefficient Calculator Does
This correlation calculator takes paired X and Y data and returns Pearson’s r with a 95% confidence interval, r², Spearman’s rank correlation ρ, the t statistic and the two-tailed p-value on n − 2 degrees of freedom. A scatter plot with the least-squares line shows whether a straight line is a fair summary of the points. Paste two lists, or two columns copied from a spreadsheet; the calculation runs in your browser as you type.
The example datasets are published ones, so you can check the output against a known answer. Anscombe’s set I gives r = 0.8164, t = 4.2415 on 9 degrees of freedom and p = 0.00217, with a 95% interval of 0.424 to 0.951. R’s cor.test reports the same figures for that data. Set II has almost the same r, 0.8162, but its points lie on a curve. The plot makes that obvious, and the drop in Spearman’s ρ from 0.818 to 0.691 hints at it, while r alone gives no sign.
At least 3 pairs are needed, and neither variable can be constant. With 2 points r is always +1 or −1, and a column with no spread has no correlation to measure.
How to Use Correlation Coefficient Calculator
- Paste X values and Y values as two lists, or switch to two columns copied from a spreadsheet
- Check that each X has one matching Y; the calculator needs at least 3 pairs
- Read Pearson r, its strength rating and the two-tailed p-value
- Compare Spearman ρ with r and look at the scatter plot for curves or outliers
- Open the rank table to see how tied values were ranked for Spearman ρ
Formula Used by Correlation Coefficient Calculator
Pearson correlation coefficient
r = Σ(xᵢ − x̄)(yᵢ − ȳ) ÷ √[ Σ(xᵢ − x̄)² × Σ(yᵢ − ȳ)² ]
- xᵢ, yᵢ
- The i-th pair of values
- x̄, ȳ
- The mean of the x values and of the y values
- n
- Number of pairs
Worked example
x = 1, 2, 3, 4, 5 and y = 2, 4, 5, 4, 5.
- x̄ = 3, ȳ = 4
- x − x̄ = −2, −1, 0, 1, 2 and y − ȳ = −2, 0, 1, 0, 1
- Σ(x − x̄)(y − ȳ) = 4 + 0 + 0 + 0 + 2 = 6
- Σ(x − x̄)² = 10 and Σ(y − ȳ)² = 6
- r = 6 ÷ √60 = 0.7746
Result: r = 0.7746 and r² = 0.60. The least-squares line is y = 2.2 + 0.6x.
Significance test for r
t = r × √(n − 2) ÷ √(1 − r²), with n − 2 degrees of freedom; two-tailed p = 2 × P(T > |t|)
- T
- A Student’s t random variable with n − 2 degrees of freedom
Worked example
The same five pairs, r = 0.7746.
- t = 0.7746 × √3 ÷ √0.4 = 2.1213
- df = 5 − 2 = 3
- Two-tailed p = 0.1240
Result: p = 0.124, so the correlation is not significant at the 0.05 level with only five pairs.
Spearman rank correlation
ρ = Pearson r of the ranks of x and the ranks of y, with tied values given the average of the ranks they occupy
Worked example
The same five pairs.
- Ranks of x: 1, 2, 3, 4, 5
- y = 2, 4, 5, 4, 5. The two 4s share positions 2 and 3, so each gets 2.5; the two 5s share 4 and 5, so each gets 4.5
- Ranks of y: 1, 2.5, 4.5, 2.5, 4.5
- Pearson r of the two rank columns = 0.7379
Result: ρ = 0.7379, with p ≈ 0.155 from the same t approximation.
95% confidence interval for r (Fisher z)
z = atanh(r); z ± 1.96 ÷ √(n − 3); convert both ends back with tanh
Worked example
Anscombe set I: r = 0.8164, n = 11.
- z = atanh(0.8164) = 1.1460
- 1.96 ÷ √8 = 0.6930
- 1.1460 − 0.6930 = 0.4530 and 1.1460 + 0.6930 = 1.8389
- tanh(0.4530) = 0.4244 and tanh(1.8389) = 0.9507
Result: 95% CI 0.424 to 0.951, matching R’s cor.test.
One Rule of Thumb for |r|
Example cut-offs from Schober, Boer and Schwarte (2018). The authors describe such cut-offs as arbitrary and inconsistent, so treat the label as a rough guide.
| |r| | Label |
|---|---|
| 0.00–0.10 | Negligible |
| 0.10–0.39 | Weak |
| 0.40–0.69 | Moderate |
| 0.70–0.89 | Strong |
| 0.90–1.00 | Very strong |
Source: Schober, Boer and Schwarte (2018), Anesthesia & Analgesia 126(5)
Critical Values of r (Two-Tailed)
The smallest |r| that is significant at each level, from t = r√(n − 2) ÷ √(1 − r²) with n − 2 degrees of freedom.
| n (pairs) | df | α = 0.05 | α = 0.01 |
|---|---|---|---|
| 5 | 3 | 0.878 | 0.959 |
| 10 | 8 | 0.632 | 0.765 |
| 15 | 13 | 0.514 | 0.641 |
| 20 | 18 | 0.444 | 0.561 |
| 30 | 28 | 0.361 | 0.463 |
| 50 | 48 | 0.279 | 0.361 |
| 100 | 98 | 0.197 | 0.256 |
Same r, Different Data: Anscombe Sets I and II
Both sets use the same 11 x values. Computed with this calculator.
| Dataset | Pearson r | Spearman ρ | p (Pearson) |
|---|---|---|---|
| Set I (roughly straight) | 0.8164 | 0.8182 | 0.00217 |
| Set II (curved) | 0.8162 | 0.6909 | 0.00218 |
How to Read Your Result
Sign and size
A positive r means y tends to rise as x rises; a negative r means it tends to fall. The size says how tightly the points hug a straight line, from 0 (no linear pattern) to 1 (every point on the line). It says nothing about the slope: a nearly flat line and a steep one can both have r = 0.99.
Significant is not the same as strong
The p-value tests whether the population correlation could be zero, and it depends heavily on sample size. With 100 pairs, r = 0.197 is significant at 0.05, yet r² = 0.039 means the line accounts for under 4% of the variation. With 5 pairs, r = 0.7746 is not significant. Report r and its confidence interval as well as p.
When Pearson and Spearman disagree
Spearman’s ρ only asks whether y rises (or falls) steadily as x rises, so a consistent curve can score high on ρ and lower on r. One extreme point usually moves r much more than ρ. If the two differ by a lot, look at the scatter plot before choosing which to report.
Always look at the plot
Anscombe built his four datasets in 1973 to show that identical summary statistics can come from completely different patterns. Sets I and II above share r ≈ 0.816 and p ≈ 0.002, but only set I is a fair fit for a straight line.
Limitations & Accuracy Notes
- The Pearson p-value and confidence interval assume independent pairs drawn from a roughly bivariate normal population. Time series, repeated measurements on the same person and clustered data break the independence assumption and make p too small.
- The Spearman p-value uses the t approximation, as in Wikipedia’s worked example. For very small samples, exact permutation tables can give a somewhat different value.
- The confidence interval needs at least 4 pairs and is an approximation that improves as n grows.
- Kendall’s tau, partial correlation and weighted correlation are not calculated.
- A restricted range of x (for example, only tall people) lowers r compared with the full population, and a few outliers can raise or lower it sharply.
- Correlation measures association. It does not show that one variable causes the other.
Frequently Asked Questions
How do you calculate the correlation coefficient?
Subtract the mean from every x and every y, multiply each pair of deviations and add them up, then divide by the square root of (sum of squared x deviations × sum of squared y deviations). For x = 1, 2, 3, 4, 5 and y = 2, 4, 5, 4, 5 that is 6 ÷ √(10 × 6) = 0.7746.
How do you find the p-value for a correlation?
Convert r to t = r√(n − 2) ÷ √(1 − r²) and look it up in the t distribution with n − 2 degrees of freedom, doubling the one-tail area for a two-tailed test. For Anscombe’s first dataset, r = 0.8164 with n = 11 gives t = 4.2415 on 9 df and p = 0.00217, the same as R’s cor.test.
What is a strong correlation coefficient?
One widely cited table (Schober, Boer and Schwarte, 2018) calls |r| below 0.10 negligible, 0.10–0.39 weak, 0.40–0.69 moderate, 0.70–0.89 strong and 0.90–1.00 very strong. The authors themselves call these cut-offs arbitrary, so judge r against what is normal in your field.
What is the difference between Pearson and Spearman correlation?
Pearson r measures how well the points fit a straight line and uses the raw values. Spearman ρ ranks each variable first and correlates the ranks, so it measures any steady upward or downward trend, straight or curved, and is less swayed by a single extreme value.
What does r squared mean?
r² is the share of the variation in one variable that a straight-line fit on the other accounts for. r = 0.7746 gives r² = 0.60, so the line accounts for 60% of the variance in y. It is never negative, so it loses the direction of the relationship.
Is a correlation of 0.77 significant?
It depends on the sample size. With 5 pairs, r = 0.7746 gives p = 0.124, not significant at 0.05, because with 3 degrees of freedom r has to reach 0.878. With 11 pairs the cut-off falls to 0.602, and with 30 pairs to 0.361.
Does correlation prove causation?
No. A correlation can come from a third variable that drives both, from reverse causation, or from chance in a small sample. A significant r only says the linear association is unlikely to be zero in the population the data came from.
References & Further Reading
- Wikipedia — Pearson correlation coefficient — Definition and the t = r√((n − 2)/(1 − r²)) test
- Wikipedia — Spearman’s rank correlation coefficient — Fractional ranks for ties, and the IQ vs TV worked example (ρ = −29/165, p = 0.627188) used as a preset
- Schober P, Boer C, Schwarte LA. Correlation Coefficients: Appropriate Use and Interpretation. Anesth Analg 2018;126(5):1763–1768 — Interpretation table and its caveats
- Duke University STA250 — Anscombe data sets — Data for sets I and II, with the regression output
- Stevison Lab R Mini-Course — Basic summary statistics in R — R cor.test output for Anscombe set I: t = 4.2415, df = 9, p = 0.00217, 95% CI 0.424 to 0.951