How do I exclude the intercept term in the 'stepwiselm' function?
6 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2019-6-4
编辑: MathWorks Support Team
2024-8-29
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?
采纳的回答
MathWorks Support Team
2024-7-29
编辑:MathWorks Support Team
2024-8-29
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:
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Model Building and Assessment 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!