Empirical Model Building Ib: Objectives: By the end of this class you should be able to: Determine the coefficients for any of the basic two parameter.

Slides:



Advertisements
Similar presentations
Empirical Model Building I: Objectives: By the end of this class you should be able to: find the equation of the “best fit” line for a linear model explain.
Advertisements

Correlation and regression
Chapter 10 Re-Expressing data: Get it Straight
Regression Analysis Once a linear relationship is defined, the independent variable can be used to forecast the dependent variable. Y ^ = bo + bX bo is.
Use of regression analysis Regression analysis: –relation between dependent variable Y and one or more independent variables Xi Use of regression model.
Matrix Algebra Matrix algebra is a means of expressing large numbers of calculations made upon ordered sets of numbers. Often referred to as Linear Algebra.
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
Objectives (BPS chapter 24)
P M V Subbarao Professor Mechanical Engineering Department
EGR 105 Foundations of Engineering I
Regression Analysis Using Excel. Econometrics Econometrics is simply the statistical analysis of economic phenomena Here, we just summarize some of the.
Excel Part III Curve-Fitting, Regression Section 8 Fall 2013 EGR 105 Foundations of Engineering I.
1 Copyright © 2005 Brooks/Cole, a division of Thomson Learning, Inc. Summarizing Bivariate Data Introduction to Linear Regression.
Regression and Correlation
Excellence Justify the choice of your model by commenting on at least 3 points. Your comments could include the following: a)Relate the solution to the.
Engineering Computation Curve Fitting 1 Curve Fitting By Least-Squares Regression and Spline Interpolation Part 7.
Linear and generalised linear models
Stat 112: Lecture 13 Notes Finish Chapter 5: –Review Predictions in Log-Log Transformation. –Polynomials and Transformations in Multiple Regression Start.
Linear and generalised linear models Purpose of linear models Least-squares solution for linear models Analysis of diagnostics Exponential family and generalised.
Correlation and Regression Analysis
Spreadsheet Problem Solving
Chapter 5 Plotting Data Curve Fitting, Good Graphing Practices Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
Relationships Among Variables
Calibration & Curve Fitting
Lecture 3: Bivariate Data & Linear Regression 1.Introduction 2.Bivariate Data 3.Linear Analysis of Data a)Freehand Linear Fit b)Least Squares Fit c)Interpolation/Extrapolation.
Descriptive Methods in Regression and Correlation
Physics 114: Lecture 17 Least Squares Fit to Polynomial
Linear Regression.
Regression and Correlation Methods Judy Zhong Ph.D.
Exponentials, logarithms and rescaling of data Math 151 Based upon previous notes by Scott Duke- Sylvester as an adjunct to the Lecture notes posted on.
Inference for regression - Simple linear regression
LINEAR REGRESSION Introduction Section 0 Lecture 1 Slide 1 Lecture 5 Slide 1 INTRODUCTION TO Modern Physics PHYX 2710 Fall 2004 Intermediate 3870 Fall.
Introduction to MATLAB for Engineers, Third Edition Chapter 6 Model Building and Regression PowerPoint to accompany Copyright © The McGraw-Hill Companies,
On Page 234, complete the Prerequisite skills #1-14.
Biostatistics Unit 9 – Regression and Correlation.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Curve Fitting.
Descriptive Statistics II: By the end of this class you should be able to: describe the meaning of and calculate the mean and standard deviation of a sample.
Wednesday, May 13, 2015 Report at 11:30 to Prairieview.
Unit One Notes: Graphing How do we graph data?. Name the different types of graphs (charts).
Summary of introduced statistical terms and concepts mean Variance & standard deviation covariance & correlation Describes/measures average conditions.
Regression Regression relationship = trend + scatter
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers Chapter 5B Model.
11/20/2015ENGR 111A - Fall MatLab – Palm Chapter 5 Curve Fitting Class 14.1 Palm Chapter:
Worked Example Using R. > plot(y~x) >plot(epsilon1~x) This is a plot of residuals against the exploratory variable, x.
Reducing Equations to a Linear Form Andrew Robertson.
Correlation/Regression - part 2 Consider Example 2.12 in section 2.3. Look at the scatterplot… Example 2.13 shows that the prediction line is given by.
Graphing Most people at one time or another during their careers will have to interpret data presented in graphical form. This means of presenting.
Correlation & Regression Analysis
Polynomials, Curve Fitting and Interpolation. In this chapter will study Polynomials – functions of a special form that arise often in science and engineering.
Trees Example More than one variable. The residual plot suggests that the linear model is satisfactory. The R squared value seems quite low though,
1 Data Analysis Linear Regression Data Analysis Linear Regression Ernesto A. Diaz Department of Mathematics Redwood High School.
^ y = a + bx Stats Chapter 5 - Least Squares Regression
Week 2 Normal Distributions, Scatter Plots, Regression and Random.
CSE 330: Numerical Methods. What is regression analysis? Regression analysis gives information on the relationship between a response (dependent) variable.
Slide Copyright © 2009 Pearson Education, Inc. Types of Distributions Rectangular Distribution J-shaped distribution.
Thursday, May 12, 2016 Report at 11:30 to Prairieview
Linear Regression Essentials Line Basics y = mx + b vs. Definitions
The simple linear regression model and parameter estimation
Regression Analysis AGEC 784.
Sections Review.
distance prediction observed y value predicted value zero
Regression and Correlation
(Residuals and
CHAPTER 29: Multiple Regression*
MatLab – Palm Chapter 5 Curve Fitting
MatLab – 2D Plots 2 MATLAB has many built-in functions and commands to create various types of plots. Instructor notes: We start with an example of some.
^ y = a + bx Stats Chapter 5 - Least Squares Regression
Distance – Time Graphs Time is usually the independent variable (plotted on the x-axis) Distance is usually the dependent variable (plotted on the y-axis)
Reducing Equations to a Linear Form (Linear Law)
Presentation transcript:

Empirical Model Building Ib: Objectives: By the end of this class you should be able to: Determine the coefficients for any of the basic two parameter models Plot the data and resulting fits Calculate and describe residuals Palm, Section 5.5 Download file FnDiscovery.mat and load into MATLAB

1. Below are three graphs of the same dataset. What is the name and equation of the likely model that would match this data?

2. Here are the plots for another dataset. Name the model and write its equation for this case

Two Parameter Models Three simple models available Can “make” the latter two linear by taking logs of the equation The resulting equations suggest plots where the data should form a straight line if the model is true. What did you get for the three problems? Problem 1: linear y = mx + b Problem 2: power y = bx m Problem 3: exponential y = b10 mx Note: on problem 3, power is also nearly straight. However, if similar the exponential model is slightly preferred over the power model.

How would you define the Best Fit line?

Fitting data plot data (see points at left) looks linear equation:y = mx + b need to find the “best” m & b (the parameters) what makes the best line? usual approach – minimize the squared distance between the points and the line in the y direction the predicted value is often displayed as and pronounced “y-hat” Calculate the predicted values then minimize the sum of squares next we look at how to do this

Fitting a Linear equation via matrices e.g., Fitting the Spring data Model:y = mx + b Setup: 1. Design Matrix: >> X = [ones(length(Force),1), Force] 2. Response Vector >> Y= Length Fit: find the fitted parameters >> B = X \ Y B will be Predict: calculate predicted y for each x >> Lhat = X*B Plot: plot the result >> plot(Force, Length, ‘p’, Force, Lhat) (plus labels...)

A Linear Model & it’s Design Matrix y = b(1) + mx Linear Model: Design Matrix: >> X = [ ones(4, 1), L’ ] Matlab Syntax: (to convert a row vector of x values to a design matrix)

Fitting a Linear Equation in Matrix Form >> B = X\Y Matrix Equation: The Full Matrices MATAB Syntax for finding the parameter matrix

Linear Equation in Matrix Form fits: >> yhat = X*B residuals: >> res = Y - X*B

Fitting Transformed models Same as linear model except set up design matrix (X) and response vector (Y) using the transformed variables e.g., the capacitor discharge from last time straight line on a semilog plot  what model is implied? Exponential y = b10 mx or in this example V = b10 mt  what is its linearized (transformed) form log(V) = log(b) + mt

E.G., Fitting the capacitor discharge data Model: Last lecture we found the data was straight on a semilog plot implying an exponential model. For the base-ten model the equations are: V = b10 mt orlog(V) = log(b) + mt Setup: 1. Design Matrix: >> X = [ones(length(t),1), t] 2. Response Vector >> Y= log10(V) Fit: determine parameters >> B = X \ Y Predict: Predict: >> logVhat = X*B Untransform: >> Vhat = 10.^logVhat or Untransform >> b = 10^B(1), m = B(2) Predict >> Vhat = b*10.^(m.*t) Plot: either on linear or semilog plot

Plotting the capacitor discharge fit: semilog plot (left below) >> semilogy(t, V, ‘s’, t, Vhat) >> xlabel ‘time (s.)’, ylabel ‘Voltage’ >> legend(‘Experimental data’, … ‘Fit: V = (95.8)10^{-0.43*t}’) linear plot (right below) >> plot(t, V, ‘s’, t, Vhat) >> xlabel ‘time (s.)’, ylabel ‘Voltage’ >> legend(‘Experimental data’, … ‘Fit: V = (95.8)10^{-0.43*t}’) or

notes: linear plot preferred when y axis range is reasonable, semilog is used when detail at the low values is required I usually set variables m & b equal to the correct values to prevent mistakes full labeling required notice use of up carrot and curly brackets {} to superscript the powers in the legend as always: data is points, equation is a line

EquationFitParameters linear x vs. y b = B(1) m= B(2) power log(x) vs. log(y) b=10^B(1) m=B(2), exponential x vs. ln(y) b=e^B(1) m=B(2), x vs. log(y) b=10^B(1) m=B(2) Function Discovery (Review) 2. Fitting Parameters (m & b)

Fitting a 2-parameter models Model: Identify Functional Form Plot data is it linear ? is it monotonic? Log-Log (loglog(x,y)) semilog (semilogy(x,y)) look for straight graph Setup: Transform Data to Linearize Create X & Y matrices Fit linear model to transformed data Predict and Untransform Parameters to m & b Plot: Plot data and predicted equation. “Normal Data”“Transformed Data”

Steps in Function Discovery & Fitting Step 1: Model - Use graphs to determine if function is linear, exponential or power. Write down the equation to be fitted Step 2: Setup – create design matrix (X) & response vector (Y) for a model that will be linear (I.E., use transformed data for exponential and power models) Step 3: Fit – Determine parameters for a linear model (B = X\Y) Step 4: Predict – Untransform: if exponential or power untransform the b coefficient Apply model to predict y values Step 5: Plot - data and model – fix any problems encountered.

Class Exercise: For problems 3 (x2 vs. y2) from last class: What type of model will likely fit this data? (from last time) Determine the full model including parameter values. Plot the data and the fitted curve on one plot For problem 2 (x1 vs. y1), repeat the above.

Handout Problem 3: (students to try) uses: x2, y2 Fitting an exponential model: Model: y = b 10 mx or log(y) = log(b) + mx Setup: >> X = [ones(length(x2),1), x2’]; Y = log10(y2’); Fit: >> B = X \ Y B = Predict: >> y2hat =10.^(X*B) ( & Untransform) or >> m = B(2), b = 10^B(1) m = b = e+005 >> y2hat = b*10.^(m.*x2) Plot: >> plot(x2, y2, 's', x2, y2hat) the resulting prediction curve is not smooth. It is a good idea to smooth this out by simply adding more x points

Commands used to create a graph with a smooth prediction curve >> x2p = linspace(min(x2), max(x2),50); >> y2hat = b*10.^(m.*x2p); >> plot(x2, y2, 's', x2p, y2hat) >> legend(‘Experimental Data’, ‘Fit: y2 = (2.06*10^5)*10^{ *x2}’) >> xlabel ‘x2’, ylabel ‘y2’

Handout Problem 2: uses variables x1, y1, Fitting a power law model Model: log-log plot is linear  power model y1 = b(x1) m orlog(y1) = log(b) + m log(x1) Setup: >> X = [x1’./x1’, log10(x1’)]; Y = log10(y1’); Fit: >> B = X\Y B = Predict: >> y1hat = 10.^(X*B); or (& Untransform) >> m = B(2), b = 10^B(1) m = b = e+003 >> y1hat = b*x1.^m; Plot: >> plot(x1, y1, 's', x1, y1hat) >> legend(‘Experimental Data’, ‘Fit: y = 3582*x^{-0.976}’) >> xlabel ‘x1’, ylabel ‘y1’

Notice that this function is very nearly 1/x. It would be a good idea to fit this case and see if this simpler model works as well. Model: y1 = m(1./x1) Setup: Design Matrix: X = (1./x1)’ Response Vector Y = y1’ Fit: m = X \ Y Predict: Yhat = X*m Plot the results Extra, if time: How could you fit 1/x? 

xy Please plot this data and determine: the likely model parameters (m&b) (data is available in FnDiscovery.mat) plot resulting data and model

A Reminder of Some Nomenclature: y  response (dependent variable) vector y i  an individual response x  predictor (independent variable) vector x i  an individual predictor value  the predicted value (the fits)  an individual predicted value (fit)

Create x & y vectors (notice transpose operator): >> x = (1:9)’; y =[5, 8, 10, 20, 21, 29, 34, 36, 45]’; Model: Check linear plot >> plot(x,y,'s') Graph is linear, fit a simple linear model and calculate predicted values >> X = [x./x, x]; Y = y;% Set up: design and response matrix >> B = X \ Y% Fit: parameters B = % Untransform: not needed for linear model >> yhat = X*B;% Predict: calculate fitted values (the fits) >> plot(x, y, ‘p', x, yhat) % Plot: graph with labels >> xlabel 'x', ylabel 'y' >> legend('Experimental Data', 'Fit: y = *x')

Residuals: What is left after subtracting model from data: residuals = y – yhat Represents what is not fit by the model Ideal model should capture all systematic information Residuals should contain only random error Plot residuals and look for patterns

Now prepare a residuals plot Calculate residuals >> res = y – yhat Plot residuals vs. fits >> plot(yhat, res, 'p', yhat, 0*res) >> ylim([-4 4]) >> xlabel 'fitted value' >> ylabel 'residuals' Generally you make the y axis equal in both positive and negative direction (hence the ylim command above) notice zero line was also plotted for reference.

What to look for in a residual plot: 1. Does the residual plot look correct? data should vary about zero sum of residuals must equal zero 2. Are there any patterns in the residuals?, e.g., curvature: high center, low ends or l ow center, high ends changes is variability: the spread of the data in the y direction should be constant 3.How big are the residuals? (what is the magnitude of the y axis)

Thermocouple Calibration Data  is it linear? Plot this data Does it look linear? Fit a linear model Determine the residuals Prepare a residuals plot Is it linear? (data is available in FnDiscovery.mat) mV (mV) T(  C)

Model: Plot data to see if it is linear >> plot(mV, T, ’p’) >> ylabel ‘Temperature(C)’, xlabel ‘Voltage(mV)’ Plot is linear so model is y = b + m x Setup: >> X = [ones(length(mV),1), mV] Fit: >> B = X \T B = Predict: >> That = X*B Untransform: not necessary for a linear model Plot: >> plot(mV, T, ’p’, mV, That) plus labels and legend as we have done before Residuals: >> Res = T – That >> plot (That, Res, ‘p’, That, Res*0) >> ylabel ‘Residuals’ >> xlabel ‘Predicted Temperature (C)’