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

`Also if you, rather than doing what's done below, do:`
```
```
fit3 <- lm(kidmomhsage\$kid_score ~ kidmomhsage\$mom_age + kidmomhsage\$mom_hs + kidmomhsage\$mom_age * kidmomhsage\$mom_hs)
```
Then this gives the result:

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

Coefficients:
(Intercept)
110.542
kidmomhsage\$mom_age
-1.522
kidmomhsage\$mom_hs
-41.287
kidmomhsage\$mom_age:kidmomhsage\$mom_hs
2.391

```
Where the interaction term now seems properly interpretable. So perhaps this is the way to use interaction terms with lm.
```
```
However, in the above, is the coefficient 2.391 of kidmomhsage\$mom_age:kidmomhsage\$mom_hs actually only that for mom_hs == 1 in which case for mom_hs == 0 one would simply ignore the last coefficient?
```
```
And would one still need to perform summations of kidmomhsage\$mom_age and kidmomhsage\$mom_age:kidmomhsage\$mom_hs coefficients, i.e. the coefficient for kidmomhsage\$mom_age = -1.522 + 2.391?
```

On 2016-09-18 20:41, mviljamaa wrote:
```
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?
```
```
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
and provide commented, minimal, self-contained, reproducible code.
```