Engineering 25
This presentation is the property of its rightful owner.
Sponsored Links
1 / 15

Bruce Mayer, PE Licensed Electrical & Mechanical Engineer [email protected] PowerPoint PPT Presentation


  • 84 Views
  • Uploaded on
  • Presentation posted in: General

Engineering 25. Linear RegressionTutorial. Bruce Mayer, PE Licensed Electrical & Mechanical Engineer [email protected] A plotting Grid. Lets Make some SCATTER. Example. Do On WhiteBoard. Example. [ eqn (7)]. The MATLAB code. % B. Mayer 20Feb07 * ENGR25

Download Presentation

Bruce Mayer, PE Licensed Electrical & Mechanical Engineer [email protected]

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Bruce mayer pe licensed electrical mechanical engineer bmayer chabotcollege

Engineering 25

LinearRegressionTutorial

Bruce Mayer, PE

Licensed Electrical & Mechanical [email protected]


A plotting grid

A plotting Grid

  • Lets Make some SCATTER


Bruce mayer pe licensed electrical mechanical engineer bmayer chabotcollege

Example


Do on whiteboard

Do On WhiteBoard

Example


Bruce mayer pe licensed electrical mechanical engineer bmayer chabotcollege

[eqn (7)]


The matlab code

The MATLAB code

% B. Mayer 20Feb07 * ENGR25

% Linear Regression Tutorial

% E25_Lin_Regress_Tutorial_0703.m

% %

clear

%

% Define Data Vectors for Croaking Frogs

Tf = [69.4, 69.7, 71.6, 75.2, 76.3, 78.6, 80.6, 80.6, 82, 82.6, 83.3, 83.5, 84.3, 88.6, 93.3];

% T in °F

CpH = [15.4, 14.7, 16, 15.5, 14.1, 15, 17.1, 16, 17.1, 17.2, 16.2, 17, 18.4, 20, 19.8];

% CPH is "Croaks per Hour"

%

% Plot CpH(T)

plot(Tf, CpH,'*'), xlabel('T °F'), ylabel('CpH (Croaks/Hr)'),...

Title('Frog Croaking vs Temperature'), grid

%

disp('Diplaying Scatter Plot - Hit any key to continue ')

pause

%

% Calc Linear Regression Coefficient terms using Absolute Temps

sumX = sum(Tf)

sumY = sum(CpH)

n = length(Tf)

sumXY = sum(Tf.*CpH)

sumXX = sum(Tf.*Tf)

%

% Calc optimum slope term m0

disp('Slope Parameter, m0')

m0 = (sumX*sumY - n*sumXY)/(sumX^2 - n*sumXX)

%

% Calc optimum intercept term b0

disp('Intercept Parameter, b0')

b0 = (sumY - m0*sumX)/n

%


The matlab code1

The MATLAB code

% Plot Regression Line

Tfmax = max(Tf);

Tfmin = min(Tf);

Tfplot = linspace(Tfmax, Tfmin);

% Calc CpH projected response using Regression Constanstants

CpHplot = m0*Tfplot + b0;

plot(Tf, CpH,'*', Tfplot, CpHplot), xlabel('T °F'), ylabel('CpH (Croaks/Hr)'),...

Title('Frog Croaking vs Temperature'), grid

%

disp('Diplaying °F Regression Plot - Hit any key to continue ')

pause

%

% Calc Goodness of Fit

%% the Minimized J value, J0

J0 = sum((m0*Tf+b0-CpH).^2)

%% Calc Sum of Sqs about the Mean

CpH_avg = mean(CpH)

S = sum((CpH-CpH_avg).^2)

%% Calc r-sqd

r_sqd = 1-J0/S;

%

%

disp('Coeff of Determination, r-sqd = ')

disp(r_sqd)


The regression plot

The Regression Plot


The matlab results

The MATLAB Results

Diplaying Scatter Plot - Hit any key to continue

sumX =

1.1996e+003

sumY =

249.5000

n =

15

sumXY =

2.0090e+004

sumXX =

9.6568e+004

Slope Parameter, m0

m0 =

0.2157

Intercept Parameter, b0

b0 =

-0.6152

Diplaying °F Regression Plot - Hit any key to continue

J0 =

12.6107

CpH_avg =

16.6333

S =

41.9933

Coeff of Determination, r-sqd =

0.6997


By excel

By Excel

  • Use to Check m0, b0, and r2


  • Login