Linear regression is a statistical modeling technique used to describe a continuous response variable as a function of one or more predictor variables. It can help you understand and predict the behavior of complex systems or analyze experimental, financial, and biological data.
Linear regression techniques are used to create a linear model. The model describes the relationship between a dependent variable
where
Types of Linear Regression
Simple linear regression (models using only one predictor): The general equation is:
![Plot showing linear regression line, response values (fatal traffic accidents per state), and predictor values (population of state).](https://au.mathworks.com/discovery/linear-regression/_jcr_content/mainParsys/band_1231704498_copy/mainParsys/columns_copy_copy/576c621e-2672-40ed-a0dc-e9e61b6f50d2/columns_copy/4a00ee99-d2e4-4625-991c-ded888e86b86/image_copy.adapt.full.medium.jpg/1701682029640.jpg)
Simple linear regression example showing how to predict the number of fatal traffic accidents in a state (response variable,
Multiple linear regression (models using multiple predictors): This regression has multiple
![Plot showing multiple linear regression, response values (MPG), and predictor values (Weight and Horsepower).](https://au.mathworks.com/discovery/linear-regression/_jcr_content/mainParsys/band_1231704498_copy/mainParsys/columns_copy_copy/576c621e-2672-40ed-a0dc-e9e61b6f50d2/columns_818208127_co/d3eff710-6ba1-4836-a581-e37f212d87f6/image_1583733776.adapt.full.medium.jpg/1701682029686.jpg)
Multiple linear regression example, which predicts the miles per gallon (MPG) of different cars (response variable,
Multivariate linear regression (models for multiple response variables): This regression has multiple
![Plot showing multivariate linear regression, response values (flu estimates for 9 regions), and predictor values (week of the year).](https://au.mathworks.com/discovery/linear-regression/_jcr_content/mainParsys/band_1231704498_copy/mainParsys/columns_copy_copy/576c621e-2672-40ed-a0dc-e9e61b6f50d2/columns_1633838249_c/26a1268b-9878-4fa0-ab83-8acb75f0c2b5/image_1583733776_cop.adapt.full.medium.jpg/1701682029730.jpg)
Multivariate linear regression example showing how to predict the flu estimates for 9 regions (response variables,
Multivariate multiple linear regression (models using multiple predictors for multiple response variables): This regression has multiple
![Equation for computing multiple responses Yi from multiple predictors Xi by using linear multivariate linear regression.](https://au.mathworks.com/discovery/linear-regression/_jcr_content/mainParsys/band_1231704498_copy/mainParsys/columns_copy_copy/576c621e-2672-40ed-a0dc-e9e61b6f50d2/columns_1354793617_c/9df4951e-6a3a-4373-b01b-f188a685475f/image_1583733776_cop.adapt.full.medium.jpg/1701682029774.jpg)
Multivariate multiple linear regression example that calculates the city and highway MPG (as response variables,
Applications of linear regression
Linear regressions have some properties that make them very interesting for the following applications:
- Prediction or forecasting: Use a regression model to build a forecast model for a specific data set. From the model, you can use regression to predict response values where only the predictors are known.
- Strength of the regression: Use a regression model to determine if there is a relationship between a variable and a predictor, and how strong this relationship is.
Linear regression with MATLAB
Engineers commonly create simple linear regression models with MATLAB. For multiple and multivariate linear regression, you can use the Statistics and Machine Learning Toolbox™ from MATLAB. It enables stepwise, robust, and multivariate regression to:
- Generate predictions
- Compare linear model fits
- Plot residuals
- Evaluate goodness-of-fit
- Detect outliers
To create a linear model that fits curves and surfaces to your data, see Curve Fitting Toolbox™.
Keep Exploring This Topic
Resources
Expand your knowledge through documentation, examples, videos, and more.
Discover More
- Linear Model Function in Statistics and Machine Learning Toolbox - Function
- Forecast Electrical Load Using the Regression Learner App (3:42) - Video
- Fitting with MATLAB: Statistics, Optimization, and Curve Fitting (38:37) - Video
- MATLAB Tools for Scientists - Introduction to Statistical Analysis (54:52) - Video
- Machine Learning with MATLAB Overview (3:02) - Video