Linear regression
Choose a line by the errors it leaves
For these five observations, begin by predicting y = 3 for everyone. A residual is the observed value minus this prediction. Squaring and adding those residuals gives the total error.
Compare the horizontal line with the least-squares line. Follow the residual segments and squared-error areas as the total error falls.
Observations, least-squares line & residual segments
Each dot is one x, y observation. The fitted line predicts y from x. Each vertical segment shows a residual, the observed y minus the predicted y.
Residuals against x
Each dot shows one observed x value and its residual. The horizontal zero line separates over-predictions from under-predictions. Using x reveals curved patterns even when the fitted line is horizontal.
Worked comparison
Follow the calculation
What the symbols mean
ŷ is the predicted y value. b₀ is the fitted intercept and b₁ is the fitted slope. Each residual is the observed y minus ŷ.
Assumptions and full calculation
The simulated data use fixed x values and a population intercept of 1. The errors are independent normal values with the chosen standard deviation. The fitted line estimates the intercept and slope from the sample. Least squares minimises the sum of squared vertical residuals. This model includes an intercept. R² is undefined if y is constant, and the slope is undefined if x is constant. Fitting the line does not require normal errors. Tests and confidence intervals for its coefficients need further assumptions. The simulation controls have no effect on manual data.