Suppose I have a pandas dataframe:
df = pd.DataFrame({'x1': [0, 1, 2, 3, 4],
'x2': [10, 9, 8, 7, 6],
'x3': [.1, .1, .2, 4, 8],
'y': [17, 18, 19, 20, 21]})
Now I fit a statsmodels model using a formula (which uses patsy under the hood):
import statsmodels.formula.api as smf
fit = smf.ols(formula='y ~ x1:x2', data=df).fit()
What I want is a list of the columns of df that fit depends on, so that I can use fit.predict() on another dataset. If I try list(fit.params.index), for example, I get:
['Intercept', 'x1:x2']
I've tried recreating the patsy design matrix, and using design_info, but I still only ever get x1:x2. What I want is:
['x1', 'x2']
Or even:
['Intercept', 'x1', 'x2']
How can I get this from just the fit object?