Quick answer: A linear regression calculator finds the least squares regression line through paired x,y data and reports it as a regression equation, ŷ = mx + b, with the slope, intercept, correlation coefficient r and R squared. Paste your pairs above, read the equation, and use the prediction mode to estimate ŷ for any new x. Remember the honest framing from the start: correlation is not causation, and the line is a summary of your data, not a law of nature.

How to use this linear regression calculator

Step 1 — Enter your pairs. Type or paste one pair per line into the data box, with the x and y values separated by a comma or a tab. Two columns copied from Excel or Google Sheets paste in exactly as they are, because the line break ends one pair and the tab or comma splits it. If you prefer to build data slowly, use the row editor instead: each row holds one x and one y, the Add Row button appends a blank pair, and the two views stay in step — editing either one updates the other and refits the line.

Step 2 — Read the regression equation. The headline result is the fitted line in the form ŷ = mx + b. Beneath it you will find the slope m and intercept b separately, the number of points n, the means of x and y, the Pearson correlation coefficient r and R squared. The same pairs are drawn on the scatter plot beside the results, with the fitted line over the points, so you can see whether a straight line is a fair summary before you quote any of the numbers.

Step 3 — Predict. Type a new x value into the prediction box and the calculator substitutes it into the regression equation and shows ŷ. The pre-filled example predicts at x = 4. Predictions inside the range of the x values you fitted are interpolations and are the most trustworthy; predictions outside that range are extrapolations and deserve the caution described later in this guide.

Step 4 — Save your work. Copy the text summary, which records every pair, the equation and the statistics so the result can be reproduced or checked later, or download the chart. Your data stays on your device throughout: the fitting, the plotting and the prediction all run locally in this tab, and nothing is stored when you close it. If you need the chart itself as the main output — with a title, axis labels and a PNG for a report — the companion Scatter Plot Maker fits the identical line and leads with the picture.

What is linear regression?

Linear regression is the standard method for summarising the relationship between two numeric variables with one straight line. You have a set of observations, each contributing a pair: an x value, conventionally the variable suspected of doing the influencing — hours studied, temperature, advertising spend, engine size — and a y value, usually the outcome — exam score, ice-cream sales, revenue, fuel consumption. Plotted as dots, the pairs form a cloud. Linear regression draws the single straight line that represents that cloud best, and expresses the relationship as an equation you can calculate with.

That equation is the whole point. A chart can suggest that scores rise with study time; the regression equation says by how much, on average — and lets you estimate the score that corresponds to a study time you have not observed. Businesses use the same machinery to relate sales to spend, engineers to relate output to input, scientists to relate a measurement to the quantity that drives it, and students meet it as one of the core techniques of introductory statistics. This linear regression calculator performs the simplest and most widely taught form, called simple linear regression: one x variable, one y variable, one straight line, fitted by ordinary least squares.

The method has a long pedigree: Francis Galton developed regression in the 1880s studying how children's heights relate to their parents', and the least squares principle underneath it — published by Legendre in 1805 — remains the default fitting method in statistics software worldwide. This slope and intercept calculator runs exactly that classical computation, with the arithmetic automated.

The least squares regression line: how the slope and intercept are found

In short: the least squares regression line is the line that minimises the sum of the squared vertical gaps — the residuals — between the observed y values and the line. Its slope is m = Sxy ÷ Sxx and its intercept is b = ȳ − m × x̄, so the line always passes through the centre point of the data, (x̄, ȳ).

For any candidate line, each observed point misses it by some vertical amount: the gap between the actual y and the value the line predicts at that x. That gap is called a residual. Some residuals are positive, where the point sits above the line, and some are negative. Simply adding them is useless — they cancel — so least squares squares each one first, then adds the squares. The fitted line is the one whose total of squared residuals is smaller than any other straight line's total. Squaring is not an arbitrary choice: it punishes one big miss far more than several small ones, it treats over- and under-prediction symmetrically, and it leads to formulas simple enough to compute by hand — which is why the method has survived two centuries of alternatives.

