Skip to content

Linear Correlation Calculator

Calculate linear correlation with instant, accurate results and clear step-by-step output.

By CalcGenius Editorial TeamLast reviewed August 28, 20253 min read
Linear Correlation Calculator — Pearson r and Regression Line

Enter paired X and Y data of the same length (at least 3 pairs). The calculator returns the Pearson correlation coefficient r, the coefficient of determination r², and the least-squares regression line y = a + b·x.

📊
Enter your values and click Calculate

About

The Pearson correlation coefficient r measures the strength and direction of the linear relationship between two continuous variables X and Y. It ranges from −1 (perfect negative linear correlation) through 0 (no linear correlation) to +1 (perfect positive linear correlation). The formula is r = Σ((xᵢ − x̄)(yᵢ − ȳ)) / sqrt(Σ(xᵢ − x̄)² · Σ(yᵢ − ȳ)²) — the covariance of X and Y divided by the product of their standard deviations. Karl Pearson introduced the coefficient in 1895, building on Francis Galton's 1880s work on regression to the mean.

The coefficient of determination r² is the square of r and ranges from 0 to 1. It is the fraction of the variance in Y explained by the linear relationship with X. For r = 0.8, r² = 0.64 — 64% of the variance in Y is explained by X. The sign of r tells you the direction (positive when X and Y move together, negative when they move oppositely); r² tells you the strength. Always report both: use r² when you want to communicate "explained variance" and r when you want to communicate "direction and strength".

The least-squares regression line y = a + b·x is the straight line that minimises the sum of squared residuals Σ(yᵢ − ŷᵢ)². The slope is b = r · (σ_y / σ_x) and the intercept is a = ȳ − b·x̄. The line passes through the centroid (x̄, ȳ) of the data. The slope b is the predicted change in Y for a one-unit change in X; the intercept a is the predicted Y when X = 0 — often extrapolated outside the observed range of X, where the prediction may be unreliable. Always report the slope and intercept together with r² so readers know how much of the variation the line captures.

Correlation does not imply causation. A high r only means the two variables move together linearly; the relationship could be causal, could be due to a third confounding variable, or could be entirely spurious. Classic spurious correlations include ice-cream sales and drowning deaths (both driven by summer weather), shoe size and reading ability in children (both driven by age), and many coincidental alignments. To establish causation you need a controlled experiment, instrumental variables, or a quasi-experimental design with careful confounder control.

Pearson r assumes the relationship is linear, both variables are continuous and approximately normal, the data are independent, and the variance of Y is constant across X (homoscedasticity). Always plot the scatter before trusting r. Anscombe's famous 1973 quartet shows four data sets with identical r ≈ 0.82, identical regression lines, and identical summary statistics — but wildly different shapes: one linear, one non-linear, one with a single outlier dominating the fit, one with no real relationship at all. For non-linear monotone relationships use Spearman's rank correlation; for categorical or ordinal data use Kendall's tau. Report r with n and a confidence interval; the t-statistic t = r·sqrt((n−2)/(1−r²)) on n−2 degrees of freedom tests the null H₀: ρ = 0.

How to Use

  1. 1
    Enter your X data set
    Type a comma-separated list of numbers for the X variable. Decimals and negatives are accepted. The two data sets must have the same length (paired observations).
  2. 2
    Enter your Y data set
    Type a comma-separated list of numbers for the Y variable, in the same order as X. Each (xᵢ, yᵢ) pair is one observation. The lengths must match.
  3. 3
    Read the Pearson r and r²
    The hero block shows r (with sign for direction) and r² (explained variance). Below it the calculator reports the regression line y = a + b·x, the slope and intercept, and the standard error of r.
  4. 4
    Inspect the regression line
    The slope b = r·(σ_y/σ_x) is the predicted change in Y for a one-unit change in X. The intercept a = ȳ − b·x̄ is the predicted Y at X = 0. The line passes through (x̄, ȳ).
  5. 5
    Check the t-statistic for significance
    The t-statistic t = r·sqrt((n−2)/(1−r²)) with n−2 degrees of freedom tests H₀: ρ = 0. Compare to a t-distribution critical value; |t| > ~2 is significant at p < 0.05 for moderate n.
  6. 6
    Always plot the scatter before trusting r
    Anscombe's quartet shows four data sets with identical r ≈ 0.82 but wildly different shapes. A scatter plot reveals non-linearity, outliers, and heteroscedasticity that r alone hides. The calculator reports the summary statistics; the plot is left to your favourite plotting tool.

Formula

Pearson correlation coefficient:

r = Σ((xᵢ − x̄)(yᵢ − ȳ)) / sqrt[ Σ(xᵢ − x̄)² · Σ(yᵢ − ȳ)² ]

Equivalent z-score form:

r = (1/(n−1)) · Σ(z_x · z_y)

Coefficient of determination:

r² = r × r   (fraction of Y variance explained)

Regression line y = a + b·x:

