3
$\begingroup$

We are looking to use a "hierarchical" method of regression in order to input predictor variables in three steps. From what we can tell, the default method of regression is "stepwise," but we can't seem to find out how to fit a model hierarchically or with forced entry. Note that we are not trying to fit a Hierarchical Linear Model (HLM) / Multi-level Model (MLM), but are trying to change the method of regression to specify the order variables are entered into the model.

Specifically, we are trying to fit the following three models, with the two-way interactions in m2ai, and the three-way interaction in m3ai, being input as 2nd and 3rd steps, respectively:

m1ai <- lm(PostValUVAve ~ cPreValUVAve + Int + Gender + SciTeacher + cPreEff + cPreInt)
m2ai <- lm(PostValUVAve ~ cPreValUVAve + Int + Gender + SciTeacher + cPreEff + cPreInt +
                          cPreEff*Int + cPreInt*Int)
m3ai <- lm(PostValUVAve ~ cPreValUVAve + Int + Gender + SciTeacher + cPreEff + cPreInt +
                          cPreEff*Int + cPreInt*Int + cPreEff*Int*cPreInt)
$\endgroup$
12
  • 1
    $\begingroup$ The * is a shorthand for main effects plus interactions, which are indicated by :, e.g. cPreEff*Int = cPreEff + Int + cPreEff:Int. That means you have multiple copies of cPreEff, etc. in your formula. I think R catches these, but I think you'll want to change your * to :. $\endgroup$ Feb 20, 2015 at 21:29
  • 1
    $\begingroup$ How to do X in R is off-topic here (see our help center), but can be on-topic on Stack Overflow w/ a reproducible example. However, you've already done it, so it isn't clear what the issue is. You might be importing into R modeling strategies that are common in SPSS (I remember it lets you enter variables in blocks). If you want to do a series of nested model tests, you can use anova(m2ai, m3ai), anova(m1ai, m2ai0. $\endgroup$ Feb 20, 2015 at 21:38
  • 1
    $\begingroup$ I really don't follow that, @JoshuaRosenberg. If you've decided a-priori to fit m3ai, then you've already done that (m1ai & m2ai are superfluous, though). Just go w/ the model you already decided on. I don't see anything to do here. $\endgroup$ Feb 20, 2015 at 21:52
  • 1
    $\begingroup$ The term "hierarchical" in regression usually refers to something that I think is different to what you seem to be asking about (your question isn't sufficiently clear for me to be certain, though). If you're asking "how do I enter blocks of predictors in R?" that's straightforward (use update and specify the set of predictors) but for it to be on topic here the question would have to have a clearly statistical component (i.e. not simply be a request for R syntax). $\endgroup$
    – Glen_b
    Feb 20, 2015 at 23:59
  • 1
    $\begingroup$ Ah. You use anova to compare the sequence of nested models. e.g. mdl1 <- lm(y ~ x1) then mdl2 <- lm(y ~ x1+x2+x3) then anova(mdl1,mdl2). The anova function can take multiple such models and will put the results into a table. $\endgroup$
    – Glen_b
    Feb 22, 2015 at 1:08

1 Answer 1

7
$\begingroup$

No, the default method is Forced Entry. Hierarchical Regression can be done manually as follows (I'm not sure if you are using "*" when you mean to use ":" for the interaction and I'm going to mention "I" as a modeling tool in R, so here's a review:

m1 <- lm(formula = outcome ~ predictor1, data = data) # copy and paste for the next line
m2 <- lm(formula = outcome ~ predictor1 + predictor2, data = data) # edited version of above line
m3 <- lm(formula = outcome ~ predictor1 + predictor2 + predictor1:predictor2, data = data) # added an interaction to the equation
anova(m1, m2, m3) # this compares the output of your model fit

You can also use the update() function as follows:

m1 <- lm(formula = outcome ~ predictor1, data = data) # same as above
m2 <- update(m1, . ~ . + predictor2)
m3 <- update(m2, . ~ . + predictor1:predictor2)
anova(m1, m2, m3)

Now, try this code and see if it gives you the output you're looking for.

m1ai <- lm(PostValUVAve ~ cPreValUVAve + Int + Gender + SciTeacher + cPreEff + cPreInt)
m2ai <- update(m1ai, . ~ . + cPreEff:Int + cPreInt:Int)
m3ai <- update(m2ai, . ~ . + + IcPreEff:Int:cPreInt)
anova(m1ai, m2ai, m3ai)
$\endgroup$
2
  • $\begingroup$ What does "I" do? m2ai and m3ai throw errors ("variable lengths differ"), although they do not when I omit "I". $\endgroup$ Feb 21, 2015 at 16:31
  • $\begingroup$ I updated the example to remove the "I"'s $\endgroup$ Feb 21, 2015 at 17:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.