The Neurophysiological Biomarker Toolbox (NBT)

# How to run linear regression analysis in Matlab

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:

$Y = a + b_1 X_1 + b_2 X_2$

This can be done typing:

 mdl = LinearModel.fit(X,Y);

assuming X is data matrix with $X_1$ and $X_2$ 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 $Y_2$ from the data $X_2$ using the model we fitted above. This is done using the 'predict' function.

Y2 = predict(mdl,X2);