# How to interpret A:B in linear regression? How to calculate A:B [duplicate]

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

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.

• Thanks for the answer, how the first order interaction was calculated? – user162385 May 23 '17 at 7:09

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.

• 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 8:17