@@ 37-70 (lines=34) @@ | ||
34 | self.p_value_two_tail < significance_level) |
|
35 | ||
36 | ||
37 | class ProportionDiffTesting(object): |
|
38 | sampling_distribution = None |
|
39 | p_value_one_tail = None |
|
40 | p_value_two_tail = None |
|
41 | mean_null = None |
|
42 | test_statistic = None |
|
43 | significance_level = None |
|
44 | reject_proportion_same = None |
|
45 | ||
46 | def __init__(self, sampling_distribution, significance_level=None): |
|
47 | self.sampling_distribution = sampling_distribution |
|
48 | p_null = (sampling_distribution.grp1_point_estimate + sampling_distribution.grp2_point_estimate) / 2 |
|
49 | self.p_null = p_null |
|
50 | if significance_level is not None: |
|
51 | self.significance_level = significance_level |
|
52 | ||
53 | if self.sampling_distribution.distribution_family == DistributionFamily.normal: |
|
54 | standard_error_null = math.sqrt(p_null * (1 - p_null) / sampling_distribution.sample_size) |
|
55 | Z = sampling_distribution.point_estimate / standard_error_null |
|
56 | self.test_statistic = Z |
|
57 | pf = norm.cdf(Z) |
|
58 | self.p_value_one_tail = 1 - pf |
|
59 | self.p_value_two_tail = self.p_value_one_tail * 2 |
|
60 | else: |
|
61 | standard_error_null = math.sqrt(p_null * (1 - p_null) / sampling_distribution.sample_size) |
|
62 | td_df = sampling_distribution.point_estimate / standard_error_null |
|
63 | self.test_statistic = td_df |
|
64 | pf = t.cdf(td_df, sampling_distribution.df) |
|
65 | self.p_value_one_tail = 1 - pf |
|
66 | self.p_value_two_tail = self.p_value_one_tail * 2 |
|
67 | ||
68 | if significance_level is not None: |
|
69 | self.reject_proportion_same = (self.p_value_one_tail < significance_level, |
|
70 | self.p_value_two_tail < significance_level) |
@@ 42-74 (lines=33) @@ | ||
39 | self.p_value_two_tail < significance_level) |
|
40 | ||
41 | ||
42 | class ProportionTesting(object): |
|
43 | sampling_distribution = None |
|
44 | p_value_one_tail = None |
|
45 | p_value_two_tail = None |
|
46 | mean_null = None |
|
47 | test_statistic = None |
|
48 | significance_level = None |
|
49 | reject_mean_null = None |
|
50 | ||
51 | def __init__(self, sampling_distribution, p_null, significance_level=None): |
|
52 | self.sampling_distribution = sampling_distribution |
|
53 | self.p_null = p_null |
|
54 | if significance_level is not None: |
|
55 | self.significance_level = significance_level |
|
56 | ||
57 | if self.sampling_distribution.distribution_family == DistributionFamily.normal: |
|
58 | standard_error_null = math.sqrt(p_null * (1 - p_null) / sampling_distribution.sample_size) |
|
59 | Z = (sampling_distribution.point_estimate - p_null) / standard_error_null |
|
60 | self.test_statistic = Z |
|
61 | pf = norm.cdf(Z) |
|
62 | self.p_value_one_tail = 1 - pf |
|
63 | self.p_value_two_tail = self.p_value_one_tail * 2 |
|
64 | else: |
|
65 | standard_error_null = math.sqrt(p_null * (1 - p_null) / sampling_distribution.sample_size) |
|
66 | td_df = (sampling_distribution.point_estimate - p_null) / standard_error_null |
|
67 | self.test_statistic = td_df |
|
68 | pf = t.cdf(td_df, sampling_distribution.df) |
|
69 | self.p_value_one_tail = 1 - pf |
|
70 | self.p_value_two_tail = self.p_value_one_tail * 2 |
|
71 | ||
72 | if significance_level is not None: |
|
73 | self.reject_mean_null = (self.p_value_one_tail < significance_level, |
|
74 | self.p_value_two_tail < significance_level) |
|
75 | ||
76 |