The winning line has a closed-form solution, which is what this calculator evaluates. First compute the two means, x̄ and ȳ. Then measure how the variables move together and how x spreads out: Sxy is the sum, over all pairs, of (x − x̄) × (y − ȳ), and Sxx is the sum of (x − x̄)². The slope is the ratio m = Sxy ÷ Sxx — roughly, how much of x's spread is matched by movement in y. The intercept follows from a beautiful constraint: the least squares line always passes through the data's centre of gravity, the point (x̄, ȳ). So b = ȳ − m × x̄, and once m is known, b is forced. There is no searching or iterating involved; given the pairs, the answer is exact, and two honest calculators given the same pairs must agree to the last decimal.

Two failure cases follow directly from the formulas, and this calculator reports both cleanly rather than hiding them. With fewer than two pairs there is nothing to fit — a line through a single point could point anywhere. And when every x value is identical, Sxx is zero, the slope formula divides by zero, and no slope exists: the points form a vertical stack, and a stack has no tilt. Both cases are data problems, not calculator problems, and the fix is always the same — collect pairs in which x genuinely varies.

The regression equation: slope, intercept and ŷ

The regression equation writes the fitted line as ŷ = mx + b. Each symbol earns its place. The x is a value you supply. The m is the slope: the average change in y associated with a one-unit increase in x, expressed in y-units per x-unit — marks per hour, dollars per thousand impressions, millimetres per degree. The b is the intercept: the line's predicted y where x equals zero. And ŷ, pronounced y-hat, is the output — the line's predicted value of y at that x. The hat is a deliberate warning label. Observed values are plain y; ŷ is an estimate read off a summary line, and real observations scatter around it, sometimes widely.

The slope is usually the number that matters. Its sign gives the direction of the relationship, its size gives the steepness in the units of the problem, and multiplying it by a change in x gives the expected change in y across that change. The intercept needs more care. When x = 0 is a real, sensible value inside or near your data — a dosage of zero, a starting temperature of zero — the intercept is a genuine baseline prediction. When x = 0 is impossible or far outside the data — a human height of zero, a house with zero floor area — the intercept is merely the geometric anchor that positions the line, and quoting it as a prediction is a classic error. A good habit, whenever you report a regression equation, is to state the units, the range of x it was fitted on, and r or R squared beside it, so a reader can judge how much trust the line deserves.

Direction also matters. This calculator regresses y on x, minimising vertical residuals; regressing x on y instead produces a different line unless the correlation is perfect. A regression equation must always say which variable is being predicted from which — and if your question is genuinely symmetric, correlation, not regression, is the honest summary.

The correlation coefficient r and R squared

The regression line describes the relationship's shape; the Pearson correlation coefficient r grades its strength. The formula is r = Sxy ÷ √(Sxx × Syy), where Syy is the sum of (y − ȳ)². Dividing by the two spreads strips out the units and the scale, leaving a pure number between −1 and +1. An r of +1 means every point sits exactly on a rising line; −1 means every point sits exactly on a falling line; 0 means no straight-line pattern at all. Working rules of thumb treat |r| of 0.7 or more as strong, 0.3 to 0.7 as moderate, and under 0.3 as weak — useful labels, provided they are never mistaken for verdicts about importance or cause.

R squared is simply r × r for simple linear regression, and it translates the same information into a proportion: the share of the variation in y that the fitted line accounts for. An R squared of 0.9643 — the worked example below — means the line explains about 96 percent of the spread in y, leaving about 4 percent in the residuals. An R squared of 0.25 means three quarters of what moves y is coming from somewhere else, however tidy the line looks. R squared is the number to quote when the question is how much the line explains; r is the number to quote when the question is how strong and in which direction the straight-line association runs.

