Linear Regression Calculator
With number of pairs 12, sum of x 78, sum of y 420, sum of xy 3080 and 3 more fields, linear regression comes to 2.4476 — slope. It is reached in 11 steps, the last of which is 350 / 143, and each one is printed on the page with its numbers filled in. The formula is the one published by NIST/SEMATECH e-Handbook, not an approximation fitted to it.
The least-squares line through a set of points, with its slope, intercept, r² and the standard error the prediction carries.
Formula and sources checked · How we check
Number of pairs 12, Sum of x 78, Sum of y 420, Sum of xy 3080
2.4476
Slope for the example below. Editing a field recomputes the calculator below; this figure holds the answer the page was loaded with.
It is written into the HTML rather than drawn by a script, so a search engine reading this page without running JavaScript still finds an answer.
- Mean of x
78 / 126.5- Mean of y
420 / 1235- Σxy − (Σx)(Σy)/n
3080 - (78 * 420) / 12350- Σx² − (Σx)²/n
650 - (78 ^ 2) / 12143- Σy² − (Σy)²/n
15600 - (420 ^ 2) / 12900- Slope
350 / 1432.448- Intercept, a
35 - 2.4475524 * 6.519.091- r², variance explained
(350 ^ 2) / (143 * 900)0.952- Standard error of the estimate
sqrt(43.356643 / (12 - 2))2.082- Standard error of the slope
2.0822258 / sqrt(143)0.174- Predicted y
19.090909 + 2.4475524 * 1043.566
Worked example
Twelve pairs with these sums fit y = 19.0909 + 2.4476x. At x = 10 the line predicts 43.566, with a standard error of the estimate of 2.082 — so a prediction quoted to four decimals is claiming precision the residuals do not support.
How to work it out yourself
- 1.Gather n, Σx, Σy, Σxy, Σx² and Σy² from the data.
- 2.Slope is Sxy over Sxx, where Sxy = Σxy − ΣxΣy/n and Sxx = Σx² − (Σx)²/n.
- 3.Intercept is the mean of y minus the slope times the mean of x, so the line always passes through the point of both means.
- 4.Predict by substituting x into y = a + bx — but only inside the range the data covered.
The formula
- Mean of x
78 / 12 - Mean of y
420 / 12 - Σxy − (Σx)(Σy)/n
3080 - (78 * 420) / 12 - Σx² − (Σx)²/n
650 - (78 ^ 2) / 12 - Σy² − (Σy)²/n
15600 - (420 ^ 2) / 12 - Slope
350 / 143 - Intercept, a
35 - 2.4475524 * 6.5 - r², variance explained
(350 ^ 2) / (143 * 900) - Standard error of the estimate
sqrt(43.356643 / (12 - 2)) - Standard error of the slope
2.0822258 / sqrt(143) - Predicted y
19.090909 + 2.4475524 * 10
Source: NIST/SEMATECH e-Handbook — least squares regression, NIST/SEMATECH e-Handbook of Statistical Methods
Questions people actually ask
- How do you find the line of best fit?
- By minimising the sum of the squared vertical distances from the points to the line. That criterion has a closed-form answer: slope = Sxy/Sxx and intercept = ȳ − b·x̄. No iteration and no guessing — the arithmetic above is the whole method.
- Why squared distances rather than plain ones?
- Two reasons, one good and one convenient. Squaring makes the criterion differentiable, so the minimum has a formula. It also weights a point twice as far away four times as heavily, which is a modelling choice rather than a law — least absolute deviations gives a different, more outlier-resistant line.
- What does the standard error of the estimate tell me?
- The typical size of a residual — how far a real point sits from the line, in the units of y. A prediction is only as good as that figure: reporting 43.5664 when the standard error is 2.08 quotes four decimals of a number that is uncertain in the units column.
- Can I predict outside the range of my data?
- You can compute it; you cannot rely on it. A line fitted between x = 1 and x = 12 says nothing about x = 100, because nothing in the data shows the relationship stays linear out there. Extrapolation is where regressions produce their most confident wrong answers.
- Which variable goes on which axis?
- It matters. Regressing y on x minimises vertical distances; regressing x on y minimises horizontal ones, and the two lines are different unless r = 1. Put the thing you want to predict on y — and if neither predicts the other, a correlation is the honest summary, not a line.
Related
- Correlation CalculatorPearson correlation from the sums a class is given, with r², the slope it implies, and the sample size at which it stops being noise.
- Percentage Change CalculatorPercentage increase or decrease between two values, with the absolute difference and the multiplier.
- Slope CalculatorSlope, intercept, angle and the full line equation from two points, with the perpendicular slope beside it.
- Z-Score to P-Value CalculatorExact p-value from a z-score, one-tailed or two-tailed, with the percentile the score sits at.
- Grade CalculatorYour weighted course grade from up to eight categories, by percentage or by points, or the score you need on the final to reach the grade you want.
- Confidence Interval CalculatorThe confidence interval around a sample mean, with the margin of error and what the interval does and does not claim.
Put this calculator on your site
Free, no attribution required beyond the link.
<iframe src="https://rulecalculators.com/embed/linear-regression" width="100%" height="420" style="border:1px solid #e7e4de;border-radius:12px" title="Linear Regression Calculator"></iframe>