def test_student(self):
        grp1_mu = 0.0
        grp1_sigma = 1.0
        grp1_sample_size = 29
        grp1_sample = Sample()

        grp2_mu = 0.09
        grp2_sigma = 2.0
        grp2_sample_size = 28
        grp2_sample = Sample()

        for i in range(grp1_sample_size):
            grp1_sample.add_numeric(normal(grp1_mu, grp1_sigma))

        for i in range(grp2_sample_size):
            grp2_sample.add_numeric(normal(grp2_mu, grp2_sigma))

        sampling_distribution = MeanDiffSamplingDistribution(
            grp1_sample_distribution=SampleDistribution(grp1_sample),
            grp2_sample_distribution=SampleDistribution(grp2_sample))
        self.assertEqual(sampling_distribution.distribution_family,
                         DistributionFamily.student_t)
        testing = MeanDiffTesting(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 mean_1 == mean_2 (one-tail) ? ' +
              str(reject_one_tail))
        print('will reject mean_1 == mean_2 (two-tail) ? ' +
              str(reject_two_tail))
        self.assertFalse(reject_one_tail)
        self.assertFalse(reject_two_tail)
    def test_confidence_interval_with_sample_student(self):
        grp1_mu = 0.0
        grp1_sigma = 1.0
        grp1_sample_size = 29
        grp1_sample = Sample()
        grp2_mu = 0.08
        grp2_sigma = 1.1
        grp2_sample_size = 27
        grp2_sample = Sample()

        for i in range(grp1_sample_size):
            grp1_sample.add_numeric(normal(grp1_mu, grp1_sigma))
        for i in range(grp2_sample_size):
            grp2_sample.add_numeric(normal(grp2_mu, grp2_sigma))

        sampling_distribution = MeanDiffSamplingDistribution(
            grp1_sample_distribution=SampleDistribution(grp1_sample),
            grp2_sample_distribution=SampleDistribution(grp2_sample))
        self.assertEqual(sampling_distribution.distribution_family,
                         DistributionFamily.student_t)
        print('sampling distribution: (point_estimate = ' +
              str(sampling_distribution.point_estimate) +
              ', standard_error = ' +
              str(sampling_distribution.standard_error) + ')')
        print('confidence interval for 95% confidence level: ' +
              str(sampling_distribution.confidence_interval(0.95)))
    def test_confidence_interval_with_sample_normal(self):
        mu = 0.0
        sigma = 1.0
        sample_size = 31
        sample = Sample()

        for i in range(sample_size):
            sample.add_numeric(normal(mu, sigma))

        sampling_distribution = MeanSamplingDistribution(
            sample_distribution=SampleDistribution(sample))
        self.assertEqual(sampling_distribution.distribution_family,
                         DistributionFamily.normal)
        print('sampling distribution: (point_estimate = ' +
              str(sampling_distribution.point_estimate) +
              ', standard_error = ' +
              str(sampling_distribution.standard_error) + ')')
        print('confidence interval for 95% confidence level: ' +
              str(sampling_distribution.confidence_interval(0.95)))
    def test_mean_student(self):
        mu = 0.0
        sigma = 1.0
        sample_size = 29
        sample = Sample()

        for i in range(sample_size):
            sample.add_numeric(normal(mu, sigma))

        sampling_distribution = MeanSamplingDistribution(sample_distribution=SampleDistribution(sample))
        testing = MeanTesting(sampling_distribution=sampling_distribution, mean_null=0.0)

        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 mean = 0 (one-tail) ? ' + str(reject_one_tail))
        print('will reject mean = 0 (two-tail) ? ' + str(reject_two_tail))
        self.assertFalse(reject_one_tail)
        self.assertFalse(reject_two_tail)
示例#5
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))
    def test_confidence_interval_with_sample_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"))
        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_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)
示例#8
0
    def test_anova(self):
        sample = Sample()

        mu1 = 1.0
        sigma1 = 1.0

        mu2 = 1.1
        sigma2 = 1.0

        mu3 = 1.09
        sigma3 = 1.0

        for i in range(100):
            sample.add_numeric(normal(mu1, sigma1), 'group1')
            sample.add_numeric(normal(mu2, sigma2), 'group2')
            sample.add_numeric(normal(mu3, sigma3), 'group3')

        testing = Anova(sample=sample)

        print('p-value: ' + str(testing.p_value))
        reject = testing.will_reject(0.01)
        print('will reject [same mean for all groups] ? ' + str(reject))
        self.assertFalse(reject)
    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)