'Construct a StratifiedTable object from data.
Parameters
var1 : int or string
The column index or name of `data` specifying the variable
defining the rows of the contingency table.  The variable
must have only two distinct values.
var2 : int or string
The column index or name of `data` specifying the variable
defining the columns of the contingency table.  The variable
must have only two distinct values.
strata : int or string
The column index or name of `data` specifying the variable
defining the strata.
data : array-like
The raw data.  A cross-table for analysis is constructed
from the first two columns.
Returns
A StratifiedTable instance.'

@classmethod
def from_data(cls, var1, var2, strata, data):

    if (not isinstance(data, pd.DataFrame)):
        data1 = pd.DataFrame(index=np.arange(data.shape[0]), columns=[var1, var2, strata])
        data1.loc[:, var1] = data[:, var1]
        data1.loc[:, var2] = data[:, var2]
        data1.loc[:, strata] = data[:, strata]
    else:
        data1 = data[[var1, var2, strata]]
    gb = data1.groupby(strata).groups
    tables = []
    for g in gb:
        ii = gb[g]
        tab = pd.crosstab(data1.loc[(ii, var1)], data1.loc[(ii, var2)])
        if (tab.shape != np.r_[(2, 2)]).any():
            msg = 'Invalid    table    dimensions'
            raise ValueError(msg)
        tables.append(np.asarray(tab))
    return cls(tables)
