5.4.1.1. statsmodels.sandbox.formula.interactions

statsmodels.sandbox.formula.interactions(terms, order=[1, 2])[source]

Output all pairwise interactions of given order of a sequence of terms.

The argument order is a sequence specifying which order of interactions should be generated – the default creates main effects and two-way interactions. If order is an integer, it is changed to range(1,order+1), so order=3 is equivalent to order=[1,2,3], generating all one, two and three-way interactions.

If any entry of order is greater than len(terms), it is effectively treated as len(terms).

>>> print interactions([Term(l) for l in ['a', 'b', 'c']])
<formula: a*b + a*c + b*c + a + b + c>
>>>
>>> print interactions([Term(l) for l in ['a', 'b', 'c']], order=list(range(5)))
<formula: a*b + a*b*c + a*c + b*c + a + b + c>
>>>