Concept Architecture
Least Squares Approximation: Concept Architecture
Orientation and learning roadmap
Least squares approximation turns an imperfectly fitting system into a precise optimization problem. This page develops residuals, linear and nonlinear formulations, geometry, computation, weighting, uncertainty, diagnostics, and health-economic applications. It then provides an auditable worked example, Excel implementation, validation workflow, and reporting standard.
Approximation begins with a target and a model space
The method requires values to approximate and a specified family of candidate models. The candidate family may be a straight line, a polynomial, a linear combination of basis functions, or a nonlinear function indexed by unknown parameters.
For observations ((x_i,y_i)) and a model (g(x_i;\boldsymbol\beta)), the residual at observation (i) is:
[ r_i=y_i-g(x_i;\boldsymbol\beta). ]
The residual sign depends on this convention, but squaring removes the sign from the objective. The convention should remain consistent in formulas, plots, gradients, and software.
The least squares criterion defines the selected approximation
Ordinary least squares chooses parameters that make the residual vector as short as possible in Euclidean distance. Squaring gives greater influence to larger absolute residuals and produces a smooth objective that is mathematically convenient.
[ \widehat{\boldsymbol\beta} =\underset{\boldsymbol\beta}{\operatorname{argmin}} \sum_{i=1}^{n}r_i^2 =\underset{\boldsymbol\beta}{\operatorname{argmin}} \left|\mathbf y-\mathbf g(\boldsymbol\beta)\right|_2^2. ]
The minimizer describes the best approximation under the chosen squared-error criterion. It does not establish that the candidate model is substantively correct or causally identified.
Linear least squares is linear in its coefficients
A model is linear for least-squares purposes when its predicted values are linear combinations of unknown coefficients. The predictors themselves may be transformed, so polynomial regression remains linear in its coefficients even though it is nonlinear in (x).
[ \mathbf y=X\boldsymbol\beta+\boldsymbol\varepsilon, \qquad \widehat{\boldsymbol\beta} =\underset{\boldsymbol\beta}{\operatorname{argmin}} |\mathbf y-X\boldsymbol\beta|_2^2. ]
The design matrix (X) contains one row per observation and one column per coefficient. An intercept is represented by a column of ones rather than being added implicitly.
The normal equations characterize an unconstrained solution
At a least-squares solution, the gradient of the residual sum of squares is zero when the problem is differentiable and unconstrained. For the linear problem, this gives the normal equations.
[ X^{\mathsf T}X\widehat{\boldsymbol\beta}=X^{\mathsf T}\mathbf y. ]
If (X) has full column rank, (X^{\mathsf T}X) is invertible and the unique solution may be written as:
[ \widehat{\boldsymbol\beta}= (X^{\mathsf T}X)^{-1}X^{\mathsf T}\mathbf y. ]
This inverse formula is useful for theory but should not be the default computational algorithm. Explicitly forming and inverting (X^{\mathsf T}X) can magnify floating-point error.
Geometry explains fitted values and residuals
The fitted vector (\widehat{\mathbf y}=X\widehat{\boldsymbol\beta}) is the orthogonal projection of (\mathbf y) onto the column space of (X) when ordinary Euclidean least squares applies. The residual vector is therefore orthogonal to every column of the design matrix.
[ X^{\mathsf T}\widehat{\mathbf r}=\mathbf 0, \qquad \widehat{\mathbf r}=\mathbf y-X\widehat{\boldsymbol\beta}. ]
With an intercept, one column of (X) is constant, so the fitted residuals sum to zero apart from numerical rounding. Orthogonality is a computational identity of the fitted problem, not evidence that errors are independent or unbiased in the population.
Rank determines whether coefficients are identifiable
Full column rank means no design column is an exact linear combination of the others and gives a unique coefficient vector for an unconstrained linear problem. Rank deficiency allows multiple coefficient vectors to produce the same fitted values, even though a minimum-residual solution still exists.
Software may return a minimum-norm solution, drop columns, pivot the factorization, or report a rank warning. Analysts must identify the effective model rather than interpreting non-unique coefficients as separately estimated effects.
Conditioning determines numerical sensitivity
An ill-conditioned design matrix has directions that are nearly linearly dependent, so small changes in the data or rounding can cause large changes in coefficient estimates. Forming (X^{\mathsf T}X) approximately squares the 2-norm condition number, which is why direct use of the normal equations may be unstable.
Centering or scaling predictors can improve numerical behavior without curing substantive non-identifiability. Condition numbers and singular values should be interpreted with the model scale and parameterization, not used as automatic pass-or-fail rules.
QR and singular-value decompositions are safer computational routes
QR factorization solves a full-rank linear least-squares problem without explicitly forming the inverse of (X^{\mathsf T}X). Singular-value decomposition is particularly informative when rank is uncertain or the design is ill-conditioned.
[ X=QR, \qquad R\widehat{\boldsymbol\beta}=Q^{\mathsf T}\mathbf y. ]
Pivoted QR can reveal dependent columns, while singular values support rank assessment and pseudoinverse solutions. Large sparse systems may instead use iterative methods that work through matrix-vector products.
Weighted least squares changes the distance being minimized
Weighted least squares assigns different influence to residuals, often because observations have unequal error variance or represent different precisions. The weight structure therefore changes the geometry of the approximation. With a symmetric positive-definite weight matrix (W), the criterion is:
[ \widehat{\boldsymbol\beta} =\underset{\boldsymbol\beta}{\operatorname{argmin}} (\mathbf y-X\boldsymbol\beta)^{\mathsf T} W(\mathbf y-X\boldsymbol\beta). ]
If errors are uncorrelated with known variances (\sigma_i^2), a conventional choice is (w_i=1/\sigma_i^2). Arbitrary weights change the estimand and cannot be justified merely because they improve visual fit.
Generalized least squares represents correlated errors
Generalized least squares extends weighting to a full error covariance structure. If (\operatorname{Var}(\boldsymbol\varepsilon)=\Sigma), the criterion uses (\Sigma^{-1}) and accounts for unequal variance and correlation jointly.
[ \widehat{\boldsymbol\beta}_{GLS} =\underset{\boldsymbol\beta}{\operatorname{argmin}} (\mathbf y-X\boldsymbol\beta)^{\mathsf T} \Sigma^{-1}(\mathbf y-X\boldsymbol\beta). ]
The covariance structure is usually estimated rather than known, adding uncertainty and potential misspecification. Clustered, repeated, longitudinal, and time-series data require methods aligned with how dependence arises.
Nonlinear least squares uses iterative optimization
When the model is nonlinear in its unknown parameters, no single matrix solve generally produces the answer. Algorithms such as Gauss–Newton, Levenberg–Marquardt, and trust-region methods repeatedly linearize the residual function and update the parameter vector.
[ \widehat{\boldsymbol\theta} =\underset{\boldsymbol\theta}{\operatorname{argmin}} \frac{1}{2}\sum_{i=1}^{n}r_i(\boldsymbol\theta)^2. ]
Starting values, parameter scaling, bounds, Jacobian accuracy, and stopping criteria can materially affect convergence. A termination message indicates that an algorithm stopped under its rules, not that the global minimum or a scientifically valid model was found.
Basis functions connect approximation and regression
A function can be approximated by combining fixed basis functions (\phi_j(x)) with estimated coefficients. Evaluating the basis functions at selected points produces a linear least-squares problem, even when the basis functions themselves are nonlinear in (x).
[ g(x)=\sum_{j=0}^{p-1}\beta_j\phi_j(x). ]
Polynomial, spline, Fourier, and other bases differ in smoothness, boundary behavior, interpretability, and conditioning. Basis selection determines the approximation space before least squares chooses the best member of that space.
Discrete and continuous approximation use related criteria
Discrete least squares minimizes squared discrepancies at observed or selected points. Continuous least squares instead minimizes an integrated squared difference over a domain, possibly with a weighting function.
[ \underset{g\in\mathcal V}{\operatorname{minimize}} \int_a^b w(x)[f(x)-g(x)]^2,dx. ]
The continuous problem projects (f) onto a function space under a weighted inner product. Numerical quadrature may turn the integral into a weighted discrete least-squares problem, so quadrature accuracy becomes part of the approximation error.
A worked straight-line approximation is fully auditable
Suppose four observations are ((1,2)), ((2,3)), ((3,5)), and ((4,4)), and the chosen model is (y=a+bx). The sample means are (\bar x=2.5) and (\bar y=3.5). The least-squares slope and intercept are calculated as follows.
[ b=\frac{\sum_i(x_i-\bar x)(y_i-\bar y)} {\sum_i(x_i-\bar x)^2} =\frac{4}{5}=0.8, ]
[ a=\bar y-b\bar x=3.5-(0.8)(2.5)=1.5. ]
The fitted values are (2.3,3.1,3.9,4.7), and the residuals (y_i-\widehat y_i) are (-0.3,-0.1,1.1,-0.7). Their sum is zero and their squared sum is (1.8), confirming the fitted line (\widehat y=1.5+0.8x).
Residual sums describe fit but not validity
The residual sum of squares measures the squared discrepancy remaining within the fitted sample. With an intercept, the total sum of squares can be partitioned into explained and residual components under ordinary least squares.
[ RSS=\sum_i(y_i-\widehat y_i)^2, \qquad TSS=\sum_i(y_i-\bar y)^2, \qquad R^2=1-\frac{RSS}{TSS}. ]
For the worked example, (TSS=5) and (R^2=1-1.8/5=0.64). A higher (R^2) does not establish correct functional form, reliable extrapolation, causal interpretation, or better out-of-sample prediction.
Statistical inference requires assumptions beyond minimization
Least squares always defines an optimization criterion, but familiar standard errors, confidence intervals, hypothesis tests, and efficiency claims require statistical assumptions. These assumptions concern the error mean, variance, dependence, distribution, sampling process, and correct specification of the conditional mean.
Under a conventional homoskedastic linear model, residual variance is estimated by:
[ \widehat{\sigma}^2=\frac{RSS}{n-p}, ]
where (p) is the number of estimated coefficients including the intercept. Robust or design-based covariance estimators may address some variance misspecification, but they do not correct confounding, selection bias, measurement error, or an incorrect estimand.
Residual diagnostics test the model-data relationship
Residual plots can reveal nonlinearity, changing variance, dependence, outliers, and omitted structure that a single fit statistic conceals. Diagnostics should be chosen for the design and outcome rather than treated as a ritual checklist.
- A residual-versus-fitted plot can reveal curvature and unequal spread.
- A residual-versus-time plot can reveal serial dependence or structural change.
- A quantile plot can assess whether distributional assumptions used for inference are plausible.
- Leverage and influence measures can identify observations with unusual predictor values or material impact on coefficients.
- Validation residuals can assess performance on observations not used to estimate the model.
Outliers can dominate a squared-error criterion
Because residuals are squared, a small number of large discrepancies can exert substantial influence. Removing observations solely because they fit poorly biases the analysis unless a documented data error or prespecified exclusion rule justifies removal.
Robust losses, least absolute deviations, heavy-tailed likelihoods, or explicit mixture models may be appropriate alternatives. Each changes the criterion and interpretation, so a “robust fit” must identify the method rather than merely report that sensitivity was assessed.
Regularization trades fit for controlled complexity
Regularized least squares adds a penalty to stabilize estimation, reduce variance, or encode structural preferences. Ridge regression penalizes squared coefficient magnitude, while lasso uses an absolute-value penalty and can set coefficients exactly to zero.
[ \widehat{\boldsymbol\beta}_{ridge} =\underset{\boldsymbol\beta}{\operatorname{argmin}} \left{|\mathbf y-X\boldsymbol\beta|_2^2 +\lambda|\boldsymbol\beta|_2^2\right}. ]
The tuning parameter (\lambda) changes the bias-variance tradeoff and should be selected transparently, often through validation. Penalized estimates are not ordinary least-squares estimates and require their own inferential and reporting conventions.
Approximation error and estimation error are different
Approximation error arises because the selected model space cannot represent the target exactly. Estimation error arises because coefficients are learned from finite or noisy data, while numerical error arises from finite-precision computation and incomplete optimization.
These errors require different remedies: a richer model space, more informative data, or a better numerical method. Increasing polynomial degree may reduce in-sample approximation error while worsening conditioning and out-of-sample performance.
Prediction and explanation require different validation
A model intended for prediction should be evaluated on data not used to fit its coefficients or through a defensible resampling design. A model intended to estimate an interpretable association or causal effect requires design and identification assumptions that predictive accuracy cannot replace.
Training residuals almost always shrink as unconstrained model complexity grows. Cross-validation, temporal validation, external validation, calibration, and clinically meaningful error measures should match the intended use.
Health-economic models use least squares in several roles
Least squares may estimate cost functions, fit calibration targets, approximate survival or disease trajectories, construct response surfaces, and summarize relationships for decision models. The correct residual scale and weighting depend on whether the target is an individual outcome, an aggregate moment, a published estimate, or a model-generated quantity.
Cost data are often skewed and heteroskedastic, survival data may be censored, and repeated observations may be correlated. Ordinary unweighted least squares should not be chosen automatically when those features determine the likelihood, estimand, or uncertainty.
Calibration weights determine which targets dominate
In model calibration, least squares can compare simulated outputs (m_k(\boldsymbol\theta)) with target values (d_k). Scaling and weights are essential because targets measured in larger numerical units would otherwise dominate the objective.
[ Q(\boldsymbol\theta)= \sum_{k=1}^{K}w_k[d_k-m_k(\boldsymbol\theta)]^2. ]
Weights may reflect target variance, covariance, policy importance, or another declared criterion, but these rationales are not interchangeable. Correlated targets require a covariance-aware distance when the goal is statistical calibration.
Decision consequences should guide acceptable accuracy
A small residual sum of squares does not guarantee that model outputs relevant to a health decision are accurate. Errors concentrated near a treatment threshold, survival tail, high-cost subgroup, or policy transition can matter more than larger errors elsewhere.
Validation should therefore examine incremental costs, outcomes, net benefit, threshold decisions, and uncertainty as well as the fitting objective. Numerical precision should be tight enough that it does not change substantive conclusions at the scale being reported.
Excel can reproduce a simple linear fit transparently
A worksheet can show the observed values, fitted values, residuals, squared residuals, and coefficient formulas in separate labeled columns. For (x) in A2:A5 and (y) in B2:B5, =SLOPE(B2:B5,A2:A5) returns (0.8) and =INTERCEPT(B2:B5,A2:A5) returns (1.5).
If the slope is in F2 and intercept in F3, the fitted value in C2 is =$F$3+$F$2*A2, the residual in D2 is =B2-C2, and the squared residual in E2 is =D2^2. Summing E2:E5 gives (1.8), while =RSQ(B2:B5,A2:A5) gives (0.64); larger, weighted, rank-deficient, nonlinear, or high-stakes problems require suitable statistical or numerical software.
A disciplined approximation workflow
Reliable use of least squares begins with the target quantity and ends with validation against the intended decision or prediction task. Every transformation, weight, constraint, and numerical choice should be visible. A practical sequence is:
- Define the target. Specify what is being approximated, the population or domain, and the intended use.
- Choose the model space. State the predictors, transformations, basis functions, interactions, constraints, and parameterization.
- Define residuals. Fix the observation-model alignment, units, sign convention, and treatment of missing or censored values.
- Justify the criterion. Explain why squared error and any weights or covariance structure suit the target.
- Assess identifiability. Check sample size, rank, collinearity, parameter bounds, and information in the design.
- Select the algorithm. Use QR, singular-value, sparse, constrained, or nonlinear methods appropriate to the problem.
- Verify the computation. Test dimensions, gradients or normal-equation orthogonality, convergence, and independent benchmark cases.
- Diagnose the fit. Examine residual structure, leverage, influence, constraints, and failures across relevant subgroups and time.
- Validate the use. Test prediction, calibration, decision outputs, or inference using evidence appropriate to the objective.
- Report reproducibly. Preserve data provenance, code, software, tolerances, weights, exclusions, diagnostics, and sensitivity results.
Common errors and safeguards
Least squares is easy to calculate but easy to misinterpret. The most serious errors involve an unsuitable objective, unstable computation, or claims that exceed the design. Common failures include:
- Computing ((X^{\mathsf T}X)^{-1}) explicitly when a stable factorization is available.
- Ignoring rank deficiency or severe ill-conditioning because software returned coefficients.
- Omitting an intercept without a substantive constraint that the fitted relationship passes through the origin.
- Treating weighted least squares as ordinary least squares without documenting the weights.
- Using a high (R^2) as evidence of causality, good extrapolation, or correct specification.
- Applying ordinary least squares to censored, dependent, or strongly heteroskedastic outcomes without addressing their structure.
- Removing influential observations solely because they change the result.
- Accepting nonlinear convergence from one starting value without checking alternatives and parameter bounds.
- Comparing residual sums across different outcome scales, samples, or weighting schemes as if they were directly equivalent.
- Confusing approximation error, sampling uncertainty, and numerical error.
- Reporting coefficient precision without the assumptions and covariance estimator that produced it.
- Evaluating only in-sample fit when the model will be used for prediction or decisions.
Reproducible reporting makes the approximation auditable
A complete record identifies the target data or function, analysis population or domain, model equation, design matrix construction, transformations, basis functions, residual definition, weights, covariance assumptions, constraints, regularization, and missing-data handling. It should also state the algorithm, software and version, rank threshold, scaling, starting values for nonlinear fits, stopping tolerances, convergence status, and treatment of failed fits.
Results should include coefficients, fitted values or sufficient summaries, residual diagnostics, uncertainty estimates where justified, condition or rank information, and performance on relevant validation data. Health-economic applications should additionally report the effect of fitting choices on incremental outcomes, uncertainty, and decisions rather than relying on the minimized objective alone.
Related Concepts (1)
Library
Publications
1
Accuracy and Stability of Numerical Algorithms — Nicholas J. Higham, 2nd Edition ed., 2002 (Society for Industrial and Applied Mathematics (SIAM))
The standard reference on floating-point error, conditioning, stability and the numerical reliability of matrix, polynomial and linear-algebra algorithms.
BookView source →
Frequently Asked Questions (6)
What is least squares approximation?
A method of estimating a model or function by minimising the sum of the squared differences between observed and predicted values.
Source: Golub GH, Van Loan CF. Matrix Computations. 4th ed. Johns Hopkins University Press; 2013.
How does least squares approximation fit a model?
Least squares approximation fits a model or function by minimising the sum of the squared differences between observed and predicted values. It chooses the model that makes those squared discrepancies as small as possible in total, so the fit sits as close to the data as the model allows. Minimising this sum of squared differences is the defining criterion of least squares approximation By penalising larger gaps more heavily and preventing positive and negative errors from cancelling, the squared-difference criterion gives a stable, widely used basis for fitting a model to data.
Source: Golub GH, Van Loan CF. Matrix Computations. 4th ed. Johns Hopkins University Press; 2013.
What quantity does least squares approximation minimise?
Least squares approximation minimises the sum of the squared differences between observed and predicted values, the total of the squared gaps between the data and the model's estimates. Squaring the differences penalises larger discrepancies more heavily and keeps the total non-negative. Making this sum of squared differences as small as possible is what least squares approximation does By penalising larger gaps more heavily and preventing positive and negative errors from cancelling, the squared-difference criterion gives a stable, widely used basis for fitting a model to data.
Source: Golub GH, Van Loan CF. Matrix Computations. 4th ed. Johns Hopkins University Press; 2013.
Why does least squares approximation square the differences?
Least squares approximation squares the differences so that positive and negative discrepancies do not cancel and so that larger errors weigh more in the total being minimised. Because it estimates a model by minimising the sum of these squared differences between observed and predicted values, squaring gives a well-behaved quantity to minimise. This squaring is intrinsic to how least squares approximation measures fit By penalising larger gaps more heavily and preventing positive and negative errors from cancelling, the squared-difference criterion gives a stable, widely used basis for fitting a model to data.
Source: Golub GH, Van Loan CF. Matrix Computations. 4th ed. Johns Hopkins University Press; 2013.
What does least squares approximation produce?
Least squares approximation produces the model or function whose predicted values minimise the sum of the squared differences from the observed values. The result is the best fit within the chosen model form according to that squared-difference criterion. Yielding this best-fitting model is the outcome of applying least squares approximation By penalising larger gaps more heavily and preventing positive and negative errors from cancelling, the squared-difference criterion gives a stable, widely used basis for fitting a model to data.
Source: Golub GH, Van Loan CF. Matrix Computations. 4th ed. Johns Hopkins University Press; 2013.
How does least squares approximation relate to polynomial approximation?
Least squares approximation estimates a model by minimising the sum of squared differences between observed and predicted values, while polynomial approximation represents a function or dataset using a polynomial that gives a sufficiently accurate estimate. When the model chosen is a polynomial, least squares approximation provides one way to fit it to data. The two are connected, since least squares supplies a fitting criterion that a polynomial approximation can be built on By penalising larger gaps more heavily and preventing positive and negative errors from cancelling, the squared-difference criterion gives a stable, widely used basis for fitting a model to data.
Source: Golub GH, Van Loan CF. Matrix Computations. 4th ed. Johns Hopkins University Press; 2013.
Trust Record
Verified by Dr Darrin Baines
British health economist
Professional identity: darrinbaines.org
Verification date: 25 Sep 2026
Content version: 1.0.0
Canonical Identity
- Term code
- CS-NA-AP-001
Stable URI · Machine-readable · Resolvable · CC BY 4.0