b = r · (σ_y / σ_x) = Σ((xᵢ−x̄)(yᵢ−ȳ)) / Σ(xᵢ−x̄)²
a = ȳ − b · x̄

t-statistic (tests H₀: ρ = 0):

t = r · sqrt[ (n−2) / (1 − r²) ]   df = n − 2

Interpretation:

  • r ≈ +1  →  perfect positive linear
  • r ≈ 0  →  no linear correlation
  • r ≈ −1  →  perfect negative linear
  • |r| > 0.7 strong, 0.3–0.7 moderate, < 0.3 weak

Worked Example

Sample data with n = 8 pairs:

X = 1, 2, 3, 4, 5, 6, 7, 8
Y = 2.1, 3.9, 6.1, 7.8, 10.2, 11.9, 14.1, 16.0

  • x̄ = 4.5, ȳ = 9.0125.
  • Σ(x−x̄)² = 42, Σ(y−ȳ)² ≈ 167.0, Σ(x−x̄)(y−ȳ) ≈ 83.86.
  • r = 83.86 / sqrt(42 × 167.0) ≈ 83.86 / 83.86 ≈ 0.9998.
  • r² ≈ 0.9996 — 99.96% of the variance in Y is explained by X.
  • b = 83.86 / 42 ≈ 1.997, a = 9.0125 − 1.997 × 4.5 ≈ 0.026.
  • Regression line: y = 0.026 + 1.997·x — a near-perfect fit through (1, 2), (2, 4), …, (8, 16).
  • t = 0.9998 × sqrt(6 / 0.0004) ≈ 122 — overwhelmingly significant.

Sanity check: the data was generated from y ≈ 2x + 0 with small noise, so the recovered slope and intercept are essentially perfect.

Tips

  • Always plot the scatter before reporting r. Anscombe&apos;s quartet shows four data sets with identical r ≈ 0.82 but wildly different shapes — non-linear, outlier-driven, heteroscedastic.
  • Report r with n and a confidence interval. At n = 5 the 95% CI for r spans more than ±0.8 even for true correlations near zero; small samples give noisy estimates.
  • Test the null hypothesis H₀: ρ = 0 with the t-statistic t = r·sqrt((n−2)/(1−r²)) on n−2 degrees of freedom. |t| &gt; ~2 is significant at p &lt; 0.05 for moderate n.
  • Switch to Spearman&apos;s rank correlation when the relationship is non-linear monotone, when the data is heavily skewed, or when outliers dominate Pearson r. Spearman ranks the data first, making it robust to outliers.
  • Watch the sign of the slope. b = r·(σ_y/σ_x) inherits the sign of r; a positive r means positive slope (Y increases with X), a negative r means negative slope. The intercept alone is often meaningless if X = 0 is outside the data range.

Common Mistakes

Common mistakes
  • Reporting r without n. A correlation of 0.8 from n = 5 is wildly less reliable than 0.8 from n = 100.
  • Inferring causation. Correlation is necessary but not sufficient for causation; spurious correlations abound.
  • Trusting r without plotting. Anscombe's quartet shows four data sets with identical r ≈ 0.82 but wildly different shapes.
  • Extrapolating the regression line outside the X range. The intercept a is the predicted Y at X = 0, often outside the data; interpret with caution.
  • Using Pearson r for non-linear monotone data. Switch to Spearman's rank correlation when the relationship is non-linear but monotone.

Frequently Asked Questions

What is the Pearson correlation coefficient r?
The Pearson correlation coefficient r measures the strength and direction of the linear relationship between two continuous variables X and Y. It ranges from −1 (perfect negative linear correlation) through 0 (no linear correlation) to +1 (perfect positive linear correlation). The formula is r = Σ((xᵢ − x̄)(yᵢ − ȳ)) / sqrt(Σ(xᵢ − x̄)² · Σ(yᵢ − ȳ)²) — the covariance of X and Y divided by the product of their standard deviations. The coefficient was introduced by Karl Pearson in 1895, building on Francis Galton&apos;s 1880s work on regression to the mean.
What is the difference between r and r²?
r is the correlation coefficient itself (range −1 to +1, signed); r² is the coefficient of determination (range 0 to 1, unsigned). r² is the fraction of the variance in Y that is explained by the linear relationship with X. For example, r = 0.8 gives r² = 0.64, meaning 64% of the variance in Y is explained by X. The sign of r tells you the direction of the relationship; r² tells you the strength. Both are reported here — use r² when you want to communicate &quot;explained variance&quot; and r when you want to communicate &quot;direction and strength&quot;.
What is the regression line?
The least-squares regression line is the straight line y = a + b·x that minimises the sum of squared residuals Σ(yᵢ − ŷᵢ)². The slope is b = r · (σ_y / σ_x) and the intercept is a = ȳ − b·x̄. The line passes through the centroid (x̄, ȳ) of the data. The slope b is the predicted change in Y for a one-unit change in X; the intercept a is the predicted Y when X = 0. The regression line is the best linear predictor of Y from X in the least-squares sense, but it is only valid within the observed range of X — extrapolation is risky.
How many data points do I need for a reliable correlation?
At least 3 (the formula has n−2 in the t-statistic denominator), but you should aim for at least 30 for a defensible correlation. Small samples give noisy r values: at n = 5 the 95% confidence interval for r spans more than ±0.8 even for true correlations near zero. Always report r with n and a confidence interval; the t-statistic t = r·sqrt((n−2)/(1−r²)) with n−2 degrees of freedom tests the null hypothesis H₀: ρ = 0.
Does a high r mean causation?
No. Correlation does not imply causation. A high r only means the two variables move together linearly; the relationship could be causal, could be due to a third confounding variable, or could be entirely spurious. Classic spurious correlations include ice-cream sales and drowning deaths (both driven by summer weather), shoe size and reading ability in children (both driven by age), and the number of Nicolas Cage films and swimming-pool drownings (purely coincidental). To establish causation you need a controlled experiment or a quasi-experimental design with careful confounder control.
What are the assumptions of Pearson correlation?
Pearson r assumes (1) the relationship is linear — non-linear monotone relationships are better captured by Spearman&apos;s rank correlation; (2) both variables are continuous and approximately normally distributed — heavily skewed or outlier-laden data distort r; (3) the data are independent — paired or repeated-measures data need a different analysis; (4) the variance of Y is constant across X (homoscedasticity) — fan-shaped scatter violates this. Always plot the data before reporting r; Anscombe&apos;s famous quartet shows four data sets with identical r ≈ 0.82 but very different shapes.

