I am running a regression equation and I want to enter in 12 indepdendent variables then stepwise enter 7 more independent variables and not have an origin.
-
DV is
shfl
. -
I want to enter in the following 12 independent dummy variables
ajan
bfeb
cmar
dapr
emay
fjun
gjul
haug
isep
joct
knov
ldec -
And then I want to enter in a stepwise fashion
slag6
slag7
slag8
slag9
slag10
slag11
slag12 -
And finally, I want there to be no origin.
I've done simple regression, but nothing quite like this that enters in the primary variables and step enters several more.
- How can such a model be specified using R?
Best Answer
I think you can set up your base model, that is the one with your 12 IVs and then use
add1()
with the remaining predictors. So, say you have a modelmod1
defined likemod1 <- lm(y ~ 0+x1+x2+x3)
(0+
means no intercept), thenwill add and test one predictor after the other on top of the base model.
More generally, if you know in advance that a set of variables should be included in the model (this might result from prior knowledge, or whatsoever), you can use
step()
orstepAIC()
(in theMASS
package) and look at thescope=
argument.Here is an illustration, where we specify a priori the functional relationship between the outcome, $y$, and the predictors, $x_1, x_2, \dots, x_{10}$. We want the model to include the first three predictors, but let the selection of other predictors be done by stepwise regression:
The results are shown below:
You can see that $x_3$ has been retained in the model, even if it proves to be non-significant (well, the usual caveats with univariate tests in multiple regression setting and model selection apply here -- at least, its relationship with $y$ was not specified).