def correlation_p_cramerphi(data0, data1): # Compute observed chi^2 statistic. chi2, n0, n1 = cramerphi_chi2(data0, data1) if math.isnan(chi2): return float('NaN') # Compute p-value for chi^2 test of independence. return stats.chi2_sf(chi2, (n0 - 1) * (n1 - 1))
def correlation_p_cramerphi(data0, data1): # Compute observed chi^2 statistic. chi2, n0, n1 = cramerphi_chi2(data0, data1) if math.isnan(chi2): return float('NaN') # Compute p-value for chi^2 test of independence. return stats.chi2_sf(chi2, (n0 - 1)*(n1 - 1))
def test_t_cdf(): # Non-positive degrees of freedom should throw an error. with pytest.raises(ValueError): stats.t_cdf(0,0) with pytest.raises(ValueError): stats.t_cdf(2,-10) # CDF of x = 0 should be 0.5. assert relerr(.5, stats.t_cdf(0,12)) < .01 assert relerr(.5, stats.t_cdf(0,6)) < .01 assert relerr(.5, stats.t_cdf(0,130)) < .01 # Test against various reference values. assert relerr(.57484842931039226, stats.t_cdf(.8, .1)) < .05 assert relerr(.64922051214061649, stats.t_cdf(.6, .6)) < .05 assert relerr(.51046281131211058, stats.t_cdf(.1, .05)) < .05 assert relerr(.99999944795492968, stats.t_cdf(9, 12)) < .05 assert relerr(.92318422834700042, stats.t_cdf(1.9, 3)) < .05 assert relerr(.81430689864299455, stats.t_cdf(1, 4.2)) < .05 assert relerr(.99995442539414559, stats.t_cdf(8, 7)) < .05 assert relerr(.92010336338282994, stats.t_cdf(3.9, 1)) < .05 assert relerr(1.0, stats.t_cdf(193, 121)) < .05 assert relerr(.42515157068960779, stats.t_cdf(-.8, .1)) < .05 assert relerr(.35077948785938345, stats.t_cdf(-.6, .6)) < .05 assert relerr(.48953718868788948, stats.t_cdf(-.1, .05)) < .05 assert relerr(.076815771652999562, stats.t_cdf(-1.9, 3)) < .05 assert relerr(.18569310135700545, stats.t_cdf(-1, 4.2)) < .05 assert relerr(.17530833141010374, stats.t_cdf(-1, 7)) < .05 assert relerr(.079896636617170003, stats.t_cdf(-3.9, 1)) < .05 assert relerr(.30899158341328747, stats.t_cdf(-0.5, 121)) < .05 # Test against reference very close to zero. # XXX Why are we testing chi2_sf here? assert relerr(.346437e-4, stats.chi2_sf(193,121)) < .01
def test_chi2_sf(): # Non-positive degrees of freedom should throw an error. with pytest.raises(ValueError): stats.chi2_sf(0, 0) with pytest.raises(ValueError): stats.chi2_sf(2, -10) # Survival of x = 0 should be 1. assert relerr(1., stats.chi2_sf(0,12)) < .05 assert relerr(1., stats.chi2_sf(0,6)) < .05 assert relerr(1., stats.chi2_sf(0,130)) < .05 # Test x < 1, x >= df against reference values. assert relerr(.0357175, stats.chi2_sf(.8,.1)) < .05 assert relerr(.2730426, stats.chi2_sf(.6,.6)) < .05 assert relerr(.0602823, stats.chi2_sf(.1,.05)) < .05 # Test x >= 1, x <= df against reference values. assert relerr(.7029304, stats.chi2_sf(9,12)) < .05 assert relerr(.5934191, stats.chi2_sf(1.9,3)) < .05 assert relerr(.9238371, stats.chi2_sf(1,4.2)) < .05 # Test x >= 1, x > df against reference values. assert relerr(.3325939, stats.chi2_sf(8,7)) < .05 assert relerr(.0482861, stats.chi2_sf(3.9,1)) < .05 assert relerr(.3464377e-4, stats.chi2_sf(193,121)) < .05