From observations to a fitted model
A data-fitting model maps observed inputs to modeled outputs by choosing coefficients for a specified set of functions. The design matrix records what each observation contributes to those outputs; the measured values stay in a separate response vector. This separation lets us ask whether one set of coefficients explains every measurement exactly or only approximately.
Build the fitting system
For the linear model y≈c0+c1x, the basis functions are 1 and x. An observation (xi,yi) contributes the row (1,xi) to A and the value yi to b. If the model is quadratic, use (1,xi,xi2) instead; each column follows the corresponding coefficient's basis function.
Multiplication Ac produces a prediction for each recorded input. The observed-minus-predicted difference ri=yi−(Ac)i is a residual. Keeping the row and response in the same observation order is essential: otherwise a mathematically valid multiplication compares a prediction with the wrong measurement.
Worked example
Consider observations (−2,0), (0,1), and (3,4) under a linear model. The rows of A are (1,−2), (1,0), and (1,3), while b=(0,1,4)T. The first two points give intercept 1 and slope 1/2, so their line predicts 5/2 at x=3, not the observed 4.
Consequently, interpolation, which requires every residual to be zero, is impossible with one line for these three observations. A least-squares fit instead chooses coefficients that minimize ∑iri2 over all three points. Its purpose is to balance the discrepancies according to that stated objective, without discarding the last measurement or pretending that every prediction equals its observation.
For observations (0,1), (1,3), and (2,4), a line y=a+bx is proposed. Which statement is correct?
A proposed line is ŷ=1+2x. At x=0,1,2 the measured y-values are 1,3,6. Define residual as observed minus predicted. Which residual vector and squared-error sum are correct?