Interpreting the Coefficients of a Regression with an Interaction Term (Part 2)

A Detailed Explanation

Vivekananda Das
7 min readAug 16, 2024
Photo by Choong Deng Xiang on Unsplash

This article discusses how to interpret the coefficients of the predictors of a linear model that includes a two-way interaction between two continous predictors or two binary predictors.

This article is a continuation of the following article which discusses the interpretation of the coefficients of the predictors of a linear model that includes a two-way interaction between a continuous predictor and a binary predictor.

Interaction between two continuous predictors

Let’s consider a hypothetical example in which we are predicting Salary of employees in a particular profession based on their years of experience and years of education — two continuous predictors — and an interaction between them.

The model can be written as:

Salary = b0 + b1 * Experience + b2 * Education + b3 * Experience * Education (1)

For this example, I will generate some fake data and estimate the model in R:

# Set the seed 
set.seed(123)

# Generate data for Experience (in years) and Education (in years)
n <- 10000 # Number of observations
Experience <- round(runif(n, 0, 20), 1) # Experience between 0 and 20 years
Education <- sample(16:24, n, replace = TRUE) # Education as an integer between 16 and 24 years

# Define the coefficients
beta_0 <- 30000 # Intercept
beta_1 <- 2000 # Coefficient for Experience
beta_2 <- 1500 # Coefficient for Education
beta_3 <- 300 # Coefficient for Interaction

# Generate Salary using the model
Salary <- beta_0 + beta_1 * Experience + beta_2 * Education + beta_3 * Experience * Education

# Add some random noise to make the data more realistic
Salary <- Salary + rnorm(n, mean = 0, sd = 5000)

# Combine into a dataframe
data <- data.frame(Experience, Education, Salary)

# Estimate the model
model <- lm(Salary ~ Experience * Education, data = data)
summary(model)
Results of the estimated model (screenshot from RStudio)

So, the estimated coefficients are:

b0 (intercept) = 30293.391

b1 (coefficient of Experience) = 2027.885

b2 (coefficient of Education) = 1482.503

b3 (coefficient of Experience * Education) = 298.573

Interpretation of b0:

The intercept represents the predicted (average) base Salary (which is $30293.391) when both Experience and Education are 0.

However, in this case, having 0 years of Education isn’t realistic because education levels in our dataset range from 16 to 24 years. Therefore, the intercept doesn’t have a meaningful real-world interpretation by itself.

Instead, it’s the starting point for calculating salary in the context of the regression equation. It essentially adjusts the salary prediction based on the values of other variables in the model.

Interpretation of b1:

In this model, b1 (the coefficient of Experience) shows how much ($2027.885) salary is, on average, associated with each additional year of Experience when Education is 0.

This is because when Education is 0, the model in equation (1) essentially reduces to:

Salary = b0 + b1 * Experience

However, having zero education isn’t realistic given that our education variable ranges from 16 to 24 years. Therefore, direct interpretation of b1 isn’t practically meaningful.

[Note: In a linear model without an interaction term, the coefficient of Experience would tell us the average increase in Salary for each additional year of Experience, assuming Education is held constant at any level, not necessarily zero.]

Interpretation of b2:

In this model, b2 (the coefficient of Education) shows how much ($1482.503) Salary is, on average, associated with each additional year of Education when Experience is 0.

This is because the model essentially reduces to:

Salary = b0 + b2 * Education

[Note: In a linear model without an interaction term, the coefficient of Education would tell us the average increase in Salary for each additional year of Education, assuming Experience is held constant at any level, not necessarily zero.]

Interpretation of b3:

The interaction term indicates how the association between Experience and Salary depends on Education, and vice versa. Specifically, for every additional year of Education, the association between Experience and Salary, on average, increases by $298.573, and for every additional year of Experience, the association between Education and Salary, on average, increases by $298.573.

This means that the association between Experience and Salary is stronger when Education is higher, and similarly, the association between Education and Salary is stronger when Experience is higher.

Interaction between two binary predictors

Let’s consider another hypothetical example in which we are predicting Salary of employees in a particular profession based on their Job Type (Part Time and Full Time) and Certification Status (No Certification and Certification) — two binary predictors — and an interaction between them.

