Linear Regression

Introduction

A data model explicitly describes a relationship between predictor and response variables. Linear regression fits a data model that is linear in the model coefficients. The most common type of linear regression is a least-squares fit, which can fit both lines and polynomials, among other linear models.

Before you model the relationship between pairs of quantities, it is a good idea to perform correlation analysis to establish if a linear relationship exists between these quantities. When you do so, be aware that variables can have nonlinear relationships, which correlation analysis cannot detect. For more information, see Linear Correlation.

The MATLAB Basic Fitting GUI helps you to fit your data, which enables you to calculate model coefficients and plot the model on top of the data. For an example of using this GUI, see Example: Using Basic Fitting GUI. You can also use the MATLAB functions polyfit and polyval to fit your data to a model that is linear in the coefficients. For an example of using these functions, see Example: Programmatic Fitting.

If you need to fit data with a nonlinear model, you can try transforming the variables to make them linear. You can use the Statistics Toolbox nlinfit function, or use Curve Fitting Toolbox™ functions.

In this chapter, you learn how to do the following:

Residuals and Goodness of Fit

Residuals are defined as the difference between the observed values of the response variable and the values that are predicted by the model. When you fit a model that is appropriate for your data, the residuals approximate independent random errors.

To calculate fit parameters for a linear model, the sum of the squares of the residuals are minimized to produce a good fit. This is called a least-squares fit.

You can gain insight into the "goodness" of a fit by visually examining a plot of the residuals: if the residual plot has a pattern (i.e., does not appear to have a random scatter), this indicates that the model does not properly fit the data.

Notice that the "goodness" of a fit must be determined in the context of your data. For example, if your goal of fitting the data is to extract coefficients that have physical meaning, then it is important that your model reflect the physics of the data. Understanding what your data represents and how it was measured is important when evaluating the goodness of fit.

Fitting Data with Curve Fitting Toolbox Functions

The Curve Fitting Toolbox software extends core MATLAB functionality by enabling the following data-fitting capabilities:

For more information, see the Curve Fitting Toolbox documentation.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS