1# Copyright 2017-2020 Spotify AB
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from abc import ABC, abstractmethod
16from typing import Union, Iterable, List, Tuple
17
18from pandas import DataFrame
19
20from ..constants import NIM_TYPE
21
22
23class ConfidenceComputerABC(ABC):
24 @abstractmethod
25 def compute_summary(self, verbose: bool) -> DataFrame:
26 """Return Pandas DataFrame with summary statistics."""
27 pass
28
29 @abstractmethod
30 def compute_difference(
31 self,
32 level_1: Union[str, Iterable],
33 level_2: Union[str, Iterable],
34 absolute: bool,
35 groupby: Union[str, Iterable],
36 nims: NIM_TYPE,
37 final_expected_sample_size_column: str,
38 verbose: bool,
39 mde_column: str,
40 ) -> DataFrame:
41 """Return dataframe containing the difference in means between
42 group 1 and 2, p-value and confidence interval
43 """
44 pass
45
46 @abstractmethod
47 def compute_multiple_difference(
48 self,
49 level: Union[str, Iterable],
50 absolute: bool,
51 groupby: Union[str, Iterable],
52 level_as_reference: bool,
53 nims: NIM_TYPE,
54 final_expected_sample_size_column: str,
55 verbose: bool,
56 mde_column: str,
57 ) -> DataFrame:
58 """Return dataframe containing the difference in means between
59 level and all other groups, with p-value and confidence interval
60 """
61 pass
62
63 def compute_differences(
64 self,
65 levels: List[Tuple],
66 absolute: bool,
67 groupby: Union[str, Iterable],
68 nims: NIM_TYPE,
69 final_expected_sample_size_column: str,
70 verbose: bool,
71 mde_column: str,
72 ) -> DataFrame:
73 """Return dataframe containing the difference in means between
74 level and all other groups, with p-value and confidence interval
75 """
76 pass
77
78 def achieved_power(
79 self,
80 level_1: Union[str, Iterable],
81 level_2: Union[str, Iterable],
82 mde: float,
83 alpha: float,
84 groupby: Union[str, Iterable],
85 ) -> DataFrame:
86 """Calculated the achieved power of test of differences between
87 level 1 and level 2 given a targeted MDE.
88
89 Args:
90 level_1 (str, tuple of str): Name of first level.
91 level_2 (str, tuple of str): Name of second level.
92 mde (float): Absolute minimal detectable effect size.
93 alpha (float): Type I error rate, cutoff value for determining
94 statistical significance.
95 groupby (str): Name of column.
96 If specified, will return the difference for each level
97 of the grouped dimension.
98
99 Returns:
100 Pandas DataFrame with the following columns:
101 - level_1: Name of level 1.
102 - level_2: Name of level 2.
103 - power: 1 - B, where B is the likelihood of a Type II (false
104 negative) error.
105 """
106 pass