How do I exclude the intercept term in the 'stepwiselm' function?

6 visualizaciones (últimos 30 días)
I am using the 'stepwiselm' function to fit my data, I would like to exclude the intercept term.
I noticed there is an 'Intercept' flag:
I use the following sample code:
load hald; X = ingredients; y = heat; lm = stepwiselm(X,y,... 'intercept', false)
I got the result 'lm':
Linear regression model: y ~ 1 + x1 + x4
Why do I still get the intercept term?
How do I exclude the intercept term in the result?

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 29 de Jul. de 2024
Editada: MathWorks Support Team el 29 de Ag. de 2024
1. The 'intercept' flag is intended to apply only to the initial model. In other words, you can specify the 'intercept' flag to be 'false' to exclude the intercept term in the initial model. However, the intercept term may still be added to the model during the computation.
2. The 'upper' model is a set of terms that could be added to the model. In other words, you can specify the 'upper' flag to prevent the intercept term from being added to the model during the computation.
The following sample code shows an example of how to exclude the intercept term in the end model:
load carsmall
X = [Acceleration,Weight];
y = MPG;
lm = stepwiselm(X,y,...
'upper','y~x1+x2',...
'intercept', false);
lm.Formula
>> y ~ x1 + x2
lm = stepwiselm(X,y,...
  'y~-1',...
  'upper','y~x1+x2-1');
lm.Formula >> y ~ x1 + x2
If you have many predictors, e.g. 100 predictors, and want the 'upper' to be with no intercept, you can either enter 'y~x1+...+x100-1', or enter a matrix such as 'eye(100,101)', which says to allow all single terms and not an intercept.
For more detailed information about how to use a matrix to specify the terms:

Más respuestas (0)

Productos


Versión

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by