code: def test_cochranq():
      # library(CVST)
      # table1 = matrix(c(1, 0, 1, 1,
      #                   0, 1, 1, 1,
      #                   1, 1, 1, 0,
      #                   0, 1, 0, 0,
      #                   0, 1, 0, 0,
      #                   1, 0, 1, 0,
      #                   0, 1, 0, 0,
      #                   1, 1, 1, 1,
      #                   0, 1, 0, 0), ncol=4, byrow=TRUE)
      # rslt1 = cochranq.test(table1)
      # table2 = matrix(c(0, 0, 1, 1, 0,
      #                   0, 1, 0, 1, 0,
      #                   0, 1, 1, 0, 1,
      #                   1, 0, 0, 0, 1,
      #                   1, 1, 0, 0, 0,
      #                   1, 0, 1, 0, 0,
      #                   0, 1, 0, 0, 0,
      #                   0, 0, 1, 1, 0,
      #                   0, 0, 0, 0, 0), ncol=5, byrow=TRUE)
      # rslt2 = cochranq.test(table2)
  
      table = [
          [1, 0, 1, 1],
          [0, 1, 1, 1],
          [1, 1, 1, 0],
          [0, 1, 0, 0],
          [0, 1, 0, 0],
          [1, 0, 1, 0],
          [0, 1, 0, 0],
          [1, 1, 1, 1],
          [0, 1, 0, 0],
      ]
      table = np.asarray(table)
  
      stat, pvalue, df = ctab.cochrans_q(table, return_object=False)
      assert_allclose(stat, 4.2)
      assert_allclose(df, 3)
  
      table = [
          [0, 0, 1, 1, 0],
          [0, 1, 0, 1, 0],
          [0, 1, 1, 0, 1],
          [1, 0, 0, 0, 1],
          [1, 1, 0, 0, 0],
          [1, 0, 1, 0, 0],
          [0, 1, 0, 0, 0],
          [0, 0, 1, 1, 0],
          [0, 0, 0, 0, 0],
      ]
      table = np.asarray(table)
  
      stat, pvalue, df = ctab.cochrans_q(table, return_object=False)
      assert_allclose(stat, 1.2174, rtol=1e-4)
      assert_allclose(df, 4)
  
      # Cochran's q and Mcnemar are equivalent for 2x2 tables
      data = table[:, 0:2]
      xtab = np.asarray(pd.crosstab(data[:, 0], data[:, 1]))
      b1 = ctab.cochrans_q(data, return_object=True)
      b2 = ctab.mcnemar(xtab, exact=False, correction=False)
      assert_allclose(b1.statistic, b2.statistic)
      assert_allclose(b1.pvalue, b2.pvalue)
  
      # Test for printing bunch
      assert_equal(
          str(b1).startswith("df          1\npvalue      0.65"), True
      )
  
imports: import os
  import warnings
  import numpy
  import statsmodels.stats.contingency_tables
  import pandas
  from numpy.testing import assert_allclose, assert_equal
  import statsmodels.api
label_desc: Use image node_id 15 for calling a global function with example usage: test_cochranq() without return types