Here is how the binary predictors are coded:

Job Type == 1 if someone works Full Time and Job Type == 0 if someone works Part Time

Certifaction Status == 1 if someone has Certification and Certification Status == 0 if someone has No Certification

The model we are estimated can be written as:

Salary = b0 + b1 * Job Type + b2 * Certification + b3 * Job Type * Certification (2)

Again, I will generate some fake data and estimate the model in R:

# Load necessary packages
library(dplyr)

# Set seed
set.seed(123)

# Generate data with 10,000 observations
n <- 10000 # Number of observations

data <- data.frame(
Job_Type = sample(0:1, n, replace = TRUE), # 0 = Part-time, 1 = Full-time
Certification = sample(0:1, n, replace = TRUE) # 0 = No Certification, 1 = Certification
)

# Create a salary variable based on a hypothetical model
data <- data %>%
mutate(
Salary = 35000 +
7000 * Job_Type +
4500 * Certification +
3000 * Job_Type * Certification +
rnorm(n, mean = 0, sd = 5000) # Adding some random noise
)

# Estimate the model
model <- lm(Salary ~ Job_Type * Certification, data = data)

# Show the model summary
summary(model)
Results of the estimated model (screenshot from RStudio)

So, the estimated coefficients are:

b0 (intercept) = 34831.15

b1 (coefficient of Job Type) = 7189.05

b2 (coefficient of Certification) = 4629.10

b3 (coefficient of Job Type * Certification) = 2859.34

Interpretation of b0:

This is the predicted (average) Salary for someone with a part-time job and no certification (both Job Type and Certification are 0).

Interpretation of b1:

In this model, b1 (the coefficient of Job Type) shows the difference in predicted (average) salary ($7189.05) between those with Full Time Job (Job Type ==1) and Part Time Job (Job Type==0) when Certification is 0 (i.e., for those who have No Certification).

This is because when Certification is 0, the model in equation (2) essentially reduces to:

Salary = b0 + b1 * Job Type

Interpretation of b2:

In this model, b2 (the coefficient of Certification) shows the difference in predicted (average) salary ($4629.10) between those with Certification (Certification ==1 and No Certification (Certification==0) when Job Type is 0 (i.e., for those who have Part Time Job).

This is because when Job Type is 0 the model in equation (2) essentially reduces to:

Salary = b0 + b2 * Certification

Interpretation of b3:

In this model, b3 estimates the following:

[Average Salary for those with Certification and Full Time Job Average Salary for those with No Certification and Full Time Job] — [Average Salary for those with Certification and Part Time JobAverage Salary for those with No Certification and Part Time Job] = $2859.34

A simplified explanation of b3 is that it indicates how the association between Job Type and Salary changes depending on the Certification, and how the association between Certification and Salary changes depending on Job Type.

It is easier to understand the interpretation of b3 mathematically.

Let’s think about four groups depending on the values of Job Type and Certification and estimate salary for each group by replacing the values of the two predictors in equation (2):

Group #1: Part-time and No Certification (Job Type = 0, Certification = 0):

Salary = b0

Group #2: Full-time and No Certification (Job Type = 1, Certification = 0):

Salary = b0 + b1

Group #3: Part-time with Certification (Job Type = 0, Certification = 1):

Salary = b0 + b2

Group #4: Full-time with Certification (Job Type = 1, Certification = 1):

Salary = b0 + b1 + b2 + b3

Difference in average Salary between those with and without certification for full-time jobs:

(b0 + b1 + b2 + b3) − (b0 + b1) = b2 ​+ b3​

Difference in average Salary between those with and without certification for part-time jobs:

(b0 + b2) − b0 ​= b2​

The coefficient of the interaction (b3)​ term is the difference between the two differences:

(b2 + b3) − b2 = b3

--

--

Vivekananda Das
Vivekananda Das

Written by Vivekananda Das

Sharing synthesized ideas on Data Analysis in R, Data Literacy, Causal Inference, and Well-being | Assistant Prof @ UUtah | More: https://vivekanandadas.com

No responses yet