linearmodels.iv.absorbing.Interaction.from_frame

static Interaction.from_frame(frame: DataFrame) Interaction[source]

Convenience function the simplifies using a DataFrame

Parameters:
frame: DataFrame

Frame containing categorical and continuous variables. All categorical variables are passed to cat and all other variables are passed as cont.

Returns:

Instance using the columns of frame

Return type:

Interaction

Examples

>>> import numpy as np
>>> from linearmodels.iv.absorbing import Interaction
>>> import pandas as pd
>>> rs = np.random.RandomState(0)
>>> n = 100000
>>> cats = pd.concat([pd.Series(pd.Categorical(rs.randint(i+2,size=n)))
...                  for i in range(4)], axis=1)
>>> cats.columns = ["cat{0}".format(i) for i in range(4)]
>>> columns = ["cont{0}".format(i) for i in range(6)]
>>> cont = pd.DataFrame(rs.standard_normal((n, 6)), columns=columns)
>>> frame = pd.concat([cats, cont], axis=1)
>>> interact = Interaction.from_frame(frame)
>>> interact.sparse.shape # Cart product of all cats, 5!, times ncont, 6
(100000, 720)