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_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_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)
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)