How do I prevent a stepwise multiple linear regression to include interaction terms?
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Martijn
el 2 de Feb. de 2016
Comentada: Ram Ratan
el 19 de En. de 2021
Hello everyone,
I am trying to do exploratory regression to see which of my recorded variables can be used to predict output. I have 12 predictor variables (stored in X) and 1 outcome/response variable (in y).
The problem is, when I use a constant linear model
mdl1 = stepwiselm(X,y,'constant')
I only get one predictive term, which does not have a very high R_squared value (0.28).
However, if I start off with a linear model,
mdl2 = stepwiselm(X,y,'linear')
the stepwise regression gives me a result with various interaction terms, which seem to be impossible to interpret in this context, albeit with a larger R_squared value.
Is there a way that I can prevent the stepwise analysis from including these interaction terms, and just limit it to linear and quadratic terms? I have a feeling it might have something to do with the 'upper' argument, but I can not figure it out.
Thank you.
0 comentarios
Respuesta aceptada
Brendan Hamm
el 2 de Feb. de 2016
You are on the right track, it is the Upper input you are looking for:
mdl1 = stepwiselm(X,y,'constant','Upper','linear');
This will create a model which starts at the Constant model and will add only linear terms (no interactions). If however you would like there to be quadratic terms without interactions, us ehte purequadratic option.
mdl2 = stepwiselm(X,y,'constant','Upper','purequadratic');
If you need to further specify which terms are allowed and which aren't, this can be accomplished with Wilkonson notation. It is a bit more complicated, but as an example the following will allow quadratic terms (and lower orders) for only the first 2 predictors and linear terms for the next 2 predictors:
mdl3 = stepwiselm(X,y,'constant','Upper','y ~ x1^2 + x2^2 + x3 + x4');
1 comentario
Ram Ratan
el 19 de En. de 2021
thanks you very much for the clarification .. it made my day and saved a lot of time.. :)
Más respuestas (0)
Ver también
Categorías
Más información sobre Linear and Nonlinear Regression en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!