Logo

Plot Interaction of Categorical FactorsΒΆ

In this example, we will vizualize the interaction between categorical factors. First, we will create some categorical data are initialized. Then plotted using the interaction_plot function which internally recodes the x-factor categories to ingegers.

In [1]: import numpy as np

In [2]: import matplotlib.pyplot as plt

In [3]: from statsmodels.graphics.factorplots import interaction_plot

In [4]: from pandas import Series

In [5]: np.random.seed(12345)

In [6]: weight = Series(np.repeat(['low', 'hi', 'low', 'hi'], 15), name='weight')

In [7]: nutrition = Series(np.repeat(['lo_carb', 'hi_carb'], 30), name='nutrition')

In [8]: days = np.log(np.random.randint(1, 30, size=60))

In [9]: plt.figure(figsize=(6, 6));

In [10]: interaction_plot(x=weight, trace=nutrition, response=days,
   ....:                   colors=['red', 'blue'], markers=['D', '^'], ms=10);
   ....: 
../../_images/interaction_plot_categorial.png

This Page