Why donate?

- Tutorials, follow the NBT course

**Follow us **

You are here: Frontpage : Introduction » Tutorials » How to run linear regression analysis in Matlab

Table of Contents

Linear regression analysis can be done using the LinearModel class (which only exists from Matlab R2012b (Statistics toolbox) (as always it is good to check the help of this class type help LinearModel in the command window)

As an example, we here fit a very simple model:

This can be done typing:

mdl = LinearModel.fit(X,Y);

assuming X is data matrix with and along the columns, and Y is a vector of Y data.

Type

mdl

to see the outcome of the fit.

Next we want to predict from the data using the model we fitted above. This is done using the 'predict' function.

Y2 = predict(mdl,X2);