FLXCode Correlation Coefficient Calculator

FLXCode apps

Appearance

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.

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

0.977266 Pearson correlation (r)

Read 7 pairs. Ignored the header "Hours Score".

Scatter plot of 7 points with the best-fit line, r = 0.977

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.

Results
Pairs (n)7
Pearson r0.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 liney = 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

  1. Select two columns in your spreadsheet and copy them.
  2. Paste them in the box. Each line is one pair, x then y.
  3. 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 rNote
1 2 · 2 4 · 3 5 · 4 4 · 5 50.7745970.7378650.124027x = 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-10.00217751y falls as x rises.
1 3 · 2 9 · 3 4 · 4 8 · 5 5 · 6 60.1615150.2571430.759835No clear pattern.
1 1 · 2 4 · 3 9 · 4 16 · 5 250.98110510.00310901y = 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 1Very strong
0.7 to 0.9Strong
0.4 to 0.7Moderate
0.2 to 0.4Weak
below 0.2Very 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

Share Correlation Coefficient Calculator