Skip to content
induwara.lk
Premium
induwara.lkStatistics · Data science

Pearson Correlation Coefficient Calculator

Paste two columns of numbers and get the Pearson correlation r, r², covariance, a significance test (t-statistic and two-tailed p-value), and a scatter plot with the full step-by-step working. Matched to scipy.stats.pearsonr, runs entirely in your browser — no signup, nothing uploaded.

By Induwara AshinsanaUpdated Aug 20, 2026
Pearson correlation calculator

Numbers separated by commas, spaces, or new lines. Paste two Excel columns here to fill both.

Must have the same count as X — each X needs a matching Y.

Examples
Covariance / SD
Decimals
Pearson r
-0.9948
Range −1 to 1 · n = 5
r² (determination)
0.9897
99.0% of variance explained
Covariance
-4.2500
Sxy / (n−1)
Strength
Very strong negative

Scatter plot

with least-squares trend line (y = -1.700x + 11.700)
XY0.765.242.5810.42(1.0000, 10.0000)(2.0000, 8.0000)(3.0000, 7.0000)(4.0000, 5.0000)(5.0000, 3.0000)

Significance test

t-statistic
-17.0000
Degrees of freedom
3
p-value (two-tailed)
0.0004
At α = 0.05Significant

Cross-check. The deviation-score formula gives r = -0.9948; the independent raw-score formula [n·Σxy − ΣxΣy] / √(…) gives -0.9948. They reconcile, as they must — and both match scipy.stats.pearsonr.

Step-by-step working

#xᵢyᵢxᵢ−x̄yᵢ−ȳ(xᵢ−x̄)(yᵢ−ȳ)(xᵢ−x̄)²(yᵢ−ȳ)²
11.000010.0000-2.00003.4000-6.80004.000011.5600
22.00008.0000-1.00001.4000-1.40001.00001.9600
33.00007.00000.00000.40000.00000.00000.1600
44.00005.00001.0000-1.6000-1.60001.00002.5600
55.00003.00002.0000-3.6000-7.20004.000012.9600
Σ15.000033.0000-17.000010.000029.2000
x̄ = 15.0000 / 5 = 3.0000 · ȳ = 33.0000 / 5 = 6.6000
SD(X) = 1.5811 · SD(Y) = 2.7019 (sample)
r = -17.0000 / √(10.0000 × 29.2000) = -0.9948

Method: r = Σ(xᵢ−x̄)(yᵢ−ȳ) / √(Σ(xᵢ−x̄)²·Σ(yᵢ−ȳ)²); significance via t = r√(n−2)/√(1−r²) with df = n−2 — NIST e-Handbook §1.3.5.13, matched to scipy.stats.pearsonr. Nothing leaves this page.

How it works

The Pearson product-moment correlation coefficient r measures the strength and direction of the linear relationship between two paired variables. It runs from −1 (a perfect decreasing line), through 0 (no linear association), to +1 (a perfect increasing line). The definition is the one in the NIST/SEMATECH e-Handbook of Statistical Methods §1.3.5.13.

For n paired observations, with means x̄ = (Σxᵢ)/n and ȳ = (Σyᵢ)/n, the coefficient is the sum of cross-products of the deviations divided by the root of the product of the squared deviations:

r = Σ(xᵢ−x̄)(yᵢ−ȳ) / √( Σ(xᵢ−x̄)² · Σ(yᵢ−ȳ)² ) = Sxy / √(Sxx · Syy)

The tool computes this in four steps:

  1. Means and deviations. It averages each column, then subtracts the mean from every value to get the deviations (xᵢ−x̄) and (yᵢ−ȳ).
  2. Sums. It accumulates Sxy, Sxx, and Syy from the deviation table. If Sxx or Syy is zero — a constant column — r is undefined, so the tool shows a clear message instead of a divide-by-zero.
  3. r and r². The correlation is Sxy / √(Sxx·Syy), and r² (the coefficient of determination) is r squared — the share of variance in one variable explained by a linear fit on the other. Covariance is Sxy/(n−1) for a sample (or Sxy/n for a whole population); r itself is unaffected by that choice.
  4. Significance. Under the null hypothesis that the true correlation is zero, t = r√(n−2)/√(1−r²) follows a Student-t distribution with df = n−2. The two-tailed p-value is the regularized incomplete beta function I_x(df/2, 1/2) at x = df/(df+t²), the exact identity SciPy uses.