Both statistics share one blind spot, which is why this calculator always draws the plot next to the numbers: r and R squared detect straight-line patterns only. A perfect curved relationship can return an r near zero while the variables completely determine each other. Anscombe's quartet — four data sets with nearly identical means, correlation and regression lines, whose plots are a clean trend, a perfect curve, a line hijacked by one outlier, and a vertical stack — is the standing demonstration. Read r, then look at the dots.

Making predictions with the regression equation

In short: to predict, substitute your new x into ŷ = mx + b. For the worked example ŷ = 1.5x + 0.3333, x = 4 gives ŷ = 6.3333. Predictions inside the fitted x range are interpolations; outside it they are extrapolations, and their reliability falls quickly.

Prediction is the payoff of the whole exercise: the equation turns a question — what y should we expect at this x? — into one substitution and one multiplication. This calculator's prediction mode does exactly that and nothing more, and its honesty rules are worth stating. A prediction is the line's value, which is the average y observed at that x in data like yours; an individual case will usually land above or below it, by an amount comparable to the typical residual. A high R squared means those misses are small relative to the spread of y; a low one means the prediction is little better than a informed guess, even when the arithmetic is perfect.

The range rule matters most. Inside the span of x values you fitted, the line is anchored by data on both sides. Outside it — extrapolation — you assert that a pattern continues into territory you never observed, and real relationships bend: growth saturates, materials fail, markets change regime. This calculator computes any prediction you ask for, but an extrapolated figure should always be reported as an extrapolation.

Finally, hold the causation line firmly: correlation is not causation, and a regression equation does not change that. A strong fit can arise because x drives y, because y drives x, because a third variable drives both — hot weather driving both ice-cream sales and swimming accidents is the textbook case — or, in small samples, by pure coincidence. The line is a summary of the data you have, not a law about the world. Establishing cause takes design — controlled experiments, or careful adjustment for confounders — not a better fit.

Worked example: three points, checked by hand

Take the smallest data set that shows every step: the pairs (1, 2), (2, 3) and (3, 5) — the same checkable example used by the Scatter Plot Maker, whose published figures this calculator reproduces exactly. The means are x̄ = 2 and ȳ = 10 ÷ 3 ≈ 3.3333. Building the sums term by term:

xyx − x̄y − ȳ(x − x̄)(y − ȳ)(x − x̄)²(y − ȳ)²
12−1−1.33331.333311.7778
230−0.3333000.1111
3511.66671.666712.7778
SumSxy = 3Sxx = 2Syy = 4.6667

The slope is m = Sxy ÷ Sxx = 3 ÷ 2 = 1.5. The intercept is b = ȳ − m × x̄ = 3.3333 − 1.5 × 2 = 0.3333. So the regression equation is ŷ = 1.5x + 0.3333. The correlation is r = Sxy ÷ √(Sxx × Syy) = 3 ÷ √(2 × 4.6667) = 3 ÷ 3.0551 ≈ 0.9820, and R squared is 0.9820² ≈ 0.9643 — the line accounts for about 96 percent of the variation in y. Predicting at x = 4: ŷ = 1.5 × 4 + 0.3333 = 6.3333. Every one of those figures is what the calculator above reports for these three pairs, and the engine behind this page was tested in code against these hand-computed values, against a perfect line — (1, 1), (2, 2), (3, 3) giving slope 1, intercept 0 and r = 1 — and against a perfect negative case — (1, 5), (2, 3), (3, 1) giving slope −2, intercept 7 and r = −1 — before the page was published.

Notice, though, what the example also teaches: with only three points, an r of 0.982 is easy to achieve by luck, and the line's authority is thin. The arithmetic is identical for three points or three thousand — but the trust you should place in it is not. Sample size is not a detail; it is most of the story, which is why n is always displayed beside the results.

Formulas reference

Every quantity this slope and intercept calculator reports, in one table. x̄ and ȳ are the means of the x and y values, n is the number of pairs, and all sums run over every pair you entered.

