Linear Regression & Correlation Calculator
Paste X,Y pairs, get linear regression equation (slope + intercept), Pearson correlation coefficient r, R² (variance explained), standard error, a scatter plot with fitted line, and a residual plot that shows where the line fails.
Linear Regression & Correlation Calculator
Residuals appear once a fitted line exists.
How to use the Linear Regression Calculator
Paste X,Y data pairs
One pair per line, separated by comma, tab, semicolon, or space. The parser is flexible: 1, 2.5 works; 1 2.5 works; 1; 2.5 works; pasting two columns from Excel / Google Sheets works (newlines + tab separator). Non-numeric lines are silently skipped. On sample size: two points always fit a line exactly, so n = 2 tells you nothing about how good the fit is — 3 pairs is the practical minimum, 10+ before a correlation is worth reading, 30+ for statistical inference. All the x values must not be identical: a vertical point cloud has no least-squares line in y.
Read the regression equation
The output equation y = mx + b describes the best-fit line through your data. m (slope): how much y changes per unit increase in x. Positive slope = positive relationship; negative = inverse. b (intercept): the predicted y when x = 0. The equation lets you predict y for any new x value by plugging it in. Always inspect the scatter plot to verify the linear fit is reasonable — non-linear relationships need non-linear models.
Interpret Pearson r and R²
Pearson r: correlation coefficient from -1 to +1. +1 = perfect positive linear relationship, -1 = perfect negative, 0 = no linear relationship. The labels this tool prints — |r| > 0.7 "strong", 0.4–0.7 "moderate", 0.2–0.4 "weak" — are conventional descriptions, not statistical thresholds; nothing changes at 0.7. R²: square of r — the fraction of variance in y explained by x. R² = 0.81 means 81% of y's variability is accounted for by x; the remaining 19% is unexplained scatter. For ordinary least squares with an intercept, R² on the sample the line was fitted to is bounded [0, 1]. That bound is narrower than it sounds: drop the intercept, fit a line chosen on other data, or apply the model out of sample, and R² can go negative — meaning the line is worse than simply predicting ȳ. A low |r| means no straight-line pattern, never "no pattern": check the scatter and residual plots.
Read the scatter plot — then the residual plot
The chart on the right shows your data points (purple dots) and the fitted regression line (red). Below it, the residual plot shows each point's vertical distance from that line (y − fitted) against x, with a dashed zero line. The residual plot is the more sensitive diagnostic, because it removes the trend and leaves only what the line failed to explain — patterns that are invisible in the scatter jump out here. Look for: outliers (one tall spike dominating the fit); non-linear patterns (residuals bending in a smile or arch — a curve the straight line is missing); heteroscedasticity (residuals fanning out as x increases, violating a regression assumption). Residuals scattered evenly around zero with no shape is what a well-specified linear model looks like. If the residual plot has structure, the regression numbers are misleading no matter how good R² looks — consider transforming the data (log, square root) or fitting a different model.
Linear regression — the simplest predictive model that still works
Linear regression is the simplest and most-used predictive model in all of statistics. The basic idea: given pairs of (x, y) data, find the straight line that best fits through them. "Best fit" is defined mathematically as minimising the sum of squared residuals — the vertical distances between each data point and the line. This "least squares" formulation, attributed to Carl Friedrich Gauss in 1795 (though Legendre published it first in 1805, sparking a famous priority dispute), produces a unique optimal line with closed-form formulas for slope and intercept. Despite being over 200 years old, it remains the workhorse of forecasting, A/B testing analysis, scientific research, and machine learning baselines. When someone says "let me run a quick regression," they almost always mean simple linear regression.
The relationship between r and R²
Pearson's correlation coefficient r measures the strength + direction of a linear relationship on a scale from -1 to +1. R² (coefficient of determination) equals r² — the same information squared. The interpretations differ: r is about direction + strength (sign tells you up vs down, magnitude tells you fit); R² is about variance explained (it answers "what fraction of y's variability is predictable from x?"). Examples: r = 0.9 means strong positive correlation; R² = 0.81 means x explains 81% of y's variance. r = -0.7 means moderate negative correlation; R² = 0.49 means x explains 49%. r = 0.3 means weak positive correlation; R² = 0.09 means only 9% explained. There is no universal figure at which R² becomes "good": what counts as acceptable depends entirely on the field, the noise floor of the measurement, and the question being asked — an R² that would be embarrassing in a physics lab can be a genuinely useful edge in a noisy market, and a high R² is worthless if the residual plot shows the model is systematically wrong. Judge the fit against a stated benchmark in your own domain, not against a number from a table.
Linear regression is 200+ years old, embarrassingly simple, and still the right tool 80% of the time. The other 20% needs more, but the linear baseline tells you what "more" needs to beat.
The "correlation does not imply causation" warning
The single most-violated rule in applied statistics: high r and R² values do NOT prove that x causes y. Two variables can be correlated because: (1) x truly causes y (the simplest case), (2) y causes x (reverse causation), (3) a third variable Z causes both x and y (confounding), or (4) the correlation is purely coincidental (spurious correlation). The famous example: ice cream sales correlate with drowning deaths. Cause? Neither — both are caused by hot weather (confounding). Trawl enough unrelated time series against each other and strong-looking correlations appear by chance alone; that is the whole premise of the "spurious correlations" genre, and it is a warning about how easy r is to manufacture rather than a finding about any particular pair of series. Real causal inference requires: randomised controlled experiments, instrumental variables, regression discontinuity designs, or causal-graphical reasoning (Judea Pearl's framework). Linear regression alone never proves causation — only describes association.
The ASEAN data-analysis angle
Linear regression is the workhorse of quantitative work across ASEAN. Common applications: property pricing (size + location → price models for PropertyGuru, 99.co, iProperty, Lamudi, Carousell Property). Demand forecasting (historical sales → predicted volume for Lazada, Shopee, Tokopedia, Grab — usually augmented with seasonality + trend). Credit scoring (income + history → default probability for Singapore banks, Indonesian fintechs, Malaysian Islamic banks). Marketing attribution (ad spend across channels → revenue lift for Grab Ads, Shopee Ads, GoTo Group). Healthcare (biomarker → diagnosis correlations in clinical research at NUS / NUHS / MGH). The math in this tool covers single-predictor cases; multiple regression (multiple x's predicting y) requires matrix algebra and is typically run in R / Python / Stata / SPSS. Most APAC tech companies use Python + scikit-learn for production regression; this tool is for quick exploratory analysis and education.
10 Things to Know About Linear Regression
Linear regression finds the line that minimises the sum of squared residuals — vertical distances from data points to the line, squared and summed.
The least-squares method was attributed to Carl Friedrich Gauss in 1795, though Legendre published it first in 1805, sparking a famous priority dispute.
Pearson r ranges from -1 (perfect negative) to +1 (perfect positive). Zero means no linear relationship — the data can still be tightly structured, even drawn into a recognisable shape, and score r ≈ 0.
R² = r² when there's only one predictor. R² is the fraction of y's variance explained by x. It is bounded [0, 1] for least-squares fits with an intercept, on the data they were fitted to — out of sample it can go negative.
Correlation does NOT imply causation. The most-violated rule in applied statistics — strong correlations can come from confounding, reverse causation, or coincidence.
Anscombe's Quartet (1973) shows four datasets with the same means, variances, regression line and R² (0.667, matching to the precision Anscombe printed) — but completely different visual patterns. Always plot your data.
The "best fit" line always passes through the mean point (x̄, ȳ). The intercept b = ȳ − m × x̄ guarantees this property.
Heteroscedasticity — when the variance of residuals isn't constant across x values — violates regression assumptions and inflates standard errors. Diagnose it in the residual plot above: residuals that fan out as x grows are the signature.
Multiple regression with k predictors uses matrix algebra (β = (X'X)⁻¹X'y) — the same idea generalised. This tool handles single-predictor case.
In machine learning, linear regression is the simplest baseline model. Any production model should beat it; if it doesn't, the problem might be unsolvable or the data inadequate.
Frequently Asked Questions
-
It's the method for finding the "best" line through data points. For each data point, compute the residual: the vertical distance from the point to the candidate line. Square each residual (to ensure positive values + emphasise larger errors). Sum the squared residuals. The "best" line is the one that minimises this sum. The math gives unique closed-form solutions for slope and intercept: slope = sum((x-mean_x)(y-mean_y)) / sum((x-mean_x)²); intercept = mean_y - slope × mean_x. Squaring residuals (vs taking absolute values) is convenient because it makes the math tractable AND penalises outliers more heavily — both algorithmically and statistically motivated.
-
r is the Pearson correlation coefficient — measures strength + direction of linear relationship on a -1 to +1 scale. R² is r squared — measures variance explained on a 0 to 1 scale. r = 0.9 means strong positive correlation; the same dataset has R² = 0.81 meaning x explains 81% of y's variability. r tells you "how related"; R² tells you "how much explained". In multiple regression with more than one predictor, R² remains meaningful but the relationship to r doesn't hold directly (R² no longer equals r²).
-
There is no number. An acceptable R² depends entirely on the field, the question you are asking, and how noisy the measurement is — the same R² can be a trivial result in one setting and a valuable edge in another. Published "R² > 0.3 for social science, R² > 0.95 for physics" style tables circulate widely but are folklore: they are not thresholds anything actually depends on, and we have deliberately removed them from this page rather than repeat them. Two things are worth more than a threshold. First, compare against a stated benchmark in your own domain — the R² a credible existing model achieves on the same problem. Second, check whether the model is wrong rather than merely imprecise: a high R² with obvious structure in the residual plot is a worse result than a modest R² with clean residuals. See NIST/SEMATECH e-Handbook of Statistical Methods §4.4.4, "R² Is Not Enough!". One specific trap: in time-series data, auto-correlation inflates R² and two independent trending series will correlate strongly for no reason at all.
-
NO. The single most-violated rule in applied statistics. Strong correlations between X and Y can arise from: (1) X causes Y. (2) Y causes X (reverse causation). (3) Some third variable Z causes both X and Y (confounding). (4) Pure coincidence (spurious correlation — see tylervigen.com for hundreds of examples). Demonstrating causation requires: randomised controlled experiments, natural experiments + instrumental variables, regression discontinuity designs, or formal causal-graphical reasoning (Pearl). Linear regression alone never proves causation. State results as "X is associated with Y" not "X causes Y" unless you have a properly designed causal study.
-
Linear regression assumes the relationship is straight-line. If it's actually curved (quadratic, exponential, logarithmic), linear regression will underfit — often while still reporting a respectable R². Inspect the scatter plot, and then the residual plot, which is the more sensitive test: a gentle curve can hide inside a scatter but shows up as an unmistakable arch or smile in the residuals. If either shows a curve, transform the data first. Power relationships (y = ax^b): log-log transform both axes, then run linear regression — slope is b. Exponential growth (y = ae^bx): log transform y only. Saturation curves: use logistic or asymptotic models. Polynomial relationships: add x² and x³ as additional predictors (multiple regression). For complex non-linear patterns, use spline regression or non-parametric methods (GAMs, decision trees, neural nets).
-
Four datasets constructed by statistician Francis Anscombe (1973) to demonstrate why you should always plot your data. All four share the same means, the same variances, the same regression line (y = 3 + 0.5x) and the same R² — 0.667, as Anscombe printed it. "Same" means to the precision he published, not bit-for-bit: at full precision the four R² values are 0.66654, 0.66624, 0.66632 and 0.66671. The visual patterns, however, are completely different: one is an ordinary linear relationship; one is a clean curve that a straight line badly misfits; one is perfectly collinear except for a single outlier; one has every x identical except one far-off point that single-handedly determines the line. The summary statistics hide all of that — only the plots reveal it. Paste any of the four into this tool and the residual plot below the scatter will show you exactly where the fit fails. Anscombe's lesson: descriptive statistics ≠ understanding. Always plot your data before drawing conclusions.
-
Two points draw a line, but they can never test one. Any two distinct points are fitted exactly, so r = ±1 and R² = 1 come out automatically — they are arithmetic, not evidence, which is why this tool reports the line for n = 2 but withholds r and R². The first sample size at which the fit can actually be wrong is n = 3. For a correlation worth reading: 10+. For stable estimates and for statistical inference (significance testing, confidence intervals): 30+ is the rule-of-thumb. For high-confidence inference: 100+. Correlations from very small samples are notoriously unstable — an r = 0.7 from n = 5 might become r = 0.2 with n = 50. Don't draw strong conclusions from regressions with n < 30. For ML/forecasting use cases, more data is essentially always better — diminishing returns kick in above ~1000 for stable estimates.
-
Least-squares regression is very sensitive to outliers because residuals are squared — one extreme point dominates the fit. Diagnose by inspecting the scatter plot and the residual plot above: an outlier that is dominating the fit shows up as one tall spike away from the zero line while the rest sit close to it. Mitigation options: (1) Investigate outliers — are they real or data entry errors? Fix obvious errors. (2) Use robust regression (M-estimators, Theil-Sen, RANSAC) that down-weights outliers automatically. (3) Transform the data to reduce skew (log-transform often helps). (4) Cap/winsorize extreme values. The simplest approach is also the most honest: report results both WITH and WITHOUT the outliers and discuss the difference.
-
No. Every calculation, the scatter plot and the residual plot run entirely in your browser via JavaScript + Canvas. There is no server roundtrip for your data: nothing you paste into the box is uploaded, logged, or stored anywhere, and closing the tab discards it. To be precise about what "no outbound requests" would and would not mean here — the page itself is not silent. Like the rest of this site it loads its own assets, and in production it also loads third-party analytics (and, where enabled, advertising), both gated behind your cookie-consent choice. Those requests carry page-level information such as the URL you are on; they never carry the contents of the input box, because your data never leaves the JavaScript running on your device in the first place. If you want to see this for yourself, open DevTools → Network, paste your data, and watch: the numbers and both charts update with no request fired. That distinction is what matters for proprietary research data, A/B test correlations, or clinical trial endpoints — the analysis stays on your machine.
-
This tool handles single-predictor regression only. Multiple regression with k > 1 predictors requires matrix algebra: β = (X'X)⁻¹X'y, where X is the design matrix and β is the vector of coefficients. The interpretation generalises: each coefficient represents the effect of that predictor holding others constant. Tools for multiple regression: R (lm function — gold standard, free), Python (statsmodels, scikit-learn LinearRegression), Excel (Data Analysis ToolPak — limited), SAS / SPSS / Stata (commercial). For quick multiple regression with a few predictors, Excel's LINEST function works for <15 variables. For production work, Python or R is essential.
Pick up where you left off
Stored only in this browser — never sent to our servers.