# R: What's the right way to add an interaction term in lm()? [closed]

I'm working with the Carseats data. I'm making a model to predict the sales of Carseats and I'd like to make an interaction term with Price and Competitor Price.

Is it as simple as

lm(Sales~Price*CompPrice,data=Carseats)


I know it's important to include the original predictors individually, too.

Yes, it is as simple! An equivalent but more explicit way of specifying the same model you did is as follows:

lm(Sales ~ Price + CompPrice + Price:CompPrice,data=Carseats)


The underlying model fitted by lm will be:

Sales = beta0 + beta1xPrice + beta2xCompPrice + beta3xPricexCompPrice + epsilon  (*)


Model (*) allows the effect of Price on Sales to depend on CompPrice:

Sales = beta0 + (beta1 + beta3xCompPrice)xPrice + beta2xCompPrice + epsilon


Indeed, the slope of Price depends on CompPrice.

Model (*) also allows the effect of CompPrice on Sales to depend on Price:

Sales = beta0 + beta1xPrice + (beta2 + beta3xPrice)xCompPrice + epsilon


Here, epsilon is an unknown (random) error term and Price and CompPrice are assumed to be continuous predictors.

• Woot! And, that means a regression with all the terms + an interaction is lm(Sales ~. Price*CompPrice,data=Carseats) – Sebastian Jan 17 at 20:45
• And then, if Price and CompPrice are statsig but Price:CompPrice is not - does that mean their interaction doesn't explain variance in Y? – Sebastian Jan 17 at 20:46
• In principle, the answer to your second comment is yes. But tests of interactions can have low power - some people perform them by relaxing the significance level to guard against this (e.g., increase the significance level from 0.05 to 0.10). – Isabella Ghement Jan 17 at 21:39