The Central Idea

Suppose a model predicts observations from a parameter vector \(\boldsymbol{\theta}\). The observed data are

\[ \mathbf{y}. \]

If the model prediction is

\[ \hat{\mathbf{y}} = F(\boldsymbol{\theta}), \]

then the residual vector is

\[ \mathbf{r} = \mathbf{y} - F(\boldsymbol{\theta}). \]

Least-squares estimation chooses the parameter vector that minimizes

\[ \boxed{ \|\mathbf{r}\|_2^2 = \sum_{i=1}^{n}r_i^2 }. \]

Why Least Squares Is Needed

In many inverse problems, there are more observations than unknown parameters.

If

\[ n>p, \]

where \(n\) is the number of observations and \(p\) is the number of parameters, the system is often overdetermined.

Because noisy measurements generally do not lie exactly on the model, there may be no parameter vector that satisfies every observation simultaneously.

Least squares provides a principled best compromise.

Linear Least Squares

The basic linear least-squares problem has the form

\[ \mathbf{y} = X\boldsymbol{\theta} + \boldsymbol{\varepsilon}, \]

where:

The Linear Residual

For a trial parameter vector \(\boldsymbol{\theta}\), the predicted data are

\[ \hat{\mathbf{y}} = X\boldsymbol{\theta}. \]

Therefore,

\[ \boxed{ \mathbf{r} = \mathbf{y} - X\boldsymbol{\theta} }. \]

The least-squares objective is

\[ \Phi(\boldsymbol{\theta}) = \|\mathbf{y}-X\boldsymbol{\theta}\|_2^2. \]

Expanding the Objective

The objective can be written

\[ \Phi(\boldsymbol{\theta}) = (\mathbf{y}-X\boldsymbol{\theta})^T (\mathbf{y}-X\boldsymbol{\theta}). \]

Expanding gives

\[ \Phi = \mathbf{y}^T\mathbf{y} - 2\boldsymbol{\theta}^TX^T\mathbf{y} + \boldsymbol{\theta}^TX^TX\boldsymbol{\theta}. \]

This is a quadratic function of the unknown parameter vector.

Deriving the Normal Equations

Differentiate the objective with respect to \(\boldsymbol{\theta}\):

\[ \nabla_{\boldsymbol{\theta}}\Phi = -2X^T\mathbf{y} + 2X^TX\boldsymbol{\theta}. \]

At a least-squares minimizer,

\[ \nabla_{\boldsymbol{\theta}}\Phi=\mathbf{0}. \]

Therefore,

\[ \boxed{ X^TX\hat{\boldsymbol{\theta}} = X^T\mathbf{y} }. \]

These are the normal equations.

The Closed-Form Solution

If \(X\) has full column rank, then

\[ X^TX \]

is invertible.

The least-squares estimate is then

\[ \boxed{ \hat{\boldsymbol{\theta}} = (X^TX)^{-1}X^T\mathbf{y} }. \]

This formula is important conceptually, although numerical software often avoids explicitly forming the inverse.

A One-Parameter Example

Suppose

\[ y_i=\theta x_i+\varepsilon_i. \]

The least-squares objective is

\[ \Phi(\theta) = \sum_{i=1}^{n}(y_i-\theta x_i)^2. \]

Differentiate:

\[ \frac{d\Phi}{d\theta} = -2\sum_i x_i(y_i-\theta x_i). \]

Set this equal to zero:

\[ \sum_i x_i y_i = \theta\sum_i x_i^2. \]

Therefore,

\[ \boxed{ \hat{\theta} = \frac{\sum_i x_i y_i}{\sum_i x_i^2} }. \]

Fitting a Line with an Intercept

For the model

\[ y_i=\beta_0+\beta_1x_i+\varepsilon_i, \]

the design matrix is

\[ X= \begin{bmatrix} 1 & x_1\\ 1 & x_2\\ \vdots & \vdots\\ 1 & x_n \end{bmatrix}, \]

and

\[ \boldsymbol{\beta} = \begin{bmatrix} \beta_0\\ \beta_1 \end{bmatrix}. \]

Least squares selects the intercept and slope that minimize the total squared vertical residuals.

The Geometric Interpretation

The vector

\[ X\boldsymbol{\theta} \]

lies in the column space of \(X\).

If the observed vector \(\mathbf{y}\) does not lie in that column space, an exact solution is impossible.

