Applications to Linear Models
Any model whose unknown parameters just get multiplied by known numbers and added up can be fit with the same least-squares recipe, even if its graph is curved. Put one row per data point in a design matrix and solve .
What the symbols mean
- Design matrix
One row per observation, one column per parameter.
- Parameters
The coefficients being estimated.
- Residuals
The leftover errors least squares minimizes.
Explanation
A linear model is simply a formula for predicting one quantity from others in which the unknown numbers you're fitting, the parameters, only ever get multiplied by known things and added up. The "linear" is about the parameters, not the shape of the graph: draws a parabola, but it's still a linear model, because each appears on its own, to the first power. What it's good for: one recipe fits lines, parabolas and models with several inputs, which is what regression software is doing under the hood. All we're really saying here is that means "the data equals the model's predictions plus some errors," with holding the known numbers (one row per observation), the parameters and the errors. And is just the normal equations from the last lesson, solved. It's the same idea with new letters.
Linear in the parameters, not in . Fitting is still linear algebra: the row for an observation at is . Think about why that's fine. Once you plug in a data point, and are just known numbers, like and . The only unknowns are the 's, and they show up exactly the way the unknowns in do.
Several variables: gives rows , with one column per parameter.
Transforming models. isn't linear in , but is.
A common mistake. It's tempting to fit by giving its own column, because that worked so well for . It can't work: is inside the exponential, so you don't know what numbers to put in that column until you already know . That's why you take logs first, which turns the model into a straight line in and .
In practice, software solves this with QR factorization instead of forming , for accuracy.
There's an animation further down that shows a curved model fit to stopping-distance data with these same normal equations.
See it
Worked examples
Fit (a line through the origin) to and .
- 1
There's only one parameter, so is a single column of -values: . Then and , and the normal equation is .
Practice
Type your answer and check it. Solve them all to complete the lesson.
Give the design-matrix row for fitting at .
Fit to and .
Fit to , , . Give .
Is fitting directly a linear least-squares problem in and ?
How many columns does have for ?
Hooke's law says a spring's force is proportional to its stretch: . A lab measures , and , in centimeters and newtons. Fit by least squares: find .
The hardest one here. Get it, and you've got this lesson.
Fit a parabola to , , and by least squares. Give .
Where it's used
Economists, epidemiologists and engineers fit linear models daily; logistic regression and neural networks generalize the same design-matrix setup.