Interaction Plot

tags: #statistics/inferential/anova/two_way

We can visualize the joint effect of two categorical predictors on a quantitative continuous DV using interaction plots.

How do we plot interaction plots?

Example:

Here we are showing the effect of dosage (FACTOR A) on males vs females (FACTOR B), where y is the measure of the efficacy of the drug dosage:

Screen Shot 2023-02-20 at 6.35.16 PM.png500

How can we interpret this?


Interaction Plots in Python

To create an interaction plot for a two-way ANOVAin Python, you can use the interaction_plot function from the statsmodels.graphics.factorplots module:

Import libraries
import matplotlib.pyplot as plt
from statsmodels.graphics.factorplots import interaction_plot
Plot Interaction After Running ANOVA
# create the interaction plot
fig, ax = plt.subplots(figsize=(8, 6))
interaction_plot(x=data['Factor1'], 
                 trace=data['Factor2'], 
                 response=data['DV'], 
                 colors=['red', 'blue'], 
                 markers=['D', '^'], 
                 markersize=10, 
                 ax=ax)
ax.set_xlabel('Factor 1')
ax.set_ylabel('DV')
ax.set_title('Interaction Plot')
plt.show()

Powered by Forestry.md