[R] How are interaction terms computed in lm's result / problems with interaction terms in lm?

mviljamaa mviljamaa at kapsi.fi
Sun Sep 18 19:41:37 CEST 2016


I'm trying to use interaction terms in lm and for the following types of 
models:

fit3_hs <- lm(kidmomhsage$kid_score ~ kidmomhsage$mom_age + 
kidmomhsage$mom_hs + kidmomhsage$mom_age * 1)
fit3_nohs <- lm(kidmomhsage$kid_score ~ kidmomhsage$mom_age + 
kidmomhsage$mom_hs + kidmomhsage$mom_age * 0)

where you see the last term being the interaction term (it's 
mom_age*mom_hs where mom_hs takes values 0 or 1), the results are 
causing a bit of confusion.

fit3_hs returns:

Call:
lm(formula = kidmomhsage$kid_score ~ kidmomhsage$mom_age + 
kidmomhsage$mom_hs +
     kidmomhsage$mom_age * 1)

Coefficients:
         (Intercept)  kidmomhsage$mom_age
             70.4787               0.3261
  kidmomhsage$mom_hs
             11.3112


fit3_nohs returns:

Call:
lm(formula = kidmomhsage$kid_score ~ kidmomhsage$mom_age + 
kidmomhsage$mom_hs +
     kidmomhsage$mom_age * 0)

Coefficients:
kidmomhsage$mom_age   kidmomhsage$mom_hs
               3.368               11.568

Now why is (Intercept) term missing from the second one?
Also since in the first one the interaction term's coefficient should be 
added to the coefficient of mom_age, then is the return value of 
kidmomhsage$mom_age 0.3261 the sum of the coefficient of mom_age and the 
coefficient of the interaction term? Or would I need to produce the sum 
myself somehow?



More information about the R-help mailing list