Which line is fitted?
At least two x values must differ. Pairing must be preserved and x and y must have the same number of entries.[1]
b is slope and a intercept. Other sources may swap letter conventions; the defining form here is ŷ=a+bx.[1]
Observations are equally weighted and the intercept is freely fitted. A line forced through zero, weighted regression or orthogonal distances are different optimization problems. Calculating this fitted line does not require normal data. Tests or confidence intervals for its parameters, however, require an appropriate error and sampling model.[1][2]
Normal equations and residuals
Residuals ei=yi−ŷi are signed vertical distances, not perpendicular geometric distances to the line.[1]
The first equation gives na+bΣxi=Σyi, hence a=ȳ−bx̄. Substitution in the second equation gives bSxx=Sxy. Since Sxx>0, b is unique. The minimum is unique too: any nontrivial change in a and b has positive quadratic form Σ(δa+δb xi)2 when the x values are not all equal.[1]
These are useful checks for an ordinary fit with an intercept. Early rounding can visibly violate them.[1]
If x has unit X and y unit Y, Sxy has unit XY, Sxx unit X2 and b therefore Y/X. The units of a, ŷ and e are Y. A prediction ŷ(x*) is a line value, not an automatically calculated prediction interval for an individual new observation. Extrapolation can be unreliable even with small residual error.[2]
Three observations and a decreasing fit
Three normalized observation pairs
- Given
- The paired observations are (0,1), (1,2) and (2,2).
- Find
- Find the line, its value at x=3 and the third residual.
First state the general setup for the supplied quantities, then substitute the particular numbers.
Compute means and centered sums.
Find slope and intercept.
Evaluate the line and compare the third point.
Result: The line is . At x=3 it gives 8/3; the third point lies 1/6 below it.
Check: Residuals are −1/6, 1/3 and −1/6. Their sum is zero, and . At the centroid x=1 the line gives 5/3. The value at x=3 already extrapolates beyond the observed range [0,2].
Four points with a negative slope
- Given
- Data: (1,7), (2,5), (3,4), (4,2). This manual example uses four pairs and is separate from the interactive three-pair mode.
- Find
- Calculate the fit and its residual sum of squares.
First state the general setup for the supplied quantities, then substitute the particular numbers.
Form means and sums.
Substitute into the parameter formulas.
Calculate the four fitted values and deviations.
Result: The line is ŷ=8.5−1.6 x and has Q=0.2.
Check: Residuals sum to zero. The weighted check is 1·0.1+2·(−0.3)+3·0.3+4·(−0.1)=0. At the centroid, 8.5−1.6·2.5 equals 4.5.
Recall the method later with the formula’s flashcards.
10 flashcards · English materials
Already have an account? Sign in for flashcardsAvailable from Essential. A ready-made formula set, no AI credits required. Article exercises are not all included.
Five exercises on the fitted line
Calculate · Foundation
Fit (0,1), (1,3), (2,5) and evaluate at x=4.
Show hint
The three points have constant y increments.
Learning goal: Recognize an exact line through pairs.
Show solution and calculation
x̄=1 and ȳ=3.
Sxx=2 and Sxy=4, so b=2 and a=1. ŷ(4)=9.
Check: all three residuals are zero. However, x=4 lies outside the data range.
Rearrange · Foundation
x̄=3, ȳ=10 and b=2. Find a.
Show hint
a=ȳ−bx̄.
Learning goal: Use the centroid to check parameters.
Show solution and calculation
a=10−2·3=4.
Check: ŷ(3)=4+2·3=10, so the line passes through the centroid. Without further data this says nothing about fit quality.
Interpret · Application
x is time in s and y length in m. A fit gives b=0.4. What unit does b have?
Show hint
Slope is change in y per change in x.
Learning goal: Interpret slope in data units.
Show solution and calculation
b=0.4 m/s.
Increasing x by 1 s changes the fitted value by 0.4 m.
Correlation would instead be dimensionless and cannot be recovered from b alone.
Error analysis · Application
Someone calls Q the sum of squared shortest geometric distances to the line. Is that correct for this formula?
Show hint
Read yi−(a+bxi).
Learning goal: Check the correct residual direction.
Show solution and calculation
No. xi is fixed and the difference is measured in the y direction.
These are vertical residuals.
Orthogonal-distance minimization treats both axes differently and generally gives another line.
Transfer · Challenge
Use x*=x−10 in place of x. How do a and b change?
Show hint
Substitute x=x*+10 into a+bx.
Learning goal: Transform a shifted x scale.
Show solution and calculation
ŷ=a+b(x*+10)=(a+10 b)+bx*.
Slope remains b and the new intercept is a*=a+10 b.
Predictions for the same physical points are unchanged.
The numerical intercept change is not a new data effect.
Check your understanding with the formula’s reference test.
8 test questions · English materials
Already have an account? Sign in for the testAvailable from Essential. A ready-made formula set, no AI credits required. Article exercises are not all included.
Three pairs in the calculator, general formulas in the text
The calculator accepts exactly three pairs and finds b, a, a line value at x* or the third residual. Centering and quotients are combined rationally before output; an intermediate slope is not rounded before subsequent evaluation. It does not import arbitrary paired lists or automatically diagnose outliers or model assumptions.
The Pearson correlation coefficient measures a unit-free linear association. The Straight-line equation instead describes a line from given parameters. Sample variance uses n−1 for a different estimation question; residual variance of a fitted line with two parameters uses n−2 under the corresponding model.[1]
Sources for this explanation
Quanta · Updated November 1, 2026
- NIST Engineering Statistics Handbook §4.4.3.1: criterion, normal equations and straight-line estimators
- NIST Engineering Statistics Handbook §4.1.4.1: linear in parameters, outliers and extrapolation
- NIST Dataplot reference CORRELATION, page2-15: centered product-moment coefficient
Editorial responsibility: Quanta Study editorial team
Review scope
This explanation, 2 worked examples and 5 exercises are available in German and English. Structure, source references and mathematical notation undergo automated checks. Calculations, model assumptions and both language versions receive a separate AI review.
An independent, named human subject review has not yet been documented. Our exercise numbers are worked examples, rather than measurements published by the cited sources.
Editorial responsibility, sources and methodsChange history
- Authored a full German-English article with an original explanation, two worked examples and five varied exercises.
Cite this reference page
Quanta. Linear Regression (Line of Best Fit). Updated November 1, 2026. https://quanta-study.de/en/formula-sheet/lineare-regression
When citing a specific scientific statement, also cite the specialist source linked to that statement.