1

In linear regression we can use A:B to show the first order interaction of variable A and B. But it is hard to know what effect was caused by A and what was caused by B. So I want to understand how exactly A:B worked

Firebug
  • 19,076
  • 6
  • 77
  • 139

2 Answers2

5

it is hard to know what effect was caused by A and what was caused by B

Actually it is not hard, but impossible. First, interaction term in regression tells you on effect of A and B together, rather then about their individual effects. Second, regression per se does not tell you anything about causality.

Tim
  • 138,066
2

In R syntax A:B includes $A \times B$ in the regression model so

lm(y~A+B+A:B,data=mydata)

is fitting $$ Y=\beta_0+\beta_1A+\beta_2B+\beta_3AB+\epsilon $$ There is a discussion of this in the book "An Introduction to Statistical Learning" by James et al.

PM.
  • 627
  • 1
  • 4
  • 15
  • 1
    More precisely: it's $A\times B$ or if both A and B are discrete, it's all combinations of pairs of values of A and B that were found in data. The resulting model matrix is obtained through model.matrix function. – Tim May 23 '17 at 08:17