def test_confidence_interval_with_sample_simulation(self):
        grp1_sample = Sample()
        grp2_sample = Sample()

        for i in range(10):
            if random() <= 0.6:
                grp1_sample.add_category("OK")
            else:
                grp1_sample.add_category("CANCEL")

        for i in range(9):
            if random() <= 0.61:
                grp2_sample.add_category("OK")
            else:
                grp2_sample.add_category("CANCEL")

        sampling_distribution = ProportionDiffSamplingDistribution(
            grp1_sample_distribution=SampleDistribution(
                grp1_sample, categorical_value="OK"),
            grp2_sample_distribution=SampleDistribution(
                grp2_sample, categorical_value="OK"))
        self.assertEqual(sampling_distribution.distribution_family,
                         DistributionFamily.simulation)
        print('sampling distribution: (point_estimate = ' +
              str(sampling_distribution.point_estimate) +
              ', standard_error = ' +
              str(sampling_distribution.standard_error) + ')')
        print('confidence level for 95% confidence level: ' +
              str(sampling_distribution.confidence_interval(0.95)))
    def test_normal(self):
        grp1_sample = Sample()
        grp2_sample = Sample()

        for i in range(100):
            if random() <= 0.6:
                grp1_sample.add_category("OK")
            else:
                grp1_sample.add_category("CANCEL")

        for i in range(100):
            if random() <= 0.61:
                grp2_sample.add_category("OK")
            else:
                grp2_sample.add_category("CANCEL")

        sampling_distribution = ProportionDiffSamplingDistribution(
            grp1_sample_distribution=SampleDistribution(
                grp1_sample, categorical_value="OK"),
            grp2_sample_distribution=SampleDistribution(
                grp2_sample, categorical_value="OK"))
        self.assertEqual(sampling_distribution.distribution_family,
                         DistributionFamily.normal)

        testing = ProportionDiffTesting(
            sampling_distribution=sampling_distribution)
        print('one tail p-value: ' + str(testing.p_value_one_tail))
        print('two tail p-value: ' + str(testing.p_value_two_tail))
        reject_one_tail, reject_two_tail = testing.will_reject(0.01)
        print('will reject p_1 == p_2 (one-tail) ? ' + str(reject_one_tail))
        print('will reject p_1 == p_2 (two-tail) ? ' + str(reject_two_tail))
        self.assertFalse(reject_one_tail)
        self.assertFalse(reject_two_tail)
    def test_proportion_simulation(self):
        sample = Sample()

        for i in range(10):
            if random() <= 0.6:
                sample.add_category("OK")
            else:
                sample.add_category("CANCEL")

        sampling_distribution = ProportionSamplingDistribution(
            sample_distribution=SampleDistribution(sample, categorical_value="OK"))

        testing = ProportionTesting(sampling_distribution=sampling_distribution, p_null=0.6)

        print('one tail p-value: ' + str(testing.p_value_one_tail))
        print('two tail p-value: ' + str(testing.p_value_two_tail))
        reject_one_tail, reject_two_tail = testing.will_reject(0.01)
        print('will reject p = 0.6 (one-tail) ? ' + str(reject_one_tail))
        print('will reject p = 0.6 (two-tail) ? ' + str(reject_two_tail))
        self.assertFalse(reject_one_tail)
        self.assertFalse(reject_two_tail)
Example #4
0
    def test_anova(self):
        sample = Sample()

        for i in range(1000):
            sample.add_category(
                'itemA' if numpy.random.randn() > 0 else 'itemB', 'group1')
            sample.add_category(
                'itemA' if numpy.random.randn() > 0 else 'itemB', 'group2')
            sample.add_category(
                'itemA' if numpy.random.randn() > 0 else 'itemB', 'group3')

        testing = ChiSquare(sample=sample)

        print('p-value: ' + str(testing.p_value))
        reject = testing.will_reject(0.01)
        print(
            'will reject [two categorical variables are independent of each other] ? '
            + str(reject))