#NEWLINE# def test_cochranq( ) : #NEWLINE# #INDENT# '\n    library(CVST)\n    table1 = matrix(c(1, 0, 1, 1,\n                      0, 1, 1, 1,\n                      1, 1, 1, 0,\n                      0, 1, 0, 0,\n                      0, 1, 0, 0,\n                      1, 0, 1, 0,\n                      0, 1, 0, 0,\n                      1, 1, 1, 1,\n                      0, 1, 0, 0), ncol=4, byrow=TRUE)\n    rslt1 = cochranq.test(table1)\n    table2 = matrix(c(0, 0, 1, 1, 0,\n                      0, 1, 0, 1, 0,\n                      0, 1, 1, 0, 1,\n                      1, 0, 0, 0, 1,\n                      1, 1, 0, 0, 0,\n                      1, 0, 1, 0, 0,\n                      0, 1, 0, 0, 0,\n                      0, 0, 1, 1, 0,\n                      0, 0, 0, 0, 0), ncol=5, byrow=TRUE)\n    rslt2 = cochranq.test(table2)\n    ' #NEWLINE# 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 ] ] #NEWLINE# table = np . asarray ( table ) #NEWLINE# ( stat , pvalue , df ) = ctab . cochrans_q ( table , return_object = False ) #NEWLINE# assert_allclose ( stat , 4.2 ) #NEWLINE# assert_allclose ( df , 3 ) #NEWLINE# 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 ] ] #NEWLINE# table = np . asarray ( table ) #NEWLINE# ( stat , pvalue , df ) = ctab . cochrans_q ( table , return_object = False ) #NEWLINE# assert_allclose ( stat , 1.2174 , rtol = 0.0001 ) #NEWLINE# assert_allclose ( df , 4 ) #NEWLINE# data = table [ : , 0 : 2 ] #NEWLINE# xtab = np . asarray ( pd . crosstab ( data [ : , 0 ] , data [ : , 1 ] ) ) #NEWLINE# b1 = ctab . cochrans_q ( data , return_object = True ) #NEWLINE# b2 = ctab . mcnemar ( xtab , exact = False , correction = False ) #NEWLINE# assert_allclose ( b1 . statistic , b2 . statistic ) #NEWLINE# assert_allclose ( b1 . pvalue , b2 . pvalue )