Docsity

Regression Analysis: Least Squares Method and Goodness of Fit, Slides of Calculus for Engineers

Partial preview of the text

Download Regression Analysis: Least Squares Method and Goodness of Fit and more Slides Calculus for Engineers in PDF only on Docsity!

Engr/Math/Physics 25

Chp6 MATLAB

Regression

Learning Goals cont

  • Use Regression Analysis as quantified by

the “Least Squares” Method

  • Calculate
    • Sum-of-Squared Errors (SSE or J)
      • The Squared Errors are Called “Residuals”
    • “Best Fit” Coefficients
    • Sum-of-Squares About the Mean (SSM or S)
    • Coefficient of Determination (r 2 )
  • Scale Data if Needed
    • Creates more meaningful spacing

Scatter on plots on XY-Plane

  • A scatter plot usually shows how an EXPLANATORY, or independent, variable affects a RESPONSE, or Dependent Variable
  • Sometimes the SHAPE of the scatter reveals a relationship - Shown Below is a Conceptual Scatter plot that could Relate the RESPONSE to some EXCITITATION

Linear Fit by Guessing

  • The previous plot looks sort of Linear
  • We could use a Ruler to draw a y = mx+b line thru the data
  • But
    • which Line is BETTER?
    • and WHY?

Least Squares

δ y

( x (^) k , yk )

h

y (^) L = mxk + b

m

y b x (^) L k

−

δ x

 To make a Good Fit, MINIMIZE the |GUESS − data | distance by one of

[ ( ) ]

( ) ( )

2 2

2

2

x y

x y h

y mx b y

x m

y b x

k k

k

k

δ δ

δ δ

δ

δ

⋅

= + −

 

  

 −

−

data

Best Guess-y

Best Guess-x

Least Squares cont

  • MATLAB polyfit Minimizes the VERTICAL distances; i.e.:

( )

∑(^ )

∑

=

=

= + −

=

n

k

k k

n

k

k

J mx b y

J y

1

2

1

2 δ

 Note that The Function J contains two Variables; m & b  Recall from MTH that to MINIMIZE a Function set the 1 st^ (partial) Derivative(s) to Zero

Least Squares cont

  • In This Case

( )^2

2 2

10 11

0 2 5 6

    • −

= + − + + − m b

J m b m b

 Solving these Eqns for m & b yields

  • m = 9/
  • b = 11/  This produces the best fit Line

 Taking ∂J/∂m = 0, and ∂J/∂b = 0 yields

x y 0 2 5 6 10 11

30 6 38

250 30 280

  • =

  • = m b

m b

6

11 10

9 y = x +

Goodness of Fit

  • The Distance from The Best-Fit Line to the Actual Data Point is called the RESIDUAL
  • For the Vertical Distance the Residual is just δy

 If the Sum of the Residuals were ZERO, then the Line would Fit Perfectly  Thus J, after finding m & b, is an Indication of the Goodness of Fit

[ ( ) ]

2

δ y = mxk + b − y k

∑(^ )

∑

=

= = + −

= n k k k

n k k

J mx b y

J y

1

2

1

δ^2

Goodness of Fit cont

  • The Mean-Scaling Quantity is the Actual- Data Relative to the Actual-Mean

 Finally the Scaled Fit-Metric, “r-squared’

( )

2

1

∑

n

k

S yk y

( )

∑^ (^ )

∑

=

=

−

  • − = −

= −

n

k

k

n

k

k k

y y

mx b y r

S

J r

1

2

1

2 2

2

1

1

 As before the Squaring Ensures that all Terms in the sum are POSITIVE

r 2 = Coeff of Determination

  • The r^2 Value is Also Called the COEFFICIENT OF DETERMINATION

r = 1 − J S

2

  • J ≡ Sum of Residual (errors)
    • May be Zero or Positive
  • S ≡ Data-to-Mean Scaling Factor
    • Always Positive if >1 Data-Pt and data not “perfectly Horizontal”

 If J = 0, then there is NO Distance Between the calculated Line and Data

 Thus if J = 0, then r 2 = 1; so r 2 = 1 (or 100%) indicates a PERFECT FIT

Norm of Residuals

  • MATLAB uses the Norm of Residuals as a Measure of Goodness of Fit
  • The Norm of Residuals, NR , is simply the SqRt of J: ( )

∑^ (^ )

∑

=

=

= + −

= = −

n k R k k

n R k L k

N mx b y

N J y y

1

2

1

2

 Thus r 2 in Terms of NR :

 As a Measure of Goodness of Fit as the FIT Approaches Perfection J →0 so :

0

1

2

→

→

N R

r

r^2 = 1 − ( NR )^2 S

r (^) N=R (^1) vs r −( N (^2) → R ) S = 1 − J S 2 2

 Notice that r^2 is a RELATIVE Measure

→ it’s NORMALIZED to the WORST

CASE Value of J which is S

  • Thus r 2 can be expressed at PERCENTAGE withOUT Units

 N R is an ABSOLUTE measure that

Technically Requires that it be stated

with SAME UNITS as the dependent

variable, y

r^2 ⇒ %

NR ⇒ Sec, m, °F,Teslas, V, etc.

Data Scaling - Normalization

  • The Significance of ANY Data Set Can be Improved by Normalizing
  • Normalize ≡ Scale Data such that the Values run: - 0 → - 0% → 100% - Steps to Normalization
  1. Find the MAX & MIN values in the Data Set; e.g.,
  • z (^) max & z (^) min
  1. Calculate the Data Range, R (^) D
  • R (^) D = (z (^) max – z (^) min )
  1. Calc the Individual Data Differences Relative to the MIN
  • Δz (^) k = z (^) k - z (^) min

Data Scaling – Normailzation cont

  1. Finally, Scale the Δzk relative to R (^) D
  • Ψk = Δz (^) k /R (^) D
  1. Scale the corresponding “y” values in the Same Manner to produce say, Φk
  2. Plot Φk vs Ψk on x & y scales that Run from 0→ - Example - Do Frogs Croak More on WARM Nites?

Temperature(ºF) Croaks/Hr 88.6 20. 71.6 16. 93.3 19. 84.3 18. 80.6 17. 75.2 15. 69.7 14. 82.0 17. 69.4 15. 83.3 16. 78.6 15. 82.6 17. 80.6 16. 83.5 17. 76.3 14.