@@ 59-86 (lines=28) @@ | ||
56 | significance_level = None |
|
57 | reject_mean_null = None |
|
58 | ||
59 | def __init__(self, sampling_distribution, p_null, significance_level=None): |
|
60 | self.sampling_distribution = sampling_distribution |
|
61 | self.p_null = p_null |
|
62 | if significance_level is not None: |
|
63 | self.significance_level = significance_level |
|
64 | ||
65 | if self.sampling_distribution.distribution_family == DistributionFamily.normal: |
|
66 | standard_error_null = math.sqrt(p_null * (1 - p_null) / sampling_distribution.sample_size) |
|
67 | Z = (sampling_distribution.point_estimate - p_null) / standard_error_null |
|
68 | self.test_statistic = Z |
|
69 | pf = norm.cdf(Z) |
|
70 | if Z < 0: |
|
71 | pf -= 0.5 |
|
72 | self.p_value_one_tail = 1 - pf |
|
73 | self.p_value_two_tail = self.p_value_one_tail * 2 |
|
74 | else: |
|
75 | standard_error_null = math.sqrt(p_null * (1 - p_null) / sampling_distribution.sample_size) |
|
76 | td_df = (sampling_distribution.point_estimate - p_null) / standard_error_null |
|
77 | self.test_statistic = td_df |
|
78 | pf = t.cdf(td_df, sampling_distribution.df) |
|
79 | if td_df < 0: |
|
80 | pf -= 0.5 |
|
81 | self.p_value_one_tail = 1 - pf |
|
82 | self.p_value_two_tail = self.p_value_one_tail * 2 |
|
83 | ||
84 | if significance_level is not None: |
|
85 | self.reject_mean_null = (self.p_value_one_tail < significance_level, |
|
86 | self.p_value_two_tail < significance_level) |
|
87 | ||
88 | ||
@@ 16-43 (lines=28) @@ | ||
13 | significance_level = None |
|
14 | reject_mean_null = None |
|
15 | ||
16 | def __init__(self, sampling_distribution, mean_null, significance_level=None): |
|
17 | self.sampling_distribution = sampling_distribution |
|
18 | self.mean_null = mean_null |
|
19 | if significance_level is not None: |
|
20 | self.significance_level = significance_level |
|
21 | ||
22 | if self.sampling_distribution.distribution_family == DistributionFamily.normal: |
|
23 | standard_error_null = sampling_distribution.standard_error |
|
24 | Z = (sampling_distribution.point_estimate - mean_null) / standard_error_null |
|
25 | self.test_statistic = Z |
|
26 | pf = norm.cdf(Z) |
|
27 | if Z < 0: |
|
28 | pf -= 0.5 |
|
29 | self.p_value_one_tail = 1 - pf |
|
30 | self.p_value_two_tail = self.p_value_one_tail * 2 |
|
31 | else: |
|
32 | standard_error_null = sampling_distribution.standard_error |
|
33 | td_df = (sampling_distribution.point_estimate - mean_null) / standard_error_null |
|
34 | self.test_statistic = td_df |
|
35 | pf = t.cdf(td_df, sampling_distribution.df) |
|
36 | if td_df < 0: |
|
37 | pf -= 0.5 |
|
38 | self.p_value_one_tail = 1 - pf |
|
39 | self.p_value_two_tail = self.p_value_one_tail * 2 |
|
40 | ||
41 | if significance_level is not None: |
|
42 | self.reject_mean_null = (self.p_value_one_tail < significance_level, |
|
43 | self.p_value_two_tail < significance_level) |
|
44 | ||
45 | def will_reject(self, significance_level): |
|
46 |