The Least Squares Method is a mathematical technique used to find the best-fitting curve or line through a set of data points by minimizing the sum of the squares of the differences between observed values and predicted values.
Problem 1: Find the line of best fit for the following data points using the least squares method: (x,y) = (1,3), (2,4), (4,8), (6,10), (8,15).
Solution:
Here, we have x as the independent variable and y as the dependent variable. First, we calculate the means of x and y values denoted by X and Y respectively.
X = (1+2+4+6+8)/5 = 4.2
Y = (3+4+8+10+15)/5 = 8
xi
yi
X - xi
Y - yi
(X-xi)*(Y-yi)
(X - xi)2
1
3
3.2
5
16
10.24
2
4
2.2
4
8.8
4.84
4
8
0.2
0
0
0.04
6
10
-1.8
-2
3.6
3.24
8
15
-3.8
-7
26.6
14.44
Sum (Σ)
0 0 55 32.8 The slope of the line of best fit can be calculated from the formula as follows:
m = (Σ (X - xi)*(Y - yi)) /Σ(X - xi)2
m = 55/32.8 = 1.68 (rounded upto 2 decimal places)Now, the intercept will be calculated from the formula as follows:
c = Y - mX
c = 8 - 1.68*4.2 = 0.94Thus, the equation of the line of best fit becomes, y = 1.68x + 0.94.
Problem 2: Find the line of best fit for the following data of heights and weights of students of a school using the Least Squares method:
- Height (in centimeters): [160, 162, 164, 166, 168]
- Weight (in kilograms): [52, 55, 57, 60, 61]
Solution:
Here, we denote Height as x (independent variable) and Weight as y (dependent variable). Now, we calculate the means of x and y values denoted by X and Y respectively.
X = (160 + 162 + 164 + 166 + 168 ) / 5 = 164
Y = (52 + 55 + 57 + 60 + 61) / 5 = 57
xi
yi
X - xi
Y - yi
(X-xi)*(Y-yi)
(X - xi)2
160
52
4
5
20
16
162
55
2
2
4
4
164
57
0
0
0
0
166
60
-2
-3
6
4
168
61
-4
-4
16
16
Sum ( Σ )
0 0 46 40 Now, the slope of the line of best fit can be calculated from the formula as follows:
m = (Σ (X - xi)✕(Y - yi)) / Σ(X - xi)2
m = 46/40 = 1.15Now, the intercept will be calculated from the formula as follows:
c = Y - mX
c = 57 - 1.15*164 = -131.6Thus, the equation of the line of best fit becomes, y = 1.15x - 131.6
Practice Questions on Least Square Method
Question 1: Find the equation of the best-fit line for the data:
| x | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| y | 2 | 3 | 5 | 7 |
Question 2: Fit a straight line using least squares for:
| x | 10 | 20 | 30 | 40 |
|---|---|---|---|---|
| y | 25 | 28 | 32 | 35 |
Question 3: For the data:
| x | -2 | -1 | 0 | 1 | 2 |
|---|---|---|---|---|---|
| y | 4 | 1 | 0 | 1 | 4 |
(a) Find the least squares line.
(b) Comment on how well it fits the data.
Question 4: The following data represents the year and population (in thousands):
| x (year) | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| y (pop.) | 50 | 54 | 57 | 60 | 65 |
Fit a straight line and estimate the population in year 6.