Ejemplo n.º 1
0
    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)))
Ejemplo n.º 2
0
    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)))
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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 __init__(self, sample, significance_level=None):
        if significance_level is not None:
            self.significance_level = significance_level

        self.sample = sample
        self.individual_sampling_distributions = TernarySearchTrie()
        self.individual_sample_distributions = TernarySearchTrie()
        self.individual_samples = sample.split_by_group_id()
        for group_id in self.individual_samples.keys():
            sample_distribution = SampleDistribution(
                sample=self.individual_samples.get(group_id),
                group_id=group_id)
            sampling_distribution = MeanSamplingDistribution(
                sample_distribution=sample_distribution)
            self.individual_sample_distributions.put(group_id,
                                                     sample_distribution)
            self.individual_sampling_distributions.put(group_id,
                                                       sampling_distribution)

        self.overall_sample_distribution = SampleDistribution(sample=sample,
                                                              group_id=None)
        self.overall_sampling_distribution = MeanSamplingDistribution(
            self.overall_sample_distribution)
        self.build()
Ejemplo n.º 6
0
    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)))
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
    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)