linear regression line of best fit. gradient = intercept =

23
Linear Regression Line of Best Fit

Upload: alaina-harrington

Post on 18-Jan-2018

229 views

Category:

Documents


0 download

DESCRIPTION

Consider the following graph

TRANSCRIPT

Page 1: Linear Regression Line of Best Fit. Gradient = Intercept =

Linear Regression

Line of Best Fit

Page 2: Linear Regression Line of Best Fit. Gradient = Intercept =

22 )( xxnyxxyn

a

22

2

)( xxnxyxxy

b

Gradient =

Intercept =

Page 3: Linear Regression Line of Best Fit. Gradient = Intercept =

Consider the following graph

Page 4: Linear Regression Line of Best Fit. Gradient = Intercept =
Page 5: Linear Regression Line of Best Fit. Gradient = Intercept =
Page 6: Linear Regression Line of Best Fit. Gradient = Intercept =

d1

d2d3

d4

d6

d5

d8d7

Page 7: Linear Regression Line of Best Fit. Gradient = Intercept =

We want a Line where d1 - d7 has the minimum distance

d1

d2d3

d4

d6

d5

d8d7

Page 8: Linear Regression Line of Best Fit. Gradient = Intercept =

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’

Page 9: Linear Regression Line of Best Fit. Gradient = Intercept =

S = d2i

= y – (ax + b)2

= y – ax - b2

Page 10: Linear Regression Line of Best Fit. Gradient = Intercept =

= y – ax - b2

S

Ignoring the summation sign

=dsda

2(y – ax – b) . (-x)

=dsdb

2(y – ax – b) . (-1)

Page 11: Linear Regression Line of Best Fit. Gradient = Intercept =

We need to find when these are = zero

=dsda

2(y – ax – b) . (-x)

0 = (y – ax – b) . (-x)

0 = (-yx + ax2 + bx) .

Page 12: Linear Regression Line of Best Fit. Gradient = Intercept =

We need to find when these are = zero

=dsdb

2(y – ax – b) . (-1)

0 = (y – ax – b) . (-1)

0 = (- y + ax + b) .

Page 13: Linear Regression Line of Best Fit. Gradient = Intercept =

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’

Page 14: Linear Regression Line of Best Fit. Gradient = Intercept =

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’

Page 15: Linear Regression Line of Best Fit. Gradient = Intercept =

22 )( xxnyxxyn

a

22

2

)( xxnxyxxy

b

Gradient =

Intercept =

Page 16: Linear Regression Line of Best Fit. Gradient = Intercept =

Easy

Try an Example

Page 17: Linear Regression Line of Best Fit. Gradient = Intercept =

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

Page 18: Linear Regression Line of Best Fit. Gradient = Intercept =

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

Page 19: Linear Regression Line of Best Fit. Gradient = Intercept =

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

Page 20: Linear Regression Line of Best Fit. Gradient = Intercept =

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

Page 21: Linear Regression Line of Best Fit. Gradient = Intercept =

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

Page 22: Linear Regression Line of Best Fit. Gradient = Intercept =

0

50

100

150

200

250

0 50 100 150 200 250 300 350 400

Page 23: Linear Regression Line of Best Fit. Gradient = Intercept =

Easy