Explain interaction term in regression

Using iris data for example

head(iris)
  Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa
5          5.0         3.6          1.4         0.2  setosa
6          5.4         3.9          1.7         0.4  setosa

We want to fit a multivariate linear regression with Sepal.Length as the outcome variable and Sepal.Width and Species as predictors. What is the difference between Sepal.Length ~ Sepal.Width + Species and Sepal.Length ~ Sepal.Width * Species?

The second formula includes an interaction term. When we use an interaction term, we assume that the effect of sepal width differs across species; that is, the slope of sepal width is different for each species. When we use the first formula, we assume that the effect of sepal width is the same across all species.

R code to ilustrate this

library(patchwork)
library(ggplot2)
library(dplyr)


## no interaction between width and species assumption
lm1  <- lm(Sepal.Length ~ Sepal.Width + Species, data=iris)

p1 <- iris |> 
  mutate(pred = predict(lm1)) |> 
  ggplot(aes(x = Sepal.Width, y = pred))+
  geom_line()+
  facet_wrap(~Species)+
  theme_bw()+
  scale_y_continuous(limits = c(4,8))

## interaction between width and species assumption
lm2  <- lm(Sepal.Length ~ Sepal.Width*Species, data=iris)

p2 <- iris |> 
  mutate(pred = predict(lm2)) |> 
  ggplot(aes(x = Sepal.Width, y = pred))+
  geom_line()+
  facet_wrap(~Species)+
  theme_bw()+
  scale_y_continuous(limits = c(4,8))

p1/
  p2

The upper figure show the outcome of the linear regression assumes no interaction between width and species. The bottom figure show the outcome of the linear regression assumes interaction between width and species.
NoteConclusion

As we can see, the slope for versicolor in the bottom figure clearly shows a difference between species, whereas the slopes for the three species in the top figure are the same.