Presentation is loading. Please wait.

Presentation is loading. Please wait.

Linear Regression 1Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression Michael Sokolov ETH Zurich, Institut für Chemie- und.

Similar presentations


Presentation on theme: "Linear Regression 1Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression Michael Sokolov ETH Zurich, Institut für Chemie- und."— Presentation transcript:

1 Linear Regression 1Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression Michael Sokolov ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften ETH Hönggerberg / HCI F128 – Zürich E-Mail: michael.sokolov@chem.ethz.ch http://www.morbidelli-group.ethz.ch/education/index

2 Linear regression model  As inputs for our model we use two vectors x and Y, where  x i is the i-th observation  Y i is the i-th response  The model reads:  At this point, we make a fundamental assumption:  As outputs from our regression we get estimated values for the regression parameters: 2Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression The errors are mutually independent and normally distributed with mean zero and variance σ 2 : A regression is called linear if it is linear in the parameters!

3 The errors ε 3Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression  Since the errors are assumed to be normally distributed, the following is true for the expectation values and variance of the model responses

4 Example: Boiling Temperature and Pressure 4Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression

5 Parameter estimation 5Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression  = confidence interval

6 Residuals 6Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression Outlier

7 Removing the Outlier 7Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression

8 Goodness of fit measures  Coefficient of determination  Total sum of squares  Sum of squares due to regression  Sum of squares due to error 8Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression R 2 = 1   i = 0 R 2 = 0  regression does not explain variation of Y

9 The LinearModel and dataset classes  Matlab 2012 features two classes that are designed specifically for statistical analysis and linear regression  dataset  creates an object that holds data and meta-data like variable names, options for inclusion / exclusion of data points, etc.  LinearModel  is constructed from datasets or X, Y pairs (as with the regress function) and a model description  automatically does linear regression and holds all important regression outputs like parameter estimates, residuals, confidence intervals etc.  includes several useful functions like plots, residual analysis, exclusion of parameters etc. 9Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression

10 Classes in Matlab  Classes define a set of properties (variables) and methods (functions) which operate on those properties  This is useful for bundling information together with ways of treating and modifying this information mdl = LinearModel.fit(X,Y);  When a class is instantiated, an object of this class is created which can be used with the methods of the class, e.g. mdl = LinearModel.fit(X,Y); mdl.Coefficients  Properties can be accessed with the dot operator, like with structs (e.g. mdl.Coefficients ) plot(mdl)mdl.plot()  Methods can be called either with the dot operator, or by having an object of the class as first input argument (e.g. plot(mdl) or mdl.plot() ) 10Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression

11 Working with LinearModel and dataset  First, we define our observed and measured variables, giving them appropriate names, since these names will be used by the dataset and the LinearModel as meta-data 11Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression

12 Working with LinearModel and dataset  Next, we construct the dataset from our variables 12Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression

13 Working with LinearModel and dataset  After defining the relationship between our data (a model), we can use the dataset and the model to construct a LinearModel object  This will automatically fit the data, perform residual analysis and much more 13Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression

14 LinearModel: Plot  Now that we have the model, we have many analysis and plotting tools at our disposal 14Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression

15 Linear Model: Tukey-Anscombe Plot  Plot residuals vs. fitted values; These should be randomly distributed around 0 15Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression Outlier?

16 LinearModel: Cook’s Distance  The Cook’s distance measures the effect of removing one measurement from the data 16Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression

17 Linear Model: Removing the Outlier  After identifying an outlier, it can be easily removed 17Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression

18 Multiple linear regression  Approximate model  Residuals  Least squares 18Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression

19 Assignment 1  The data file asphalt.dat (online), contains data from a degradation experiment for different concrete mixtures [1]  The rutting (erosion) in inches per million cars (RUT) is measured as a function of  viscosity (VISC)  percentage of asphalt in the surface course (ASPH)  percentage of asphalt in the base course (BASE)  an operating mode 0 or 1 (RUN)  percentage (*10) of fines in the surface course (FINES)  percentage of voids in the surface course (VOIDS) 19Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression [1] R.V. Hogg and J. Ledolter, Applied Statistics for Engineers and Physical Scientists, Maxwell Macmillan International Editions, 1992, p.393.

20 Assignment 1 (Continued) 1.Find online the file readVars.m that will read the data file and assign the variables RUT, VISC, ASPH, BASE, RUN, FINES and VOIDS; You can copy and paste this script into your own file. 2.Create a dataset using the variables from 1. 3.Set the RUN variable to be a discrete variable ds.RUN = nominal(ds.RUN);  Assuming your dataset is called ds, use ds.RUN = nominal(ds.RUN); 4.Create a modelspec string  To include multiple variables in the modelspec, use the plus sign  How many dependent and independent variables does you problem contain? mdl1LinearModel.fit 5.Fit your model ( mdl1 ) using LinearModel.fit, display the model output and plot the model. 20Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression

21 Assignment 1 (Continued) 6.Which variables most likely have the largest influence? 7.Generate the Tukey-Anscombe plot. Is there any indication of nonlinearity, non-constant variance or of a skewed distribution of residuals? plotAllResponses 8.Plot the adjusted responses for each variable, using the plotAllResponses function you can find online. What do you observe? 9.Try and transform the system by defining  logRUT = log10(RUT); logVISC = log10(VISC); 10.Define a new dataset and modelspec using the transformed variables. 21Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression

22 Assignment 1 (Continued) 11.Fit a new model with the transformed variables and repeat the analysis from before (steps 6.-8.). step mdl3 = step(mdl2, 'nsteps', 20); 12.With the new model, try to remove variables that have a small influence. To do this systematically, use the function step, which will remove and/or add variables one at a time: mdl3 = step(mdl2, 'nsteps', 20);  Which variables have been removed and which of the remaining ones most likely have the largest influence?  Do you think variable removal is helpful to improve general conclusions (in other words avoid overfitting)?  How could you compare the quality of the three models? Is the root mean squared error of help?  How could you determine SST, SSR and SSE of your models (at least 2 options)?  How could you improve the models? Think about synergic effects. 22Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression


Download ppt "Linear Regression 1Michael Sokolov / Numerical Methods for Chemical Engineers / Linear Regression Michael Sokolov ETH Zurich, Institut für Chemie- und."

Similar presentations


Ads by Google