-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TST: Add tests to increase coverage for ksample.py and npc.py files. #221
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For testing, I added prints of
Value printed are like above. So the asserts work fine that are added below at: Also, the stat method 'two_way_anova' is the default method. So res2 has same result. |
||
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]]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In above code, I added prints for fisher, liptak, tippet combine methods.
Have added the code that I used to print:
|
||
# 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only white-space changes in this block of code. No real code change. |
||
|
||
# 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, at line 165 - have changed the test function to use 'one_way_anova' method. And I printed the value of 'res' as returned from 'sim_npc()' function.
Code used to print above value:
|
||
|
||
|
||
def test_westfall_young(): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For testing, I added prints for value of
res
from line 15 (printed as "Res1:") , andres2
(printed as "Res2:") from line 18. Values show up as following:So assert added in:
line 19: length is 1000 of array being printed in res2
line 20: res and res2 are same.
line 21: see values of array printed in res2.
Also the 'one_way_anova' method is the default method, so res and res2 have same results.