Download presentation

Presentation is loading. Please wait.

Published byMarlon Woodward Modified about 1 year ago

1
Linear Regression 1Daniel Baur / Numerical Methods for Chemical Engineers / Linear Regression Daniel Baur ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften ETH Hönggerberg / HCI F128 – Zürich

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: 2Daniel Baur / 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 ε 3Daniel Baur / 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 4Daniel Baur / Numerical Methods for Chemical Engineers / Linear Regression

5
Parameter estimation 5Daniel Baur / Numerical Methods for Chemical Engineers / Linear Regression = confidence interval

6
Residuals 6Daniel Baur / Numerical Methods for Chemical Engineers / Linear Regression Outlier

7
Removing the Outlier 7Daniel Baur / 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 8Daniel Baur / 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. 9Daniel Baur / 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() ) 10Daniel Baur / 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 11Daniel Baur / Numerical Methods for Chemical Engineers / Linear Regression

12
Working with LinearModel and dataset Next, we construct the dataset from our variables 12Daniel Baur / 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 13Daniel Baur / 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 14Daniel Baur / 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 15Daniel Baur / 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 16Daniel Baur / Numerical Methods for Chemical Engineers / Linear Regression

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

18
Multiple linear regression Approximate model Residuals Least squares 18Daniel Baur / Numerical Methods for Chemical Engineers / Linear Regression

19
Exercise 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) 19Daniel Baur / 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 The LinearModel class only exists in Matlab 2012 or newer There are two versions of the assignment, one for Matlab 2012 and one for older versions, do one of the two 20Daniel Baur / Numerical Methods for Chemical Engineers / Linear Regression

21
Matlab 2012 and newer only Assignment (Matlab 2012 and newer only) 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 LinearModel.fit 5.Fit your model using LinearModel.fit, display the model output and plot the model. 21Daniel Baur / Numerical Methods for Chemical Engineers / Linear Regression

22
Assignment (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 9.The variables seem to show a rather random response, except for VISC which seems to mostly lie on one of the axes. Try and transform the system by defining logRUT = log10(RUT); logVISC = log10(VISC); 10.Define a new dataset and modelspec using the transformed variables. 22Daniel Baur / Numerical Methods for Chemical Engineers / Linear Regression

23
Assignment (Continued) 11.Fit a new model with the transformed variables and repeat the analysis from before. step 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: reduced_model = step(mdl2, 'nsteps', 20); Which variables have been removed and which of the remaining ones most likely have the largest influence? 23Daniel Baur / Numerical Methods for Chemical Engineers / Linear Regression

24
Assignment (older versions than Matlab 2012) 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 the matrix X using the variables from 1 except RUT and a column of ones. 3.Create the vector Y using RUT 4.Fit your model using regress and and alpha = Display the estimated values of beta and the confidence intervals 6.Are any of the values not significantly different from 0, i.e. does 0 lie inside the confidence interval? 24Daniel Baur / Numerical Methods for Chemical Engineers / Linear Regression

25
Assignment (Continued) 7.Generate the Tukey-Anscombe plot. Is there any indication of nonlinearity, non-constant variance or of a skewed distribution of residuals? plotmatrix(aspData(:,1:6), RUT) 8.Plot the response of all the variables using plotmatrix(aspData(:,1:6), RUT). The variables seem to show a rather random response, except for VISC. Try and transform the system by defining logRUT = log10(RUT); logVISC = log10(VISC); 9.Define a new X matrix and a new Y vector and regress again 10.Comment again on the estimates and their significance 11.Reproduce the Tukey-Anscombe plot. Did anything change? 25Daniel Baur / Numerical Methods for Chemical Engineers / Linear Regression

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google