def test_binom_test(): #> bt = binom.test(51,235,(1/6),alternative="less") #> cat_items(bt, "binom_test_less.") binom_test_less = Holder() binom_test_less.statistic = 51 binom_test_less.parameter = 235 binom_test_less.p_value = 0.982022657605858 binom_test_less.conf_int = [0, 0.2659460862574313] binom_test_less.estimate = 0.2170212765957447 binom_test_less.null_value = 1. / 6 binom_test_less.alternative = 'less' binom_test_less.method = 'Exact binomial test' binom_test_less.data_name = '51 and 235' #> bt = binom.test(51,235,(1/6),alternative="greater") #> cat_items(bt, "binom_test_greater.") binom_test_greater = Holder() binom_test_greater.statistic = 51 binom_test_greater.parameter = 235 binom_test_greater.p_value = 0.02654424571169085 binom_test_greater.conf_int = [0.1735252778065201, 1] binom_test_greater.estimate = 0.2170212765957447 binom_test_greater.null_value = 1. / 6 binom_test_greater.alternative = 'greater' binom_test_greater.method = 'Exact binomial test' binom_test_greater.data_name = '51 and 235' #> bt = binom.test(51,235,(1/6),alternative="t") #> cat_items(bt, "binom_test_2sided.") binom_test_2sided = Holder() binom_test_2sided.statistic = 51 binom_test_2sided.parameter = 235 binom_test_2sided.p_value = 0.0437479701823997 binom_test_2sided.conf_int = [0.1660633298083073, 0.2752683640289254] binom_test_2sided.estimate = 0.2170212765957447 binom_test_2sided.null_value = 1. / 6 binom_test_2sided.alternative = 'two.sided' binom_test_2sided.method = 'Exact binomial test' binom_test_2sided.data_name = '51 and 235' alltests = [('larger', binom_test_greater), ('smaller', binom_test_less), ('two-sided', binom_test_2sided)] for alt, res0 in alltests: # only p-value is returned res = smprop.binom_test(51, 235, prop=1. / 6, alternative=alt) #assert_almost_equal(res[0], res0.statistic) assert_almost_equal(res, res0.p_value, decimal=13) # R binom_test returns Copper-Pearson confint ci_2s = smprop.proportion_confint(51, 235, alpha=0.05, method='beta') ci_low, ci_upp = smprop.proportion_confint(51, 235, alpha=0.1, method='beta') assert_almost_equal(ci_2s, binom_test_2sided.conf_int, decimal=13) assert_almost_equal(ci_upp, binom_test_less.conf_int[1], decimal=13) assert_almost_equal(ci_low, binom_test_greater.conf_int[0], decimal=13)
def get_results(cls): cls.k = 1 # results from R WRS2 cls.res_basic = np.array([ 342.705882352941, 92.3342348150314, 380.157894736842, 92.9416968861829, 129679.029239766 ]) # results from R PairedData ytt1 = Holder() ytt1.statistic = 3.71157981694944 ytt1.parameter = 16 ytt1.p_value = 0.00189544440273015 ytt1.conf_int = np.array([146.966048669017, 538.445716036866]) ytt1.estimate = 342.705882352941 ytt1.null_value = 0 ytt1.alternative = 'two.sided' ytt1.method = 'One sample Yuen test, trim=0.0526315789473684' ytt1.data_name = 'x' cls.ytt1 = ytt1
tost_clinic_all_multi.method = 'step.up' tost_clinic_all_multi.var_equal = '''FALSE''' tost_clinic_all_multi.FWER = 0.05 #t-tests #> tt = t.test(clinic$var1[16:30], clinic$var1[1:15], data=clinic, mu=-0., alternative="two.sided", paired=TRUE) #> cat_items(tt, prefix="ttest_clinic_paired_1.") ttest_clinic_paired_1 = Holder() ttest_clinic_paired_1.statistic = 1.213001548676048 ttest_clinic_paired_1.parameter = 14 ttest_clinic_paired_1.p_value = 0.245199929713149 ttest_clinic_paired_1.conf_int = (-0.1264911434745851, 0.4558244768079186) ttest_clinic_paired_1.estimate = 0.1646666666666667 ttest_clinic_paired_1.null_value = 0 ttest_clinic_paired_1.alternative = 'two.sided' ttest_clinic_paired_1.method = 'Paired t-test' ttest_clinic_paired_1.data_name = 'clinic$var1[1:15] and clinic$var1[16:30]' #> ttless = t.test(clinic$var1[1:15], clinic$var1[16:30],, data=clinic, mu=-0., alternative="less", paired=FALSE) #> cat_items(ttless, prefix="ttest_clinic_paired_1_l.") ttest_clinic_paired_1_l = Holder() ttest_clinic_paired_1_l.statistic = 0.650438363512706 ttest_clinic_paired_1_l.parameter = 26.7484787582315 ttest_clinic_paired_1_l.p_value = 0.739521349864458 ttest_clinic_paired_1_l.conf_int = (-np.inf, 0.596019631405587) ttest_clinic_paired_1_l.estimate = (3.498, 3.333333333333333) ttest_clinic_paired_1_l.null_value = 0 ttest_clinic_paired_1_l.alternative = 'less' ttest_clinic_paired_1_l.method = 'Welch Two Sample t-test' ttest_clinic_paired_1_l.data_name = 'clinic$var1[1:15] and clinic$var1[16:30]'
def setup(self): self.n_success = np.array([73, 90, 114, 75]) self.nobs = np.array([86, 93, 136, 82]) self.res_ppt_pvals_raw = np.array([ 0.00533824886503131, 0.8327574849753566, 0.1880573726722516, 0.002026764254350234, 0.1309487516334318, 0.1076118730631731 ]) self.res_ppt_pvals_holm = np.array([ 0.02669124432515654, 0.8327574849753566, 0.4304474922526926, 0.0121605855261014, 0.4304474922526926, 0.4304474922526926 ]) res_prop_test = Holder() res_prop_test.statistic = 11.11938768628861 res_prop_test.parameter = 3 res_prop_test.p_value = 0.011097511366581344 res_prop_test.estimate = np.array([ 0.848837209302326, 0.967741935483871, 0.838235294117647, 0.9146341463414634 ]).reshape(4, 1, order='F') res_prop_test.null_value = '''NULL''' res_prop_test.conf_int = '''NULL''' res_prop_test.alternative = 'two.sided' res_prop_test.method = '4-sample test for equality of proportions ' + \ 'without continuity correction' res_prop_test.data_name = 'smokers2 out of patients' self.res_prop_test = res_prop_test #> pt = prop.test(smokers2, patients, p=rep(c(0.9), 4), correct=FALSE) #> cat_items(pt, "res_prop_test_val.") res_prop_test_val = Holder() res_prop_test_val.statistic = np.array([13.20305530710751 ]).reshape(1, 1, order='F') res_prop_test_val.parameter = np.array([4]).reshape(1, 1, order='F') res_prop_test_val.p_value = 0.010325090041836 res_prop_test_val.estimate = np.array([ 0.848837209302326, 0.967741935483871, 0.838235294117647, 0.9146341463414634 ]).reshape(4, 1, order='F') res_prop_test_val.null_value = np.array([0.9, 0.9, 0.9, 0.9]).reshape(4, 1, order='F') res_prop_test_val.conf_int = '''NULL''' res_prop_test_val.alternative = 'two.sided' res_prop_test_val.method = '4-sample test for given proportions without continuity correction' res_prop_test_val.data_name = 'smokers2 out of patients, null probabilities rep(c(0.9), 4)' self.res_prop_test_val = res_prop_test_val #> pt = prop.test(smokers2[1], patients[1], p=0.9, correct=FALSE) #> cat_items(pt, "res_prop_test_1.") res_prop_test_1 = Holder() res_prop_test_1.statistic = 2.501291989664086 res_prop_test_1.parameter = 1 res_prop_test_1.p_value = 0.113752943640092 res_prop_test_1.estimate = 0.848837209302326 res_prop_test_1.null_value = 0.9 res_prop_test_1.conf_int = np.array( [0.758364348004061, 0.9094787701686766]) res_prop_test_1.alternative = 'two.sided' res_prop_test_1.method = '1-sample proportions test without continuity correction' res_prop_test_1.data_name = 'smokers2[1] out of patients[1], null probability 0.9' self.res_prop_test_1 = res_prop_test_1
assert_almost_equal(res1a, res1, decimal=12) # test for ztest and z confidence interval against R BSDA z.test # Note: I needed to calculate the pooled standard deviation for R # std = np.std(np.concatenate((x-x.mean(),y-y.mean())), ddof=2) # > zt = z.test(x, sigma.x=0.57676142668828667, y, sigma.y=0.57676142668828667) # > cat_items(zt, "ztest.") ztest_ = Holder() ztest_.statistic = 6.55109865675183 ztest_.p_value = 5.711530850508982e-11 ztest_.conf_int = np.array([1.230415246535603, 2.280948389828034]) ztest_.estimate = np.array([7.01818181818182, 5.2625]) ztest_.null_value = 0 ztest_.alternative = 'two.sided' ztest_.method = 'Two-sample z-Test' ztest_.data_name = 'x and y' # > zt = z.test(x, sigma.x=0.57676142668828667, y, # sigma.y=0.57676142668828667, alternative="less") # > cat_items(zt, "ztest_smaller.") ztest_smaller = Holder() ztest_smaller.statistic = 6.55109865675183 ztest_smaller.p_value = 0.999999999971442 ztest_smaller.conf_int = np.array([np.nan, 2.196499421109045]) ztest_smaller.estimate = np.array([7.01818181818182, 5.2625]) ztest_smaller.null_value = 0 ztest_smaller.alternative = 'less' ztest_smaller.method = 'Two-sample z-Test' ztest_smaller.data_name = 'x and y' # > zt = z.test(x, sigma.x=0.57676142668828667, y,
def setup(self): self.n_success = np.array([ 73, 90, 114, 75]) self.nobs = np.array([ 86, 93, 136, 82]) self.res_ppt_pvals_raw = np.array([ 0.00533824886503131, 0.8327574849753566, 0.1880573726722516, 0.002026764254350234, 0.1309487516334318, 0.1076118730631731 ]) self.res_ppt_pvals_holm = np.array([ 0.02669124432515654, 0.8327574849753566, 0.4304474922526926, 0.0121605855261014, 0.4304474922526926, 0.4304474922526926 ]) res_prop_test = Holder() res_prop_test.statistic = 11.11938768628861 res_prop_test.parameter = 3 res_prop_test.p_value = 0.011097511366581344 res_prop_test.estimate = np.array([ 0.848837209302326, 0.967741935483871, 0.838235294117647, 0.9146341463414634 ]).reshape(4,1, order='F') res_prop_test.null_value = '''NULL''' res_prop_test.conf_int = '''NULL''' res_prop_test.alternative = 'two.sided' res_prop_test.method = '4-sample test for equality of proportions ' + \ 'without continuity correction' res_prop_test.data_name = 'smokers2 out of patients' self.res_prop_test = res_prop_test #> pt = prop.test(smokers2, patients, p=rep(c(0.9), 4), correct=FALSE) #> cat_items(pt, "res_prop_test_val.") res_prop_test_val = Holder() res_prop_test_val.statistic = np.array([ 13.20305530710751 ]).reshape(1,1, order='F') res_prop_test_val.parameter = np.array([ 4 ]).reshape(1,1, order='F') res_prop_test_val.p_value = 0.010325090041836 res_prop_test_val.estimate = np.array([ 0.848837209302326, 0.967741935483871, 0.838235294117647, 0.9146341463414634 ]).reshape(4,1, order='F') res_prop_test_val.null_value = np.array([ 0.9, 0.9, 0.9, 0.9 ]).reshape(4,1, order='F') res_prop_test_val.conf_int = '''NULL''' res_prop_test_val.alternative = 'two.sided' res_prop_test_val.method = '4-sample test for given proportions without continuity correction' res_prop_test_val.data_name = 'smokers2 out of patients, null probabilities rep(c(0.9), 4)' self.res_prop_test_val = res_prop_test_val #> pt = prop.test(smokers2[1], patients[1], p=0.9, correct=FALSE) #> cat_items(pt, "res_prop_test_1.") res_prop_test_1 = Holder() res_prop_test_1.statistic = 2.501291989664086 res_prop_test_1.parameter = 1 res_prop_test_1.p_value = 0.113752943640092 res_prop_test_1.estimate = 0.848837209302326 res_prop_test_1.null_value = 0.9 res_prop_test_1.conf_int = np.array([0.758364348004061, 0.9094787701686766]) res_prop_test_1.alternative = 'two.sided' res_prop_test_1.method = '1-sample proportions test without continuity correction' res_prop_test_1.data_name = 'smokers2[1] out of patients[1], null probability 0.9' self.res_prop_test_1 = res_prop_test_1