Least squares chooses the point in the column space closest to \(\mathbf{y}\).

Thus,

\[ \boxed{ X\hat{\boldsymbol{\theta}} = \operatorname{proj}_{\operatorname{Col}(X)}\mathbf{y} }. \]

The Residual Is Orthogonal to the Model Space

At the least-squares solution,

\[ X^T (\mathbf{y}-X\hat{\boldsymbol{\theta}}) = \mathbf{0}. \]

Since

\[ \hat{\mathbf{r}} = \mathbf{y}-X\hat{\boldsymbol{\theta}}, \]

we obtain

\[ \boxed{ X^T\hat{\mathbf{r}}=\mathbf{0} }. \]

Therefore, the least-squares residual is orthogonal to every column of the design matrix.

Why the Normal Equations Are Called Normal

In geometry, a vector is normal to a subspace when it is perpendicular to that subspace.

The least-squares residual satisfies

\[ \hat{\mathbf{r}} \perp \operatorname{Col}(X). \]

The normal equations express exactly this orthogonality condition.

The Projection Matrix

When \(X\) has full column rank, the fitted vector is

\[ \hat{\mathbf{y}} = X(X^TX)^{-1}X^T\mathbf{y}. \]

Define

\[ P = X(X^TX)^{-1}X^T. \]

Then

\[ \boxed{ \hat{\mathbf{y}}=P\mathbf{y} }. \]

The matrix \(P\) projects observation vectors onto the column space of \(X\).

The Residual Projection

Since

\[ \hat{\mathbf{r}} = \mathbf{y}-P\mathbf{y}, \]

we may write

\[ \hat{\mathbf{r}} = (I-P)\mathbf{y}. \]

Thus \(I-P\) projects onto the orthogonal complement of the model space.

Pythagorean Decomposition

Because the fitted vector and residual are orthogonal,

\[ \mathbf{y} = \hat{\mathbf{y}} + \hat{\mathbf{r}} \]

gives

\[ \boxed{ \|\mathbf{y}\|_2^2 = \|\hat{\mathbf{y}}\|_2^2 + \|\hat{\mathbf{r}}\|_2^2 }. \]

Least-squares geometry is therefore a direct application of orthogonal decomposition.

Uniqueness of the Least-Squares Estimate

The fitted prediction

\[ X\hat{\boldsymbol{\theta}} \]

is unique as the orthogonal projection of \(\mathbf{y}\) onto a subspace.

The parameter vector itself is unique only if \(X\) has full column rank.

If the columns of \(X\) are linearly dependent, multiple parameter vectors may produce exactly the same fitted prediction.

Rank Deficiency

If