What each number on screen actually tells you

r is the headline: direction from its sign, strength from its size. converts that into a share of variance — the same quantity a simple linear regression reports as its goodness of fit, which is why fitting a straight line through the same two columns in the linear regression calculator returns exactly this r². Covariance is the unscaled version of the same cross-product sum: it carries the units of X times the units of Y, so it tells you the direction but not the strength. Dividing covariance by the two standard deviations is what strips the units out and forces the result into [−1, 1] — so r is nothing more than a standardised covariance. If you want the means, standard deviations, and quartiles of either column on their own, the descriptive statistics calculator takes the same paste-a-column input.

Reading the strength label

The tool labels |r| using the convention most textbooks and the NIST handbook share: 0.00–0.19 negligible, 0.20–0.39 weak, 0.40–0.59 moderate, 0.60–0.79 strong, 0.80–0.99 very strong, and 1.00 perfect. These bands are a reading aid, not a rule. A correlation of 0.30 between a screening test and an outcome can matter a great deal in a public-health dataset of 10,000 people, while 0.85 across six points can be noise. Judge the label, the p-value, the sample size, and the scatter plot together — never one alone.

Assumptions, and the edge cases that break them

Pearson's r is only meaningful when four conditions roughly hold: both variables are continuous, the pairing is genuine (row i of X belongs with row i of Y), the underlying relationship is linear, and the observations are independent of each other. The p-value adds a fifth: approximate bivariate normality. Here is how this tool behaves when those conditions are pushed:

  • A constant column.If every X is 5, then Sxx = 0 and r is 0/0 — genuinely undefined, not zero. The tool reports “one variable has zero variance” rather than printing NaN.
  • Fewer than three pairs. Two points always sit on a perfect line, so r = ±1 with no information in it, and df = n−2 = 0 leaves no t-test. The minimum here is three pairs.
  • A perfect fit. When r is exactly ±1, 1−r² = 0 and t is infinite. Instead of dividing by zero the tool reports the perfect correlation and suppresses the t-statistic.
  • A curved relationship. r can be exactly 0 while Y is perfectly determined by X — the parabola in worked example 5 below. Pearson only sees straight lines.
  • One outlier. A single distant pair can flip r from −1 to +0.92, as worked example 6 shows. Deviations are squared, so far-from-mean points dominate every sum.
  • Mismatched column lengths. Pearson needs pairs, so 5 X values against 4 Y values is an error naming both counts, not a silent truncation.

When the linearity or outlier check fails, the fix is usually a rank method rather than a transformation: the Spearman rank correlation calculator correlates ranks instead of values and handles any monotonic curve, and the Kendall's tau calculator is steadier again on small samples with tied ranks. For two categorical variables neither applies — that is Cramér's V territory.

The raw-score formula, and why both routes give the same r

Most A/L and first-year formula sheets print r in a different shape from the deviation formula above — the raw-score (or computational) form:

r = [nΣxy − ΣxΣy] / √( [nΣx² − (Σx)²] · [nΣy² − (Σy)²] )

It needs five running totals — Σx, Σy, Σxy, Σx², Σy² — and never asks you to hold a table of deviations, which is exactly why it is the form wired into scientific calculators and the one that was practical before spreadsheets existed. The two forms are algebraically identical: expanding Σ(xᵢ−x̄)(yᵢ−ȳ) gives Σxy − nx̄ȳ, and multiplying through by n turns that into nΣxy − ΣxΣy. The numerator and both terms under the root pick up the same factor of n, so it cancels and r is unchanged. Worked example 7 below runs the same dataset both ways and lands on the same 0.7746.

