Linear Correlation Calculator
Calculate linear correlation with instant, accurate results and clear step-by-step output.
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.
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
- 1Enter your X data setType 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).
- 2Enter your Y data setType 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.
- 3Read 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.
- 4Inspect the regression lineThe 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̄, ȳ).
- 5Check the t-statistic for significanceThe 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.
- 6Always plot the scatter before trusting rAnscombe'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'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| > ~2 is significant at p < 0.05 for moderate n.
- Switch to Spearman'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
- 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'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 "explained variance" and r when you want to communicate "direction and strength".
- 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'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'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.
| r value | Strength | What it looks like | r² |
|---|---|---|---|
| r = 1.0 | Perfect positive | All points on a line of positive slope | r² = 1.00 |
| r = 0.9 | Strong positive | Tight linear cloud, positive slope | r² = 0.81 |
| r = 0.5 | Moderate positive | Loose upward cloud | r² = 0.25 |
| r = 0.0 | No correlation | Random scatter or non-linear pattern | r² = 0.00 |
| r = −0.5 | Moderate negative | Loose downward cloud | r² = 0.25 |
| r = −0.9 | Strong negative | Tight linear cloud, negative slope | r² = 0.81 |
| r = −1.0 | Perfect negative | All points on a line of negative slope | r² = 1.00 |
Authoritative References
- Wikipedia — Pearson correlation coefficient— wikipedia.orgComprehensive overview of Pearson r, including the formula, the relationship with covariance and standard deviation, and Anscombe's quartet.
- Khan Academy — Correlation coefficient— khanacademy.orgKhan Academy video on calculating r and the regression line, with worked examples and the connection to r².
- Wolfram MathWorld — Correlation Coefficient— wolfram.comMathWorld entry with the formal definition, the relationship with covariance, and worked examples for paired data.
- NIST/SEMATECH e-Handbook — Linear Regression— nist.govThe NIST Engineering Statistics chapter on linear regression, with the formula for the slope, intercept, and r, plus worked engineering examples.
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.