class_docstr: Methods for analyzing a square contingency table.
  
  Parameters
  ----------
  table : array_like
      A square contingency table, or DataFrame that is converted
      to a square form.
  shift_zeros : bool
      If True and any cell count is zero, add 0.5 to all values
      in the table.
  
  Notes
  -----
  These methods should only be used when the rows and columns of the
  table have the same categories.  If `table` is provided as a
  Pandas DataFrame, the row and column indices will be extended to
  create a square table, inserting zeros where a row or column is
  missing.  Otherwise the table should be provided in a square form,
  with the (implicit) row and column categories appearing in the
  same order.
class_docstr_tok: ["Methods","for","analyzing","a","square","contingency","table",".","Parameters","--","--","--","--","--","table",":","array_like","A","square","contingency","table",",","or","DataFrame","that","is","converted","to","a","square","form",".","shift_zeros",":","bool","If","True","and","any","cell","count","is","zero",",","add","0.5","to","all","values","in","the","table",".","Notes","--","--","-","These","methods","should","only","be","used","when","the","rows","and","columns","of","the","table","have","the","same","categories",".","If","`","table","`","is","provided","as","a","Pandas","DataFrame",",","the","row","and","column","indices","will","be","extended","to","create","a","square","table",",","inserting","zeros","where","a","row","or","column","is","missing",".","Otherwise","the","table","should","be","provided","in","a","square","form",",","with","the","(","implicit",")","row","and","column","categories","appearing","in","the","same","order","."]
docstr: Test for symmetry of a joint distribution.
  
  This procedure tests the null hypothesis that the joint
  distribution is symmetric around the main diagonal, that is
  
  .. math::
  
  p_{i, j} = p_{j, i}  for all i, j
  
  Returns
  -------
  Bunch
      A bunch with attributes
  
      * statistic : float
          chisquare test statistic
      * p-value : float
          p-value of the test statistic based on chisquare distribution
      * df : int
          degrees of freedom of the chisquare distribution
  
  Notes
  -----
  The implementation is based on the SAS documentation. R includes
  it in `mcnemar.test` if the table is not 2 by 2.  However a more
  direct generalization of the McNemar test to larger tables is
  provided by the homogeneity test (TableSymmetry.homogeneity).
  
  The p-value is based on the chi-square distribution which requires
  that the sample size is not very small to be a good approximation
  of the true distribution. For 2x2 contingency tables the exact
  distribution can be obtained with `mcnemar`
  
  See Also
  --------
  mcnemar
  homogeneity
docstr_tok: ["Test","for","symmetry","of","a","joint","distribution",".","This","procedure","tests","the","null","hypothesis","that","the","joint","distribution","is","symmetric","around","the","main","diagonal",",","that","is","..","math",":",":","p_","{","i",",","j","}","=","p_","{","j",",","i","}","for","all","i",",","j","Returns","--","--","--","-","Bunch","A","bunch","with","attributes","*","statistic",":","float","chisquare","test","statistic","*","p-value",":","float","p-value","of","the","test","statistic","based","on","chisquare","distribution","*","df",":","int","degrees","of","freedom","of","the","chisquare","distribution","Notes","--","--","-","The","implementation","is","based","on","the","SAS","documentation",".","R","includes","it","in","`","mcnemar.test","`","if","the","table","is","not","2","by","2",".","However","a","more","direct","generalization","of","the","McNemar","test","to","larger","tables","is","provided","by","the","homogeneity","test","(","TableSymmetry.homogeneity",")",".","The","p-value","is","based","on","the","chi-square","distribution","which","requires","that","the","sample","size","is","not","very","small","to","be","a","good","approximation","of","the","true","distribution",".","For","2x2","contingency","tables","the","exact","distribution","can","be","obtained","with","`","mcnemar","`","See","Also","--","--","--","--","mcnemar","homogeneity"]
code: def symmetry(self, method="bowker"):
      """
      Test for symmetry of a joint distribution.
  
      This procedure tests the null hypothesis that the joint
      distribution is symmetric around the main diagonal, that is
  
      .. math::
  
      p_{i, j} = p_{j, i}  for all i, j
  
      Returns
      -------
      Bunch
          A bunch with attributes
  
          * statistic : float
              chisquare test statistic
          * p-value : float
              p-value of the test statistic based on chisquare distribution
          * df : int
              degrees of freedom of the chisquare distribution
  
      Notes
      -----
      The implementation is based on the SAS documentation. R includes
      it in `mcnemar.test` if the table is not 2 by 2.  However a more
      direct generalization of the McNemar test to larger tables is
      provided by the homogeneity test (TableSymmetry.homogeneity).
  
      The p-value is based on the chi-square distribution which requires
      that the sample size is not very small to be a good approximation
      of the true distribution. For 2x2 contingency tables the exact
      distribution can be obtained with `mcnemar`
  
      See Also
      --------
      mcnemar
      homogeneity
      """
  
      if method.lower() != "bowker":
          raise ValueError(
              "method for symmetry testing must be 'bowker'"
          )
  
      k = self.table.shape[0]
      upp_idx = np.triu_indices(k, 1)
  
      tril = self.table.T[upp_idx]  # lower triangle in column order
      triu = self.table[upp_idx]  # upper triangle in row order
  
      statistic = ((tril - triu) ** 2 / (tril + triu + 1e-20)).sum()
      df = k * (k - 1) / 2.0
      pvalue = stats.chi2.sf(statistic, df)
  
      b = _Bunch()
      b.statistic = statistic
      b.pvalue = pvalue
      b.df = df
  
      return b
  
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 SquareTable obj's underlying member method code with example usage: obj.symmetry(method) and returns: b