|
@@ 106-135 (lines=30) @@
|
| 103 |
|
self.assertFalse(reject_one_tail) |
| 104 |
|
self.assertFalse(reject_two_tail) |
| 105 |
|
|
| 106 |
|
def test_student(self): |
| 107 |
|
grp1_sample = Sample() |
| 108 |
|
grp2_sample = Sample() |
| 109 |
|
|
| 110 |
|
for i in range(20): |
| 111 |
|
if random() <= 0.6: |
| 112 |
|
grp1_sample.add_category("OK") |
| 113 |
|
else: |
| 114 |
|
grp1_sample.add_category("CANCEL") |
| 115 |
|
|
| 116 |
|
for i in range(20): |
| 117 |
|
if random() <= 0.61: |
| 118 |
|
grp2_sample.add_category("OK") |
| 119 |
|
else: |
| 120 |
|
grp2_sample.add_category("CANCEL") |
| 121 |
|
|
| 122 |
|
sampling_distribution = ProportionDiffSamplingDistribution(grp1_sample_distribution=SampleDistribution( |
| 123 |
|
grp1_sample, categorical_value="OK"), |
| 124 |
|
grp2_sample_distribution=SampleDistribution( |
| 125 |
|
grp2_sample, categorical_value="OK")) |
| 126 |
|
self.assertEqual(sampling_distribution.distribution_family, DistributionFamily.simulation) |
| 127 |
|
|
| 128 |
|
testing = ProportionDiffTesting(sampling_distribution=sampling_distribution) |
| 129 |
|
print('one tail p-value: ' + str(testing.p_value_one_tail)) |
| 130 |
|
print('two tail p-value: ' + str(testing.p_value_two_tail)) |
| 131 |
|
reject_one_tail, reject_two_tail = testing.will_reject(0.01) |
| 132 |
|
print('will reject p_1 == p_2 (one-tail) ? ' + str(reject_one_tail)) |
| 133 |
|
print('will reject p_1 == p_2 (two-tail) ? ' + str(reject_two_tail)) |
| 134 |
|
self.assertFalse(reject_one_tail) |
| 135 |
|
self.assertFalse(reject_two_tail) |
| 136 |
|
|
| 137 |
|
if __name__ == '__main__': |
| 138 |
|
unittest.main() |
|
@@ 75-104 (lines=30) @@
|
| 72 |
|
|
| 73 |
|
class ProportionDiffTestingUnitTest(unittest.TestCase): |
| 74 |
|
|
| 75 |
|
def test_normal(self): |
| 76 |
|
grp1_sample = Sample() |
| 77 |
|
grp2_sample = Sample() |
| 78 |
|
|
| 79 |
|
for i in range(100): |
| 80 |
|
if random() <= 0.6: |
| 81 |
|
grp1_sample.add_category("OK") |
| 82 |
|
else: |
| 83 |
|
grp1_sample.add_category("CANCEL") |
| 84 |
|
|
| 85 |
|
for i in range(100): |
| 86 |
|
if random() <= 0.61: |
| 87 |
|
grp2_sample.add_category("OK") |
| 88 |
|
else: |
| 89 |
|
grp2_sample.add_category("CANCEL") |
| 90 |
|
|
| 91 |
|
sampling_distribution = ProportionDiffSamplingDistribution(grp1_sample_distribution=SampleDistribution( |
| 92 |
|
grp1_sample, categorical_value="OK"), |
| 93 |
|
grp2_sample_distribution=SampleDistribution( |
| 94 |
|
grp2_sample, categorical_value="OK")) |
| 95 |
|
self.assertEqual(sampling_distribution.distribution_family, DistributionFamily.normal) |
| 96 |
|
|
| 97 |
|
testing = ProportionDiffTesting(sampling_distribution=sampling_distribution) |
| 98 |
|
print('one tail p-value: ' + str(testing.p_value_one_tail)) |
| 99 |
|
print('two tail p-value: ' + str(testing.p_value_two_tail)) |
| 100 |
|
reject_one_tail, reject_two_tail = testing.will_reject(0.01) |
| 101 |
|
print('will reject p_1 == p_2 (one-tail) ? ' + str(reject_one_tail)) |
| 102 |
|
print('will reject p_1 == p_2 (two-tail) ? ' + str(reject_two_tail)) |
| 103 |
|
self.assertFalse(reject_one_tail) |
| 104 |
|
self.assertFalse(reject_two_tail) |
| 105 |
|
|
| 106 |
|
def test_student(self): |
| 107 |
|
grp1_sample = Sample() |