Covariance and standardisation

Pearson r is the covariance of X and Y divided by the product of their standard deviations: r = cov(X, Y) / (σ_x · σ_y). Equivalently, it is the average product of the z-scores: r = Σ(z_x · z_y) / (n−1). Standardising by σ removes the units and bounds r to [−1, +1]. The sign of r comes from the sign of the covariance — positive when X and Y move together, negative when they move oppositely.

The regression line y = a + b·x

The least-squares regression line minimises the sum of squared residuals Σ(yᵢ − ŷᵢ)². The slope is b = r · (σ_y / σ_x) and the intercept is a = ȳ − b·x̄. The line passes through the centroid (x̄, ȳ) of the data. The slope is the predicted change in Y for a one-unit change in X; the intercept is the predicted Y at X = 0 (often extrapolated outside the data range — interpret with caution).

r² — coefficient of determination

r² (the coefficient of determination) is the fraction of the variance in Y explained by the linear relationship with X. It ranges from 0 to 1 and is the square of r. For r = 0.8, r² = 0.64 — meaning 64% of the variance in Y is explained by X. Use r² to communicate "explained variance" and r to communicate "direction and strength". Always report r² alongside the regression equation so readers know how much of the variation the line captures.

Correlation ≠ causation

A high r only means the two variables move together linearly. It does not establish that one causes the other. Classic spurious correlations include ice-cream sales and drowning deaths (both driven by summer weather), shoe size and reading ability in children (both driven by age), and many coincidental alignments. To establish causation you need a controlled experiment, instrumental variables, or a quasi-experimental design with careful confounder control.

Reference values of r for the strength and direction of a linear relationship. The corresponding r² shows the explained variance.
r valueStrengthWhat it looks liker²
r = 1.0Perfect positiveAll points on a line of positive sloper² = 1.00
r = 0.9Strong positiveTight linear cloud, positive sloper² = 0.81
r = 0.5Moderate positiveLoose upward cloudr² = 0.25
r = 0.0No correlationRandom scatter or non-linear patternr² = 0.00
r = −0.5Moderate negativeLoose downward cloudr² = 0.25
r = −0.9Strong negativeTight linear cloud, negative sloper² = 0.81
r = −1.0Perfect negativeAll points on a line of negative sloper² = 1.00
r vs r² — when to use which
Report r when you want to communicate the direction (sign) and strength of the linear relationship; report r² when you want to communicate the fraction of variance explained. A correlation of r = 0.7 sounds impressive, but r² = 0.49 means less than half the variance is explained — and the regression predictions will be noisy. Always pair the two so readers understand both the direction and the predictive power.
Correlation does not imply causation
A high r only means the two variables move together linearly. Ice-cream sales correlate with drowning deaths because both peak in summer, not because eating ice-cream causes drowning. To establish causation you need a controlled experiment, an instrumental variable, or a natural experiment — never a correlation alone.
Always plot the scatter first
Anscombe's quartet shows four data sets with identical r ≈ 0.82, identical regression lines, and identical summary statistics — but wildly different shapes. A scatter plot reveals non-linearity, outliers, and heteroscedasticity that r alone hides. The calculator returns the summary statistics; the plot is left to your favourite plotting tool.

Authoritative References

Try our other free calculators

CalcGenius has 1,200+ free, ad-free, browser-based calculators for finance, health, math, science, and everyday life. No sign-up required.

Linear Correlation Calculator for Scientists, Analysts