Creating Interaction Terms
You'll learn: How to mathematically construct interaction terms by multiplying predictor variables together in your regression model.
The Core Idea
An interaction term is created by simply multiplying two predictor variables together to form a new variable that you then include in your regression equation. If you have predictors X₁ and X₂, the interaction term is X₁ × X₂.
In mathematical notation, a regression with an interaction looks like:
y = β₀ + β₁X₁ + β₂X₂ + β₃(X₁ × X₂) + ε
The term (X₁ × X₂) is your interaction term, and β₃ is its coefficient.
Why Multiply?
Think of it like adjusting a thermostat based on both temperature and humidity. The "feels like" temperature isn't just temperature plus humidity—it's how they work together. Multiplication captures this combined effect: when X₁ increases, the impact of X₂ on your outcome changes proportionally.
Creating the Term
The mechanics are straightforward:
- Take the values of your first predictor
- Multiply them element-wise by your second predictor
- Add this new column to your dataset as an additional predictor
For example, if you're predicting house price with square_feet and age, you'd create a new variable square_feet_age = square_feet × age and include all three terms in your model.
This works for any predictor types: continuous × continuous, continuous × dummy variable, or even dummy × dummy (though interpretation differs for each combination).
Key Takeaway: Interaction terms are constructed by multiplying two predictors together element-wise, creating a new variable that captures how the effect of one predictor changes depending on the value of another.