\[ \operatorname{rank}(X) then the parameters are not all independently identifiable from the linear model.

In that case,

\[ X^TX \]

is singular, so the inverse in the standard formula does not exist.

This connects least squares directly to identifiability.

Near Rank Deficiency

A design matrix can have full rank and still be nearly rank deficient.

This occurs when one column is almost a linear combination of others.

Then parameter estimates may become extremely sensitive to small changes in the data.

The problem is mathematically identifiable but practically ill conditioned.

Conditioning of the Normal Equations

Forming

\[ X^TX \]

can worsen numerical conditioning.

Roughly,

\[ \kappa(X^TX) \approx \kappa(X)^2, \]

where \(\kappa\) is a condition number.

Therefore, direct solution of the normal equations can lose accuracy when the design matrix is poorly conditioned.

Why We Usually Do Not Form the Inverse

The expression

\[ (X^TX)^{-1}X^T\mathbf{y} \]

is useful theoretically.

Numerically, explicitly computing a matrix inverse is often less stable and less efficient than solving a linear system or using matrix factorizations.

Practical least-squares software usually uses QR decomposition, singular value decomposition, or specialized sparse solvers.

QR Factorization

Suppose

\[ X=QR, \]

where \(Q\) has orthonormal columns and \(R\) is upper triangular.

Then

\[ \|\mathbf{y}-X\boldsymbol{\theta}\|_2 = \|\mathbf{y}-QR\boldsymbol{\theta}\|_2. \]

The least-squares problem can be reduced to solving a triangular system

\[ R\hat{\boldsymbol{\theta}} = Q^T\mathbf{y}. \]

Why QR Is Useful

QR factorization avoids explicitly forming \(X^TX\), which generally improves numerical stability.

It is a standard method when the design matrix has full or nearly full column rank.

Householder reflections and Givens rotations are common computational tools for constructing QR factorizations.

Singular Value Decomposition

The singular value decomposition writes

\[ X = U\Sigma V^T. \]

The diagonal entries of \(\Sigma\),

\[ \sigma_1\ge\sigma_2\ge\cdots\ge0, \]

are the singular values.

They reveal how strongly different parameter directions affect the observations.

SVD and Identifiability

If a singular value is exactly zero, there is a parameter direction that does not affect the predicted observations.

If a singular value is very small, the corresponding direction affects the observations only weakly.

Therefore:

\[ \boxed{ \text{small singular values indicate weakly informed parameter directions} }. \]

The Pseudoinverse

The Moore-Penrose pseudoinverse provides a generalized solution when \(X\) is rectangular or rank deficient.

If

\[ X=U\Sigma V^T, \]

then

\[ X^{+} = V\Sigma^{+}U^T, \]

where nonzero singular values are replaced by their reciprocals.

A least-squares solution can then be written

\[ \boxed{ \hat{\boldsymbol{\theta}} = X^{+}\mathbf{y} }. \]

Minimum-Norm Solutions

When an underdetermined system has infinitely many exact solutions, the pseudoinverse selects the solution with the smallest Euclidean norm:

\[ \boxed{ \hat{\boldsymbol{\theta}} = \operatorname*{arg\,min} \|\boldsymbol{\theta}\|_2 } \]

subject to satisfying the observational constraints.

This is one natural way to choose among many equivalent parameter vectors.

Weighted Least Squares

If observations have unequal uncertainty, we may minimize

\[ \Phi(\boldsymbol{\theta}) = (\mathbf{y}-X\boldsymbol{\theta})^T W (\mathbf{y}-X\boldsymbol{\theta}), \]

where \(W\) is a positive-definite weighting matrix.

The weighted normal equations are

\[ \boxed{ X^TWX\hat{\boldsymbol{\theta}} = X^TW\mathbf{y} }. \]

Weighted Closed-Form Estimate

If \(X^TWX\) is invertible, then

\[ \boxed{ \hat{\boldsymbol{\theta}} = (X^TWX)^{-1}X^TW\mathbf{y} }. \]

Observations receiving larger weights have greater influence on the fit.

Inverse-Variance Weighting

If observation \(i\) has variance

\[ \sigma_i^2 \]

and measurement errors are independent, a natural choice is

\[ W = \operatorname{diag} \left( \frac{1}{\sigma_1^2}, \ldots, \frac{1}{\sigma_n^2} \right). \]

More precise observations receive more weight.

Correlated Errors

If measurement errors have covariance matrix

\[ \Sigma, \]

then generalized least squares uses

\[ W=\Sigma^{-1}. \]

The objective becomes

\[ \boxed{ \Phi = \mathbf{r}^T\Sigma^{-1}\mathbf{r} }. \]

This accounts for both unequal variances and correlation among errors.

Whitening the Residuals

If

\[ \Sigma=LL^T, \]

where \(L\) is a matrix factor, define transformed quantities

\[ \tilde{\mathbf{y}} = L^{-1}\mathbf{y}, \qquad \tilde{X} = L^{-1}X. \]

Then generalized least squares becomes ordinary least squares:

\[ \|\tilde{\mathbf{y}}-\tilde{X}\boldsymbol{\theta}\|_2^2. \]

This transformation is often called whitening.

Least Squares and Gaussian Error

Suppose measurement errors are independent and Gaussian:

\[ \varepsilon_i \sim N(0,\sigma^2). \]

Then the probability density of observing the data contains the factor

\[ \exp \left( -\frac{1}{2\sigma^2} \sum_i r_i^2 \right). \]

Maximizing this likelihood is equivalent to minimizing

\[ \sum_i r_i^2. \]

This is the key connection between least squares and maximum likelihood.

Least Squares Does Not Require Exact Gaussianity

Least squares can still be useful even when the errors are not perfectly Gaussian.

However, the interpretation of standard errors, confidence intervals, and optimality may change when the error assumptions are violated.

The loss function should be chosen with the data-generating process in mind.

Residual Sum of Squares

The minimized least-squares objective is often called the residual sum of squares:

\[ \boxed{ \operatorname{RSS} = \sum_{i=1}^{n} \hat{r}_i^2 }. \]

Smaller RSS indicates closer agreement between model and observations, holding the data and model scaling fixed.

Mean Squared Error

A normalized residual measure is

\[ \operatorname{MSE} = \frac{1}{n} \sum_{i=1}^{n}\hat{r}_i^2. \]

In statistical estimation, a degrees-of-freedom adjustment is often used:

\[ s^2 = \frac{\operatorname{RSS}}{n-p}. \]

Under suitable assumptions, \(s^2\) estimates the error variance \(\sigma^2\).

Root Mean Squared Error

The root mean squared error is

\[ \operatorname{RMSE} = \sqrt{ \frac{1}{n} \sum_i \hat{r}_i^2 }. \]

Unlike squared error, RMSE has the same physical units as the observed quantity.

Parameter Covariance in Linear Least Squares

Under the model

\[ \mathbf{y} = X\boldsymbol{\theta} + \boldsymbol{\varepsilon}, \qquad \operatorname{Cov}(\boldsymbol{\varepsilon}) = \sigma^2 I, \]

the least-squares estimator has covariance

\[ \boxed{ \operatorname{Cov}(\hat{\boldsymbol{\theta}}) = \sigma^2(X^TX)^{-1} }. \]

What the Covariance Matrix Tells Us

Diagonal entries describe parameter variances:

\[ \operatorname{Var}(\hat{\theta}_j). \]

Off-diagonal entries describe how parameter estimates vary together.

Large variances or strong correlations often indicate weak information or nearly dependent model effects.

Standard Errors

The standard error of parameter \(j\) is

\[ \operatorname{SE}(\hat{\theta}_j) = \sqrt{ \operatorname{Var}(\hat{\theta}_j) }. \]

A large standard error relative to the parameter magnitude signals substantial uncertainty.

Confidence Intervals

Under suitable statistical assumptions, a parameter confidence interval can be constructed from the estimate and its standard error.

A generic form is

\[ \hat{\theta}_j \pm c\, \operatorname{SE}(\hat{\theta}_j), \]

where \(c\) depends on the desired confidence level and reference distribution.

Confidence intervals describe uncertainty in estimation, not guaranteed physical bounds.

Leverage

In linear least squares, the projection matrix

\[ P = X(X^TX)^{-1}X^T \]

has diagonal entries

\[ h_{ii}. \]

These are called leverages.

Observations with high leverage occupy unusual locations in predictor space and can strongly influence fitted parameters.

Influence

An observation can have a small residual yet still strongly affect the fit if it has high leverage.

Influence diagnostics examine how parameter estimates or fitted values change when individual observations are removed or perturbed.

Residual size alone therefore does not fully describe the importance of an observation.

Least Squares and Scaling

Poorly scaled columns of \(X\) can make the numerical problem difficult.

Suppose one column is of order \(10^{-8}\) and another is of order \(10^6\). Rescaling parameters or columns can improve numerical behavior without changing the underlying model.

Scaling is especially important before interpreting condition numbers or singular values.

Centering Predictors

In some regression problems, replacing \(x_i\) by

\[ x_i-\bar{x} \]

can reduce correlation between the intercept and slope terms.

Centering often improves interpretation and sometimes improves numerical conditioning.

Polynomial Least Squares

A quadratic model can be written

\[ y = \beta_0+\beta_1x+\beta_2x^2. \]

The design matrix becomes

\[ X= \begin{bmatrix} 1 & x_1 & x_1^2\\ 1 & x_2 & x_2^2\\ \vdots & \vdots & \vdots\\ 1 & x_n & x_n^2 \end{bmatrix}. \]

Although the model is nonlinear in \(x\), it is linear in the unknown coefficients and is therefore a linear least-squares problem.

Linear in Parameters Versus Linear in Variables

The phrase linear least squares refers to linearity in the unknown parameters.

For example,

\[ y = a\sin x+b\cos x \]

is linear in \(a\) and \(b\), even though the predictors involve nonlinear functions of \(x\).

Therefore, the problem can still be written

\[ \mathbf{y}=X\boldsymbol{\theta}. \]

Nonlinear Least Squares

If the model is nonlinear in the unknown parameters,

\[ \mathbf{y} = F(\boldsymbol{\theta}) + \boldsymbol{\varepsilon}, \]

then the objective is

\[ \Phi(\boldsymbol{\theta}) = \|\mathbf{y}-F(\boldsymbol{\theta})\|_2^2. \]

There is usually no direct closed-form solution.

Local Linearization

Near a current estimate \(\boldsymbol{\theta}_k\), approximate the model by

\[ F(\boldsymbol{\theta}_k+\Delta\boldsymbol{\theta}) \approx F(\boldsymbol{\theta}_k) + J_k\Delta\boldsymbol{\theta}, \]

where

\[ J_k = \frac{\partial F}{\partial\boldsymbol{\theta}} \bigg|_{\boldsymbol{\theta}_k}. \]

This converts the nonlinear problem locally into a linear least-squares update.

Gauss-Newton Method

Let

\[ \mathbf{r}_k = \mathbf{y}-F(\boldsymbol{\theta}_k). \]

The Gauss-Newton step approximately solves

\[ J_k \Delta\boldsymbol{\theta} \approx \mathbf{r}_k. \]

The corresponding normal equations are

\[ \boxed{ J_k^TJ_k \Delta\boldsymbol{\theta} = J_k^T\mathbf{r}_k }. \]

Then

\[ \boldsymbol{\theta}_{k+1} = \boldsymbol{\theta}_k + \Delta\boldsymbol{\theta}. \]

When Gauss-Newton Works Well

Gauss-Newton is often effective when:

Performance can deteriorate with poor initialization or severe nonlinearity.

Levenberg-Marquardt Idea

A common modification adds a stabilizing term:

\[ \left( J^TJ+\lambda I \right) \Delta\boldsymbol{\theta} = J^T\mathbf{r}. \]

When \(\lambda\) is large, the step is more conservative.

When \(\lambda\) is small, the method behaves more like Gauss-Newton.

This provides a bridge between gradient descent and Gauss-Newton behavior.

Residual Diagnostics Still Matter

Least squares produces an optimum relative to the selected objective, but the residual pattern must still be inspected.

A good residual pattern should be consistent with the assumed error process.

Systematic trends can indicate that the model family itself is inadequate.

Heteroscedasticity

Heteroscedasticity means that the measurement variance changes across observations.

For example,

\[ \operatorname{Var}(\varepsilon_i) = \sigma_i^2 \]

may increase with the magnitude of the response.

In such cases, ordinary least squares may give inefficient or misleading uncertainty estimates, while weighted least squares can better reflect the error structure.

Outliers and Squared Loss

Squared loss grows rapidly:

\[ r^2. \]

Therefore, one very large residual can have substantial influence on the fitted parameters.

Least squares is highly effective when the assumed error model is appropriate, but it is not automatically robust to outliers.

Regularized Least Squares

When the inverse problem is unstable or underdetermined, a penalty can be added:

\[ \Phi(\boldsymbol{\theta}) = \|\mathbf{y}-X\boldsymbol{\theta}\|_2^2 + \lambda \|L\boldsymbol{\theta}\|_2^2. \]

The first term measures data mismatch.

The second term penalizes undesirable parameter behavior.

This leads toward the later lesson on regularization.

Ridge-Type Least Squares

If

\[ L=I, \]

then

\[ \Phi = \|\mathbf{y}-X\boldsymbol{\theta}\|_2^2 + \lambda\|\boldsymbol{\theta}\|_2^2. \]

The corresponding normal equations become

\[ \boxed{ (X^TX+\lambda I) \hat{\boldsymbol{\theta}} = X^T\mathbf{y} }. \]

The added diagonal term can improve stability in weak parameter directions.

Bias-Variance Tradeoff

Regularization generally introduces bias because the solution is pulled toward values favored by the penalty.

In return, it can substantially reduce variance and sensitivity to noise.

This creates a fundamental tradeoff:

\[ \boxed{ \text{slightly biased but stable} \quad\text{versus}\quad \text{unbiased but highly variable} }. \]

Least Squares with Constraints

Parameters may be subject to constraints such as

\[ \theta_j\ge0. \]

Then the problem becomes

\[ \operatorname*{minimize}_{\boldsymbol{\theta}} \|\mathbf{y}-X\boldsymbol{\theta}\|_2^2 \]

subject to the stated restrictions.

Nonnegative least squares is a common example.

Why Constraints Matter

In physical estimation problems, negative values may be impossible for quantities such as:

Constrained least squares incorporates such knowledge directly into the estimation problem.

Recursive Least Squares

Sometimes observations arrive sequentially rather than all at once.

Recursive least-squares methods update the parameter estimate as new data become available without solving the full problem from scratch each time.

This is useful in:

Batch Versus Sequential Estimation

Batch least squares uses all available observations at once.

Sequential least squares updates the estimate as observations arrive.

Both are built on the same principle of minimizing accumulated squared prediction errors.

Least Squares and Experimental Design

The precision of parameter estimates depends on the structure of \(X\).

Experimental design can therefore improve estimation by choosing conditions that make the columns of \(X\) more independent and informative.

In nonlinear problems, the same idea applies to the sensitivity matrix \(J\).

More Observations Are Not Always Better

Additional observations improve estimation only when they contribute useful information.

Repeating nearly identical measurements can reduce random uncertainty but may do little to resolve parameter correlations or rank deficiency.

Informative diversity in the design can matter more than raw data volume.

Checking a Least-Squares Implementation

A robust implementation should be tested with synthetic problems for which the answer is known.

Useful checks include:

Common Error: Solving \(X\boldsymbol{\theta}=\mathbf{y}\) Exactly

In an overdetermined noisy problem, there may be no exact solution.

Least squares does not require

\[ X\boldsymbol{\theta}=\mathbf{y}. \]

Instead, it minimizes the residual norm:

\[ \|\mathbf{y}-X\boldsymbol{\theta}\|_2. \]

Common Error: Assuming the Residual Must Be Zero

A nonzero residual is normal when observations contain noise or the model is approximate.

The relevant question is whether the residual is as small as the model allows and whether its remaining structure is consistent with the assumed errors.

Common Error: Using the Normal Equations Blindly

The normal equations are mathematically correct under appropriate rank conditions, but forming \(X^TX\) can magnify conditioning problems.

QR or SVD methods are often preferable for numerical work.

Common Error: Ignoring Rank

If \(X\) is rank deficient, the parameter vector is not uniquely determined.

Numerical software may still return one answer, but that answer should not be interpreted as uniquely identified by the data.

Common Error: Ignoring Weights

If measurement uncertainties differ strongly, unweighted least squares can give disproportionately noisy observations too much influence.

Weighting should reflect the measurement model whenever justified.

Common Error: Reporting Only the Best-Fit Parameters

A complete least-squares analysis should include more than \(\hat{\boldsymbol{\theta}}\).

Also inspect:

A Reliable Linear Least-Squares Workflow

  1. Write the model in the form \(\mathbf{y}\approx X\boldsymbol{\theta}\).
  2. Check units and parameter scaling.
  3. Inspect the rank and conditioning of \(X\).
  4. Choose weights if observation uncertainties differ.
  5. Solve using a numerically stable method such as QR or SVD.
  6. Compute fitted values and residuals.
  7. Verify the orthogonality condition \(X^T\hat{\mathbf{r}}\approx0\).
  8. Inspect residual structure.
  9. Estimate parameter uncertainty.
  10. Validate the fitted model where possible.

A Reliable Nonlinear Least-Squares Workflow

  1. Define the nonlinear forward model \(F(\boldsymbol{\theta})\).
  2. Define the residual vector.
  3. Check identifiability and parameter scaling.
  4. Choose initial parameter values.
  5. Compute or approximate the Jacobian.
  6. Use Gauss-Newton, Levenberg-Marquardt, or another suitable solver.
  7. Repeat from multiple starts when necessary.
  8. Inspect convergence and residual diagnostics.
  9. Assess local curvature and uncertainty.
  10. Test the fit on independent or synthetic data.

Practice 1: Residual Vector

Let

\[ \mathbf{y} = \begin{bmatrix} 5\\ 8 \end{bmatrix}, \qquad X\boldsymbol{\theta} = \begin{bmatrix} 4\\ 10 \end{bmatrix}. \]

Compute the residual vector.

Practice 2: Residual Sum of Squares

For

\[ \mathbf{r} = \begin{bmatrix} 1\\ -2\\ 2 \end{bmatrix}, \]

compute the residual sum of squares.

Practice 3: One-Parameter Least Squares

For the model

\[ y_i=\theta x_i, \]

suppose

\[ (x_1,y_1)=(1,2), \qquad (x_2,y_2)=(2,5). \]

Compute

\[ \hat{\theta} = \frac{\sum_i x_i y_i}{\sum_i x_i^2}. \]

Practice 4: Normal Equations

Starting from

\[ \Phi(\boldsymbol{\theta}) = \|\mathbf{y}-X\boldsymbol{\theta}\|_2^2, \]

state the normal equations satisfied by the least-squares estimate.

Practice 5: Orthogonality

At a linear least-squares solution, what relationship must hold between the residual vector and the columns of \(X\)?

Practice 6: Rank Deficiency

Suppose

\[ X= \begin{bmatrix} 1 & 2\\ 2 & 4\\ 3 & 6 \end{bmatrix}. \]

Explain why the two parameters are not uniquely identifiable.

Practice 7: Weighted Least Squares

One observation has standard deviation \(1\), while another has standard deviation \(4\).

Under inverse-variance weighting, what are their relative diagonal weights?

Practice 8: QR Versus Normal Equations

Give one numerical reason QR factorization is often preferred to explicitly solving the normal equations.

Practice 9: Nonlinear Least Squares

In the model

\[ y(t)=Ae^{-kt}, \]

explain why least-squares estimation of \(A\) and \(k\) is nonlinear.

Practice 10: Regularized Least Squares

What effect does the term

\[ \lambda\|\boldsymbol{\theta}\|_2^2 \]

have when added to an ordinary least-squares objective?

Practice Answers

Practice 1

\[ \mathbf{r} = \mathbf{y} - X\boldsymbol{\theta} = \begin{bmatrix} 5\\ 8 \end{bmatrix} - \begin{bmatrix} 4\\ 10 \end{bmatrix} = \boxed{ \begin{bmatrix} 1\\ -2 \end{bmatrix} }. \]

Practice 2

\[ \operatorname{RSS} = 1^2+(-2)^2+2^2 = 1+4+4 = \boxed{9}. \]

Practice 3

The numerator is

\[ \sum_i x_i y_i = 1(2)+2(5) = 12. \]

The denominator is

\[ \sum_i x_i^2 = 1^2+2^2 = 5. \]

Therefore,

\[ \boxed{ \hat{\theta} = \frac{12}{5} = 2.4 }. \]

Practice 4

\[ \boxed{ X^TX\hat{\boldsymbol{\theta}} = X^T\mathbf{y} }. \]

Practice 5

The residual must be orthogonal to every column of \(X\):

\[ \boxed{ X^T\hat{\mathbf{r}} = \mathbf{0} }. \]

Practice 6

The second column is twice the first:

\[ \begin{bmatrix} 2\\4\\6 \end{bmatrix} = 2 \begin{bmatrix} 1\\2\\3 \end{bmatrix}. \]

Therefore,

\[ \operatorname{rank}(X)=1<2. \]

The two parameter effects are not independent, so multiple parameter pairs can produce the same fitted values.

Practice 7

Inverse-variance weights are

\[ w_1=\frac{1}{1^2}=1, \]

and

\[ w_2=\frac{1}{4^2}=\frac{1}{16}. \]

Therefore, the first observation receives

\[ \boxed{16} \]

times the weight of the second.

Practice 8

Forming \(X^TX\) can square the condition number approximately, magnifying numerical sensitivity. QR avoids explicitly forming \(X^TX\) and is usually more stable.

Practice 9

The parameter \(k\) appears inside the exponential:

\[ e^{-kt}. \]

Therefore, the model is not linear in the unknown parameter vector \((A,k)\), so iterative nonlinear least-squares methods are generally needed.

Practice 10

The penalty discourages large parameter norms and can stabilize weak or poorly conditioned directions. It trades some bias for reduced sensitivity to noise and instability.

What to Remember

Least squares chooses parameters by minimizing squared model-data mismatch.

The central relationship is:

\[ \boxed{ \text{least squares} = \text{projection} + \text{optimization} + \text{uncertainty geometry} }. \]

Where We Go Next

Least-squares estimation converts model fitting into a precise optimization problem with a rich geometric and linear-algebraic structure.

The next lesson, Maximum-Likelihood Methods, broadens the estimation framework by starting from a probability model for the observed data. Least squares will appear as an important special case when measurement errors are Gaussian.