QuantityFormulaWhat it gives you
Slope (m)m = Sxy ÷ SxxAverage change in y per one-unit increase in x
Intercept (b)b = ȳ − m × x̄The line's predicted y at x = 0; anchors the line through (x̄, ȳ)
Regression equationŷ = mx + bThe predicted y for any x you substitute
Co-movement (Sxy)Sxy = Σ (x − x̄)(y − ȳ)How x and y move together, in x-units times y-units
Spread of x (Sxx)Sxx = Σ (x − x̄)²How far the x values spread around their mean
Spread of y (Syy)Syy = Σ (y − ȳ)²How far the y values spread around their mean
Correlation coefficient (r)r = Sxy ÷ √(Sxx × Syy)Strength and direction of the straight-line relationship, −1 to +1
R squared (R²)R² = r × rShare of the variation in y accounted for by the line
Predictionŷ = m × xnew + bEstimated y at a new x value
Residuale = y − ŷThe vertical miss of an observed point from the line

For the spread of a single list of numbers rather than a relationship between two, see the Standard Deviation Calculator; for the slope between just two points, with no fitting involved, see the Slope Calculator.

When to use linear regression — and when not to

Use it when you have paired numeric data, the scatter plot looks roughly straight, and your question is either how y changes with x on average, or what y to expect at a given x. That covers a large share of everyday quantitative work: calibrating a sensor against a reference, relating practice time to test scores, summarising a dose–response trend in its roughly linear region, forecasting a steady quantity one step ahead, or answering the regression questions that introductory statistics courses set — which is why the worked example above mirrors the textbook method exactly, term by term.

Do not use it, or do not trust it, when the plot curves — fit a curve-aware method instead; when one or two outliers sit far from the cloud, because squaring lets them drag the line; when the data are ranks, categories or yes/no outcomes, which need rank correlation or logistic models; when the pairs are a time series with strong momentum, where neighbouring residuals are not independent; or when the real question is causal and the data are observational. In each case the calculator will still return numbers if you feed it pairs — arithmetic never refuses — and that is precisely why the judgement has to come from you, looking at the plot this page draws beside every result.

Common mistakes

Reading cause into correlation. The most consequential error, and the easiest: a beautiful line through observational data shows association, full stop. Confounders, reverse causation and coincidence all produce strong fits.

Extrapolating far beyond the data. The equation will happily evaluate at any x. The further from the fitted range, the more the prediction is hope rather than summary.

Quoting the intercept where x = 0 is meaningless. An intercept of 0.3333 in the worked example is an anchor, not a prophecy about y at x = 0 — there is no such observation anywhere near it.

Trusting r without looking at the plot. Anscombe's quartet is the standing warning: identical r, four utterly different relationships, only one of them a straight line.

Fitting two or three points and reporting four decimals. The decimals are exact; the knowledge is not. Small samples produce dramatic correlations by chance alone.

Swapping x and y without noticing. Regressing y on x and x on y give different lines. Decide which variable you are predicting before you fit, and say so when you report.

Letting one outlier steer. Least squares squares the gaps, so a single far-away point pulls the line hard. Identify outliers, check them for errors, and if you remove one, say so and show both results.

Honest limits: what this linear regression calculator does not do

This tool fits one straight line to the pairs you enter by ordinary least squares, reporting the regression equation, slope, intercept, Pearson r, R squared, the means and a prediction for a chosen x — for those pairs only. It does not fit curves, polynomials, logarithmic or multiple regression with several predictors; it does not compute confidence intervals, prediction intervals, standard errors or significance tests; it does not compute Spearman or other rank correlations; and it does not detect or remove outliers for you. It cannot tell you whether a relationship is causal, and no calculator can. State the summary plainly, as this page does: correlation is not causation, and the line is a summary, not a law. Everything here is computed on your device from exactly what you typed: no data is added, smoothed, uploaded or stored.

Sources and References

Source verification note: six of the seven sources above returned HTTP 200 to a direct request on 24 November 2026. The Penn State STAT 501 page did not respond to that direct request, so it was verified instead by full content retrieval of the page on the same date; no source was substituted.