diff --git a/permute/tests/test_ksample.py b/permute/tests/test_ksample.py index e135d38..e86d0b5 100644 --- a/permute/tests/test_ksample.py +++ b/permute/tests/test_ksample.py @@ -15,6 +15,10 @@ def test_worms_ksample(): res = k_sample(worms.x, worms.y, stat='one-way anova', reps=1000, seed=1234) np.testing.assert_array_less(0.006, res[0]) np.testing.assert_array_less(res[0], 0.02) + res2 = k_sample(worms.x, worms.y, stat=one_way_anova, reps=1000, keep_dist=True, seed=1234) + assert len(res2[2]) == 1000 + np.testing.assert_array_equal([res[0], res[1]], [res2[0], res2[1]]) + np.testing.assert_array_less([8, 2], [res2[2][0], res2[2][1]]) def test_one_way_anova(): @@ -52,3 +56,7 @@ def test_testosterone_ksample(): assert len(x) == 55 res = bivariate_k_sample(x, group1, group2, reps=5000, seed=5) np.testing.assert_array_less(res[0], 0.0002) + res2 = bivariate_k_sample(x, group1, group2, reps=5000, stat=two_way_anova, keep_dist=True, seed=5) + assert len(res2[2]) == 5000 + np.testing.assert_array_equal([res[0], res[1]], [res2[0], res2[1]]) + np.testing.assert_array_less([0.002, 0.0001], [res2[2][0], res2[2][1]]) diff --git a/permute/tests/test_npc.py b/permute/tests/test_npc.py index a949dd1..219753f 100644 --- a/permute/tests/test_npc.py +++ b/permute/tests/test_npc.py @@ -120,7 +120,7 @@ def test_sim_npc(): # test Y always greater than X so p-value should be 1 responses = np.array([[0, 1], [0, 1], [1, 2], [1, 2]]) group = np.array([1, 1, 2, 2]) - my_randomizer = Experiment.Randomizer(randomize = randomize_group, seed = prng) + my_randomizer = Experiment.Randomizer(randomize=randomize_group, seed=prng) data = Experiment(group, responses) # create median test statistic to apply to every column @@ -137,22 +137,34 @@ def med_diff(data, resp_index): test_array = Experiment.make_test_array(med_diff, [0, 1]) res = sim_npc(data, test_array, combine="fisher", seed=None, reps=int(1000)) np.testing.assert_almost_equal(res[0], 1) - + res = sim_npc(data, test_array, combine="liptak", seed=1234, reps=int(1000)) + np.testing.assert_almost_equal(res[0], 1) + res = sim_npc(data, test_array, combine=tippett, in_place=True, seed=None, reps=int(1000)) + np.testing.assert_almost_equal(res[0], 1) + # test X = Y so p-value should be 1 responses = np.array([[0, 1], [0, 1], [0, 1], [0, 1]]) group = np.array([1, 1, 2, 2]) - data = Experiment(group, responses, randomizer = my_randomizer) - res = sim_npc(data, test = Experiment.make_test_array(Experiment.TestFunc.mean_diff, [0, 1]), + data = Experiment(group, responses, randomizer=my_randomizer) + res = sim_npc(data, test=Experiment.make_test_array(Experiment.TestFunc.mean_diff, [0, 1]), combine="fisher", seed=None, reps=int(1000)) np.testing.assert_almost_equal(res[0], 1) # test stat for cat_1 is smaller if X all 0s which about 0.015 chance so pvalue should be about 0.985 responses = np.array([[0, 1], [1, 1], [0, 1], [0, 1], [1, 1], [1, 1], [1, 1], [0, 1]]) group = np.array([1, 1, 1, 1, 2, 2, 2, 2]) - data = Experiment(group, responses, randomizer = my_randomizer) - res = sim_npc(data, test = Experiment.make_test_array(Experiment.TestFunc.mean_diff, [0, 1]), + data = Experiment(group, responses, randomizer=my_randomizer) + res = sim_npc(data, test=Experiment.make_test_array(Experiment.TestFunc.mean_diff, [0, 1]), + combine="fisher", seed=None, reps=int(1000)) + np.testing.assert_almost_equal(res[0], 0.985, decimal=2) + + # test stat for cat_1 is smaller if X all 0s which about 0.015 chance so pvalue should be about 0.0209 + responses = np.array([[0, 1], [1, 1], [0, 1], [0, 1], [1, 1], [1, 1], [1, 1], [0, 1]]) + group = np.array([1, 1, 1, 1, 2, 2, 2, 2]) + data = Experiment(group, responses, randomizer=my_randomizer) + res = sim_npc(data, test=Experiment.make_test_array(Experiment.TestFunc.one_way_anova, [0, 1]), combine="fisher", seed=None, reps=int(1000)) - np.testing.assert_almost_equal(res[0], 0.985, decimal = 2) + np.testing.assert_almost_equal(res[0], 0.0209, decimal=2) def test_westfall_young():