class_docstr: Analyses for a collection of 2x2 contingency tables.
  
  Such a collection may arise by stratifying a single 2x2 table with
  respect to another factor.  This class implements the
  'Cochran-Mantel-Haenszel' and 'Breslow-Day' procedures for
  analyzing collections of 2x2 contingency tables.
  
  Parameters
  ----------
  tables : list or ndarray
      Either a list containing several 2x2 contingency tables, or
      a 2x2xk ndarray in which each slice along the third axis is a
      2x2 contingency table.
  
  Notes
  -----
  This results are based on a sampling model in which the units are
  independent both within and between strata.
class_docstr_tok: ["Analyses","for","a","collection","of","2x2","contingency","tables",".","Such","a","collection","may","arise","by","stratifying","a","single","2x2","table","with","respect","to","another","factor",".","This","class","implements","the","'Cochran-Mantel-Haenszel","'","and","'Breslow-Day","'","procedures","for","analyzing","collections","of","2x2","contingency","tables",".","Parameters","--","--","--","--","--","tables",":","list","or","ndarray","Either","a","list","containing","several","2x2","contingency","tables",",","or","a","2x2xk","ndarray","in","which","each","slice","along","the","third","axis","is","a","2x2","contingency","table",".","Notes","--","--","-","This","results","are","based","on","a","sampling","model","in","which","the","units","are","independent","both","within","and","between","strata","."]
docstr: 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
  -------
  StratifiedTable
docstr_tok: ["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","--","--","--","-","StratifiedTable"]
code: def from_data(cls, var1, var2, strata, data):
      """
      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
      -------
      StratifiedTable
      """
  
      if not isinstance(data, pd.DataFrame):
          data1 = pd.DataFrame(
              index=np.arange(data.shape[0]),
              columns=[var1, var2, strata],
          )
          data1[data1.columns[var1]] = data[:, var1]
          data1[data1.columns[var2]] = data[:, var2]
          data1[data1.columns[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)
  
imports: import warnings
  import numpy
  import pandas
  from scipy import stats
  from statsmodels import iolib
  from statsmodels.tools import sm_exceptions
  from statsmodels.tools.decorators import cache_readonly
label_desc: Use image node_id 2 for calling the StratifiedTable obj's underlying member method code with example usage: obj.from_data(cls, var1, var2, strata, data) and returns: cls