Compute OLS intercept and slope for a tiny six-point series both with the normal equations and with statsmodels, then confirm they match.
Compute OLS intercept and slope for a tiny six-point series both with the normal equations and with statsmodels, then confirm they match.
Least squares chooses coefficients that minimise Σ(y_t − β0 − β1 x_t)². For simple regression, β1 = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)² and β0 = ȳ − β1 x̄. The fitted line passes through the point of means. This is a calculation practical: students should see that the software is doing the same arithmetic.
Six observations: t = 1..6 and y = 10, 12, 13, 15, 16, 18. Teaching data small enough to compute by hand.
Printed intercept and slope from the formulas and the same pair from statsmodels. For this six-point table the two methods must agree to rounding error. Students can also compute the slope on paper.
Agreement shows that 'least squares' is a defined calculation, not a mysterious black box. Later practicals add standard errors and residual plots on top of these same coefficients.
OLS estimates minimise squared residuals. Matching the formula to software builds trust in the numbers.