linear regression line of best fit. gradient = intercept =
DESCRIPTION
Consider the following graphTRANSCRIPT
Linear Regression
Line of Best Fit
22 )( xxnyxxyn
a
22
2
)( xxnxyxxy
b
Gradient =
Intercept =
Consider the following graph
d1
d2d3
d4
d6
d5
d8d7
We want a Line where d1 - d7 has the minimum distance
d1
d2d3
d4
d6
d5
d8d7
Just adding will not do it
A better method is to square the error
S = d21 + d2
2 + d23 + d2
5+ d24 + d2
6
We now need to find when ‘S’ is a ‘minimum’
S = d2i
= y – (ax + b)2
= y – ax - b2
= y – ax - b2
S
Ignoring the summation sign
=dsda
2(y – ax – b) . (-x)
=dsdb
2(y – ax – b) . (-1)
We need to find when these are = zero
=dsda
2(y – ax – b) . (-x)
0 = (y – ax – b) . (-x)
0 = (-yx + ax2 + bx) .
We need to find when these are = zero
=dsdb
2(y – ax – b) . (-1)
0 = (y – ax – b) . (-1)
0 = (- y + ax + b) .
This this gives us two equations
0 = (- y + ax + b)
0 = (-yx + ax2 + bx)
Rearranging gives
y = + ax + b
yx = + ax2 + bx
This is a set of simultaneous equations and can be solved for ‘a’ and ‘b’
Put back the Summation signs
y = ax + b
yx = ax2 + bx
This can be rearranged
yx = a. x2 + b.x
y = a. x + bn
Now solve for ‘a’ and ‘b’
22 )( xxnyxxyn
a
22
2
)( xxnxyxxy
b
Gradient =
Intercept =
Easy
Try an Example
n x y
Freq Inductive reactance
1 50 30
2 100 65
3 150 90
4 200 130
5 250 150
6 300 190
7 350 200 0
50
100
150
200
250
0 100 200 300 400
FrequencyIn
duct
ive
Rea
ctan
ce
Plot your data
Consider the following data
Not very straight
Make two new columns
Use Method of Least Squares
xy x2
1500 2500
6500 10000
13500 22500
26000 40000
37500 62500
57000 90000
70000 122500
n x y
Freq Inductive reactance
1 50 30
2 100 65
3 150 90
4 200 130
5 250 150
6 300 190
7 350 200
1400 855 212000 350000
22 )( xxnyxxyn
a
22
2
)( xxnxyxxy
b
Now for y = a.x + b
where
Use Method of Least Squares
xy x2
1500 2500
6500 10000
13500 22500
26000 40000
37500 62500
57000 90000
70000 122500
n x y
Freq Inductive reactance
1 50 30
2 100 65
3 150 90
4 200 130
5 250 150
6 300 190
7 350 200
1400 855 212000 350000
22 )( xxnyxxyn
a
Find ‘ a ‘
a = 7 x 212000 - 1400 x 855
7 x 350000
- (1400)2
a = 0.5857
Use Method of Least Squares
xy x2
1500 2500
6500 10000
13500 22500
26000 40000
37500 62500
57000 90000
70000 122500
n x y
Freq Inductive reactance
1 50 30
2 100 65
3 150 90
4 200 130
5 250 150
6 300 190
7 350 200
1400 855 212000 350000
Find ‘ b ‘
b = 855 x 350000 - 1400 x 212000
7 x 350000
- (1400)2
b = 5
22
2
)( xxnxyxxy
b
Use Method of Least Squares
xy x2
1500 2500
6500 10000
13500 22500
26000 40000
37500 62500
57000 90000
70000 122500
n x y
Freq Inductive reactance
1 50 30
2 100 65
3 150 90
4 200 130
5 250 150
6 300 190
7 350 200
1400 855 212000 350000
Line of best fit
50 34.29
100 63.57
150 92.86
200 122.14
250 151.43
300 180.71
350 210.00
Make two more columns
y = a.x + b
New values for ‘y’ are found from
Plot this new data on the original graph
0
50
100
150
200
250
0 50 100 150 200 250 300 350 400
Easy