Correlation Coefficient Calculator
Paste two columns, x and y. You get Pearson r, Spearman ρ, the p-value and a scatter plot with the best-fit line.
https://flxcode.com/correlation-coefficient-calculator/
One pair per line, x then y, separated by a tab, space, comma or semicolon. Paste two columns straight from a spreadsheet. A header row is ignored.
Example Correlation
Pearson correlation (r)
Read 7 pairs. Ignored the header "Hours Score".
Very strong positive straight-line relationship (a rough rule of thumb).
With fewer than 10 pairs, r can be large by chance.
Correlation is not causation. It also only measures straight-line relationships.
| Pairs (n) | 7 |
|---|---|
| Pearson r | 0.977266 |
| r² (share of y explained by x) | 0.955048 |
| Spearman ρ (rank correlation) | 0.964286 |
| p-value for r (two-tailed, df = n − 2) | 0.000147862 |
| p-value for ρ (t approximation) | 0.000454149 |
| Best-fit line | y = 46.7143 + 5.14286 × x |
The steps, with your numbers
Means: x̄ = 4, ȳ = 67.2857
Σ(x − x̄)(y − ȳ) = 144, Σ(x − x̄)² = 28, Σ(y − ȳ)² = 775.429
r = Σ(x − x̄)(y − ȳ) / √(Σ(x − x̄)² × Σ(y − ȳ)²) = 144 / √(28 × 775.429) = 0.977266
Slope b = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)² = 144 / 28 = 5.14286
Intercept a = ȳ − b × x̄ = 67.2857 − 5.14286 × 4 = 46.7143
No ads. No account. Nothing you type or record is uploaded. We count page events with a daily code. Check it.
Problem or idea? Email us
Quick start
- Select two columns in your spreadsheet and copy them.
- Paste them in the box. Each line is one pair, x then y.
- Read r, r² and ρ. The plot shows the points and the best-fit line.
The formula
r = Σ(x − x̄)(y − ȳ) / √( Σ(x − x̄)² × Σ(y − ȳ)² )
The line of best fit is y = a + b × x, where b = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)² and a = ȳ − b × x̄. Spearman's ρ uses the same formula on ranks, with tied values given the average of their ranks.
Worked examples
| Pairs (x y) | r | ρ | p for r | Note |
|---|---|---|---|---|
| 1 2 · 2 4 · 3 5 · 4 4 · 5 5 | 0.774597 | 0.737865 | 0.124027 | x = 1 to 5 and y = 2, 4, 5, 4, 5. A common textbook set. |
| 1 10 · 2 8 · 3 7 · 4 5 · 5 2 | -0.985104 | -1 | 0.00217751 | y falls as x rises. |
| 1 3 · 2 9 · 3 4 · 4 8 · 5 5 · 6 6 | 0.161515 | 0.257143 | 0.759835 | No clear pattern. |
| 1 1 · 2 4 · 3 9 · 4 16 · 5 25 | 0.981105 | 1 | 0.00310901 | y = x², a curve that always rises. |
The curve in the last row is a perfect pattern but r is only 0.9811, because it is not a straight line. Spearman's ρ is exactly 1 since y always rises with x.
How strong is r
| |r| | Rough label |
|---|---|
| 0.9 to 1 | Very strong |
| 0.7 to 0.9 | Strong |
| 0.4 to 0.7 | Moderate |
| 0.2 to 0.4 | Weak |
| below 0.2 | Very weak or none |
These labels are a convention, not a law. What counts as strong depends on the field. Always look at the plot too: the same r can come from very different shapes. To judge whether r could be chance, use the p-value calculator with a t statistic.
Numbers this uses
Every constant the tool uses is listed here with its source. Where a number varies, you can edit it in the tool.
- p-value is two-tailed t-test with n − 2 degrees of freedom. Needs 3 or more pairs. For Spearman it is the same t approximation, which is fine from about 10 pairs.
- Plot is up to 2,000 points drawn. The numbers always use every pair.
- Limit is 100,000 pairs. For speed in the browser.
Common mistakes
- Skipping the plot. Outliers and curves can fool r.
- Pairing the wrong rows after sorting one column. Sort both columns together.
- Treating a high r as cause and effect.
Nothing you type or paste is uploaded. We count events without cookies (details).
FAQ
What is the correlation coefficient?
Pearson r measures how close the points lie to a straight line, from −1 to 1. Plus 1 is a perfect rising line, −1 a perfect falling line and 0 no straight-line link. For the study hours and scores in the tool r is 0.977266.
How do I enter my data?
Paste two columns from a spreadsheet, x then y, one pair per line. A header row is ignored. You can also type pairs separated by a space, comma or semicolon. Rows with only one number are skipped and counted.
What is r squared?
It is r multiplied by itself, the share of the variation in y that a straight line on x accounts for. With r = 0.9773, r² is 0.955, so about 95.5% of the variation in scores goes along with study hours.
What is Spearman's rho and when should I use it?
Spearman ρ is Pearson r on the ranks of the values. It catches any steadily rising or falling relationship, not just straight lines, and is less affected by outliers. For y = x² on 1 to 5, r is 0.9811 but ρ is 1.
How do I read the p-value?
It tests the null hypothesis that the true correlation is 0, using t = r × √((n − 2) / (1 − r²)) with n − 2 degrees of freedom. For the hours data it is 0.000147862. A small p means the link is unlikely to be chance, but says nothing about how strong or useful it is.
Does a high correlation mean one thing causes the other?
No. Two things can move together because of a third, because of chance, or because the cause runs the other way. A correlation is a reason to look closer, not a proof of cause.
What are the Excel and Google Sheets formulas?
=CORREL(A1:A10,B1:B10) or =PEARSON(A1:A10,B1:B10) for r, =RSQ for r squared, and =SLOPE and =INTERCEPT for the best-fit line. For Spearman, rank both columns with RANK.AVG first and run CORREL on the ranks.
Is my data uploaded?
No. Both columns stay in your browser. They are not stored, not put in the address bar and not sent.
More from FLXCode
P-Value CalculatorNew
p-value from a z, t, chi-square or F statistic, one or two tailed, with the tails shown.
Variance CalculatorNew
Variance of a list of numbers, sample or population, with the sum of squares and the steps.
Z-Score CalculatorNew
z-score from a value, mean and standard deviation, or from data, with percentile and p-values.
Standard Deviation CalculatorNew
Paste your numbers and get the sample and population standard deviation, with the steps shown.