They are not equally well behaved in floating point, though. The deviation form is easier to debug because you can see which pair contributed what. The raw-score form is faster and needs less memory, but it subtracts two large, nearly equal numbers, so on badly scaled data — values in the millions with a spread of a few units — it loses precision. This tool computes r the deviation way and then recomputes it the raw-score way as a cross-check, which is why a disagreement between the two is worth knowing about rather than hiding.

What this page does not report: a confidence interval on r

r is a point estimate, and the p-value only answers one narrow question — could the true correlation plausibly be zero? It says nothing about how precisely r has been pinned down. The standard way to put an interval around r is Fisher's z transformation: take z = ½·ln((1+r)/(1−r)), whose standard error is 1/√(n−3), add and subtract 1.96 standard errors for a 95% interval in z, then transform each endpoint back with r = (e^2z − 1)/(e^2z + 1).

Run that on worked example 4 — r = 0.9368 from six students — and the 95% interval stretches from roughly 0.52 to 0.99. The honest reading of that dataset is “positive, probably strong, but six points cannot pin it down,” which is a much weaker claim than r = 0.94 alone suggests. This page reports r, r², the t-statistic and the p-value; R's cor.test() prints the Fisher interval directly, and the confidence interval calculator here covers the mean and proportion cases. Small-sample studies far more often get the width of that interval wrong than the size of r, so plan n before collecting rather than after — the statistical power calculator is the tool for that half of the problem.

Sample or population, and why r does not care

The covariance and standard deviations shown alongside r depend on the delta degrees of freedom you pick: dividing by n−1 gives the sample statistics used for inference, dividing by n gives the population values. r itself is identical either way, because the same divisor appears in the numerator and in both terms under the root and cancels out. That is a useful sanity check when your output disagrees with a classmate's: if the covariances differ but the r values match, the only difference is the ddof setting, not an arithmetic error.

As a credibility check the calculator also recomputes r a second way — the raw-score formula [n·Σxy − ΣxΣy] / √(…) — and confirms both routes agree to floating-point precision, matching scipy.stats.pearsonr. A strong r is evidence of association, never of causation on its own.

Worked examples

Seven datasets, each computed by hand below and then reconciled against this tool and against scipy.stats.pearsonr to at least four decimal places. Examples 5 and 6 are the edge cases that catch people out; example 7 re-runs the first dataset through the formula-sheet route to show the two agree.

1. Classic positive — X = [1, 2, 3, 4, 5], Y = [2, 4, 5, 4, 5]

  1. Means: x̄ = 15/5 = 3, ȳ = 20/5 = 4
  2. Sxy = (−2)(−2)+(−1)(0)+(0)(1)+(1)(0)+(2)(1) = 4+0+0+0+2 = 6
  3. Sxx = 4+1+0+1+4 = 10; Syy = 4+0+1+0+1 = 6
  4. r = 6 / √(10·6) = 6/√60 = 0.7746; r² = 0.6000 (60% of variance)
  5. t = 0.7746·√3/√0.4 = 2.1213, df = 3, p = 0.1240 → not significant at α=0.05

2. Strong negative — study hours X = [1, 2, 3, 4, 5] vs exam errors Y = [10, 8, 7, 5, 3]

  1. Means: x̄ = 3, ȳ = 33/5 = 6.6
  2. Deviations y: 3.4, 1.4, 0.4, −1.6, −3.6
  3. Sxy = −6.8−1.4+0−1.6−7.2 = −17; Sxx = 10; Syy = 29.2
  4. r = −17 / √(10·29.2) = −17/√292 = −0.9948; r² = 0.9897
  5. t = −17.0000, df = 3, p = 0.000443 → significant: more study, fewer errors

3. Weak, not significant — X = [−2, −1, 0, 1, 2], Y = [0.5, 0.2, 0.0, 0.3, 0.9]

  1. Means: x̄ = 0, ȳ = 1.9/5 = 0.38
  2. Sxy = (−2)(0.12)+(−1)(−0.18)+0+(1)(−0.08)+(2)(0.52) = 0.90
  3. Sxx = 10; Syy = 0.468
  4. r = 0.90 / √(10·0.468) = 0.90/√4.68 = 0.4160; r² = 0.1731
  5. t = 0.7924, df = 3, p = 0.4860 → a weak hint, not significant at α=0.05

