def _G_test(site_counts): """G test for 2x2 contingency table (PRIVATE). Argument: - site_counts - [syn_fix, nonsyn_fix, syn_poly, nonsyn_poly] >>> print("%0.6f" % _G_test([17, 7, 42, 2])) 0.004924 """ # TODO: # Apply continuity correction for Chi-square test. from math import log # from scipy.stats import chi2 G = 0 tot = sum(site_counts) tot_syn = site_counts[0] + site_counts[2] tot_non = site_counts[1] + site_counts[3] tot_fix = sum(site_counts[:2]) tot_poly = sum(site_counts[2:]) exp = [ tot_fix * tot_syn / tot, tot_fix * tot_non / tot, tot_poly * tot_syn / tot, tot_poly * tot_non / tot ] for obs, ex in zip(site_counts, exp): G += obs * log(obs / ex) G *= 2 # return 1-chi2.cdf(G, 1) # only 1 dof for 2x2 table return chisqprob(G, 1)
def _G_test(site_counts): """G test for 2x2 contingency table (PRIVATE). Argument: - site_counts - [syn_fix, nonsyn_fix, syn_poly, nonsyn_poly] >>> round(_G_test([17, 7, 42, 2]), 7) 0.004924 """ # TODO: # Apply continuity correction for Chi-square test. from math import log # from scipy.stats import chi2 G = 0 tot = sum(site_counts) tot_syn = site_counts[0] + site_counts[2] tot_non = site_counts[1] + site_counts[3] tot_fix = sum(site_counts[:2]) tot_poly = sum(site_counts[2:]) exp = [tot_fix * tot_syn / tot, tot_fix * tot_non / tot, tot_poly * tot_syn / tot, tot_poly * tot_non / tot] for obs, ex in zip(site_counts, exp): G += obs * log(obs / ex) G *= 2 # return 1-chi2.cdf(G, 1) # only 1 dof for 2x2 table return chisqprob(G, 1)