Completed
Push — master ( f89968...a9e9bf )
by Xianshun
01:02
created

test_confidence_interval_with_sample_student()   A

Complexity

Conditions 2

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
dl 13
loc 13
rs 9.4285
c 1
b 0
f 0
1
import unittest
2
3
from numpy.random import normal
4
5
from pysie.stats.distributions import MeanSamplingDistribution, DistributionFamily
6
from pysie.stats.samples import Sample, SampleDistribution
7
8
9
class MeanSamplingDistributionUnitTest(unittest.TestCase):
10
11
    def test_confidence_interval_with_sample_stats_normal(self):
12
        sample_mean = 0
13
        sample_sd = 1
14
        sample_size = 31
15
        sampling_distribution = MeanSamplingDistribution(sample_mean=sample_mean, sample_sd=sample_sd, sample_size=sample_size)
16
        self.assertEqual(sampling_distribution.distribution_family, DistributionFamily.normal)
17
        print('sampling distribution: (point_estimate = ' + str(sampling_distribution.point_estimate) + ', standard_error=' + str(sampling_distribution.standard_error) + ')')
18
        print('confidence interval for 95% confidence level: ' + str(sampling_distribution.confidence_interval(0.95)))
19
20 View Code Duplication
    def test_confidence_interval_with_sample_normal(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
21
        mu = 0.0
22
        sigma = 1.0
23
        sample_size = 31
24
        sample = Sample()
25
26
        for i in range(sample_size):
27
            sample.add_numeric(normal(mu, sigma))
28
29
        sampling_distribution = MeanSamplingDistribution(sample_distribution=SampleDistribution(sample))
30
        self.assertEqual(sampling_distribution.distribution_family, DistributionFamily.normal)
31
        print('sampling distribution: (point_estimate = ' + str(sampling_distribution.point_estimate) + ', standard_error=' + str(sampling_distribution.standard_error) + ')')
32
        print('confidence interval for 95% confidence level: ' + str(sampling_distribution.confidence_interval(0.95)))
33
34
    def test_confidence_interval_with_sample_stats_student(self):
35
        sample_mean = 0
36
        sample_sd = 1
37
        sample_size = 29
38
        sampling_distribution = MeanSamplingDistribution(sample_mean=sample_mean, sample_sd=sample_sd, sample_size=sample_size)
39
        self.assertEqual(sampling_distribution.distribution_family, DistributionFamily.student_t)
40
        print('sampling distribution: (point_estimate = ' + str(sampling_distribution.point_estimate) + ', standard_error=' + str(sampling_distribution.standard_error) + ')')
41
        print('confidence interval for 95% confidence level: ' + str(sampling_distribution.confidence_interval(0.95)))
42
43 View Code Duplication
    def test_confidence_interval_with_sample_student(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
44
        mu = 0.0
45
        sigma = 1.0
46
        sample_size = 29
47
        sample = Sample()
48
49
        for i in range(sample_size):
50
            sample.add_numeric(normal(mu, sigma))
51
52
        sampling_distribution = MeanSamplingDistribution(sample_distribution=SampleDistribution(sample))
53
        self.assertEqual(sampling_distribution.distribution_family, DistributionFamily.student_t)
54
        print('sampling distribution: (point_estimate = ' + str(sampling_distribution.point_estimate) + ', standard_error=' + str(sampling_distribution.standard_error) + ')')
55
        print('confidence interval for 95% confidence level: ' + str(sampling_distribution.confidence_interval(0.95)))
56
57
if __name__ == '__main__':
58
    unittest.main()
59