Linear Regression Calculator
Fit a least-squares line to paired data for the slope, intercept, equation and R², with the correlation alongside so you can judge the fit.
Everything you type here is processed on your own device. No input is sent to a server, logged, or stored.
What the Linear Regression Calculator does
Use this linear regression calculator to fit a least-squares line to paired data for the slope, intercept, equation and R², with the correlation alongside so you can judge the fit. Fill in all 2 fields and the result updates as you type — there is no Calculate button to press and no page reload. It is most often used for finding the line of best fit for a lab experiment or a coursework data set. If you want to cross-check the result, there is another linear regression calculator on FreeToolStation.org.
How to use it
- Paste your x values, separated by commas, spaces or new lines.
- Paste the matching y values in the same order.
- Read the equation, then check R² before trusting the slope.
How it works
Least-squares regression finds the one straight line that makes the sum of the squared vertical distances to your points as small as possible. Squaring the residuals is what makes the answer unique: it penalises a point ten units away a hundred times more than one unit away, and it makes the algebra solvable in closed form, which is why the slope and intercept come out of two sums rather than an iterative search.
The slope is the interesting number. It says how much y moves for a one-unit move in x, in whatever units the data is in. The intercept is where the line crosses x = 0, which is often outside the range of the data and sometimes physically meaningless — a regression of weight on height has an intercept at zero height. R² is the share of the variation in y that the line accounts for, from 0 to 1, and it is just the correlation squared.
What regression cannot tell you is whether a line was the right shape. A curved relationship can produce a respectable R² while the residuals form an obvious arc, and a single far-off point can drag a slope a long way. Plot the data, or at least look at the residuals, before trusting the equation.
When to use it
- Finding the line of best fit for a lab experiment or a coursework data set.
- Getting the slope when the slope itself is the quantity you want — a rate, a coefficient, a per-unit effect.
- Checking how much of one variable's variation another actually explains.
- Producing a prediction equation from paired measurements.
Common mistakes to avoid
- Reading a high R² as proof that x causes y. Regression measures association, and a third variable or pure coincidence produces the same numbers.
- Predicting far outside the range of the data. The line is fitted where the points are; beyond them it is an assumption.
- Swapping x and y. Regressing y on x and x on y give different lines unless the fit is perfect, because the residuals being minimised are measured in different directions.
- Leaving an outlier in without noticing. Squared residuals give a single stray point enormous leverage over the slope.
Frequently asked questions
What is the least-squares regression formula?
The slope is b = (nΣxy − ΣxΣy) / (nΣx² − (Σx)²) and the intercept is a = (Σy − bΣx) / n. Together they give the line y = a + bx that minimises the sum of squared vertical residuals.
What does R² actually mean?
The proportion of the variance in y that the fitted line accounts for. R² = 0.95 means the line explains 95% of the up-and-down movement in y, leaving 5% unexplained. It is the square of the correlation coefficient.
How many data pairs do I need?
Two will define a line, but a line through two points always fits perfectly and tells you nothing. The standard error of the estimate needs at least three. For a slope you would quote, more is better and a plot matters more than the count.
Does a negative slope mean a bad fit?
No. A negative slope just means y falls as x rises. Fit quality is R² and the residual pattern, not the sign.
Can I use this for a curved relationship?
Not directly — it fits a straight line. If the points curve, transforming one variable (taking logs, say) sometimes straightens the relationship enough for a linear fit to be meaningful.