Problem 30
Question
Least Squares Given \(n\) points \(\left(x_{1}, y_{1}\right),\left(x_{2}, y_{2}\right), \ldots\), \(\left(x_{n}, y_{n}\right)\) in the \(x y\)-plane, we wish to find the line \(y=m x+b\) such that the sum of the squares of the vertical distances from the points to the line is a minimum; that is, we wish to minimize $$ f(m, b)=\sum_{i=1}^{n}\left(y_{i}-m x_{i}-b\right)^{2} $$
Step-by-Step Solution
Verified Answer
Use calculus to derive equations, solve using normal equations, and find the line's slope \(m\) and y-intercept \(b\).
1Step 1: Define the Objective Function
The goal is to find the parameters \(m\) (slope) and \(b\) (y-intercept) for the line \(y = mx + b\) such that the function \(f(m, b) = \sum_{i=1}^{n} (y_i - mx_i - b)^2\) is minimized. This function represents the sum of the squared vertical distances from each point \((x_i, y_i)\) to the line.
2Step 2: Use Calculus to Minimize the Function
To find the minimum, we take the partial derivatives of \(f(m, b)\) with respect to \(m\) and \(b\) and set them equal to zero. This gives us two equations. 1. \( \frac{\partial f}{\partial m} = -2 \sum (y_i - mx_i - b)x_i = 0 \)2. \( \frac{\partial f}{\partial b} = -2 \sum (y_i - mx_i - b) = 0 \)
3Step 3: Solve the System of Equations
Solve the following system of linear equations obtained from the conditions in Step 2:1. \( \sum x_i y_i = m \sum x_i^2 + b \sum x_i \)2. \( \sum y_i = m \sum x_i + nb \)These can be solved simultaneously using substitution or matrix methods such as the normal equations in linear algebra.
4Step 4: Use Normal Equations to Find Values of m and b
Rewrite the system of equations in matrix form:\[\begin{pmatrix} \sum x_i^2 & \sum x_i \ \sum x_i & n \end{pmatrix} \begin{pmatrix} m \ b \end{pmatrix} = \begin{pmatrix} \sum x_i y_i \ \sum y_i \end{pmatrix}\]Solve for \(m\) and \(b\) by inverting the matrix or using techniques to find the solution.
5Step 5: Calculate m and b
After finding \(m\) and \(b\), substitute the values back into the equation of the line \(y = mx + b\) to obtain the best fit line.
6Step 6: Verify the Solution
Check if the line obtained indeed minimizes the sum of the squared distances by plugging a few points back into the line equation and confirming that the squared deviations are minimized.
Key Concepts
Objective FunctionPartial DerivativesSystem of Linear EquationsMatrix Method
Objective Function
In the context of least squares regression, the objective function is the mathematical expression we aim to minimize to find the best-fitting line for a set of data points. The formula used is \( f(m, b) = \sum_{i=1}^{n} (y_i - mx_i - b)^2 \). Here,
- \(m\) represents the slope of the line,
- \(b\) is the y-intercept,
- \((x_i, y_i)\) are the given data points,
- The expression \((y_i - mx_i - b)^2 \) represents the square of the distance from each point to the line.
Partial Derivatives
Once the objective function is defined, the next step is to find its minimum by using calculus. This involves taking the partial derivatives of the function with respect to its parameters, \(m\) and \(b\). A partial derivative measures how the function changes as one of the variables changes, while keeping others constant. For our function,
- The partial derivative with respect to \(m\) is \( \frac{\partial f}{\partial m} = -2 \sum (y_i - mx_i - b)x_i = 0 \).
- The partial derivative with respect to \(b\) is \( \frac{\partial f}{\partial b} = -2 \sum (y_i - mx_i - b) = 0 \).
System of Linear Equations
After taking partial derivatives and equating them to zero, we derive a system of linear equations. These equations are:
The equations can be solved using algebraic methods such as substitution. Alternatively, they can be resolved using a more streamlined mathematical approach known as the matrix method. These solutions give us the critical values for the least squares fitting line.
- \( \sum x_i y_i = m \sum x_i^2 + b \sum x_i \)
- \( \sum y_i = m \sum x_i + nb \)
The equations can be solved using algebraic methods such as substitution. Alternatively, they can be resolved using a more streamlined mathematical approach known as the matrix method. These solutions give us the critical values for the least squares fitting line.
Matrix Method
The matrix method is a powerful tool for solving systems of equations, especially in linear regression problems like least squares. We express the system of linear equations in a compact form using matrices:\[\begin{pmatrix} \sum x_i^2 & \sum x_i \\sum x_i & n \end{pmatrix} \begin{pmatrix} m \b \end{pmatrix} = \begin{pmatrix} \sum x_i y_i \\sum y_i \end{pmatrix}\]In this setup:
- The first matrix is called the coefficient matrix.
- The second is the vector of unknowns \(m\) and \(b\).
- The third is the result vector from our equations.
Other exercises in this chapter
Problem 30
Show that if \(w=f(r-s, s-t, t-r)\) then $$ \frac{\partial w}{\partial r}+\frac{\partial w}{\partial s}+\frac{\partial w}{\partial t}=0 $$
View solution Problem 30
In Problems 27-32, describe geometrically the domain of each of the indicated functions of three variables. $$ f(x, y, z)=\frac{\left(144-16 x^{2}-16 y^{2}+9 z^
View solution Problem 30
The temperature in degrees Celsius on a metal plate in the \(x y\)-plane is given by \(T(x, y)=4+2 x^{2}+y^{3}\). What is the rate of change of temperature with
View solution Problem 30
Let \(w=x_{1} x_{2} \cdots x_{n}\). (a) Maximize \(w\) subject to \(x_{1}+x_{2}+\cdots+x_{n}=1\) and all \(x_{i}>0 .\) (b) Use part (a) to deduce the famous Geo
View solution