4. Real-world — A/L Z-score vs first-year GPA for six students

  1. X (Z-score) = [1.0, 1.2, 1.4, 1.6, 1.8, 2.0]; Y (GPA) = [2.6, 3.0, 2.9, 3.4, 3.3, 3.7]
  2. Means: x̄ = 9.0/6 = 1.50, ȳ = 18.9/6 = 3.15
  3. dx = −0.5, −0.3, −0.1, 0.1, 0.3, 0.5; dy = −0.55, −0.15, −0.25, 0.25, 0.15, 0.55
  4. Sxy = 0.275+0.045+0.025+0.025+0.045+0.275 = 0.690
  5. Sxx = 0.25+0.09+0.01+0.01+0.09+0.25 = 0.700; Syy = 0.775
  6. r = 0.690 / √(0.700·0.775) = 0.690/0.736546 = 0.9368; r² = 0.8776
  7. t = 5.3554, df = 4, p = 0.005864 → significant: higher Z-score, higher GPA
  8. Least-squares line: GPA ≈ 1.6714 + 0.9857 · Z — but six students is a class, not a cohort

5. Edge case — a perfect curve that r reports as zero

  1. X = [−2, −1, 0, 1, 2]; Y = [4, 1, 0, 1, 4] — exactly Y = X², no noise at all
  2. Means: x̄ = 0, ȳ = 10/5 = 2. dy = 2, −1, −2, −1, 2
  3. Sxy = (−2)(2)+(−1)(−1)+(0)(−2)+(1)(−1)+(2)(2) = −4+1+0−1+4 = 0
  4. Sxx = 10; Syy = 4+1+4+1+4 = 14
  5. r = 0 / √140 = 0.0000; r² = 0.0000; t = 0, df = 3, p = 1.0000
  6. Verdict: 'no linear correlation' — yet Y is perfectly determined by X. The symmetry cancels every cross-product. Plot before you report.

6. Edge case — one outlier reverses the sign

  1. Baseline X = [1,2,3,4,5], Y = [5,4,3,2,1]: Sxy = −10, Sxx = Syy = 10 → r = −1.0000 exactly
  2. Now append the single pair (20, 20): X = [1,2,3,4,5,20], Y = [5,4,3,2,1,20]
  3. Means shift to x̄ = ȳ = 35/6 = 5.8333; the new pair has dx = dy = 14.1667
  4. That one point contributes 14.1667² = 200.69 to Sxy — against 30.14 from the other five combined
  5. Sxy = 230.8333; Sxx = Syy = 250.8333 → r = 230.8333/250.8333 = +0.9203; r² = 0.8469
  6. t = 4.7037, df = 4, p = 0.009283 → 'very strong positive', and significant
  7. One pair in six turned a perfect negative into a significant positive. Squared deviations give distant points enormous leverage.

7. Cross-check — the same data through the raw-score formula

  1. X = [1, 2, 3, 4, 5], Y = [2, 4, 5, 4, 5] again — no deviation table this time, just five totals
  2. Σx = 15; Σy = 20; Σxy = 2+8+15+16+25 = 66; Σx² = 55; Σy² = 86; n = 5
  3. Numerator: nΣxy − ΣxΣy = 5(66) − 15(20) = 330 − 300 = 30
  4. Denominator: √(5·55 − 15²) · √(5·86 − 20²) = √(275−225) · √(430−400) = √50 · √30 = √1500 = 38.7298
  5. r = 30 / 38.7298 = 0.7746 — identical to example 1 at every decimal place
  6. Why: 30/5 = 6 = Sxy, 50/5 = 10 = Sxx, 30/5 = 6 = Syy. Every term carries the same factor of n, and it cancels.

Frequently asked questions

Sources & references

The formulas on this page were last cross-checked against these sources on 2026-08-20. Pearson's r is a stable mathematical definition, so this tool needs no rate or schedule updates — only the worked examples are periodically re-reconciled against SciPy.

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, edge case, or want to suggest an improvement?

Email me at [email protected] — most fixes ship within 24 hours.