Coverage for /Users/sebastiana/Documents/Sugarpills/confidence/spotify_confidence/analysis/frequentist/chi_squared.py: 89%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

9 statements  

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 typing import Union, Iterable 

16 

17from pandas import DataFrame 

18 

19from spotify_confidence.analysis.abstract_base_classes.confidence_computer_abc import ConfidenceComputerABC 

20from spotify_confidence.analysis.abstract_base_classes.confidence_grapher_abc import ConfidenceGrapherABC 

21from spotify_confidence.analysis.constants import BONFERRONI, METHOD_COLUMN_NAME 

22from spotify_confidence.analysis.frequentist.experiment import Experiment 

23 

24 

25class ChiSquared(Experiment): 

26 def __init__( 

27 self, 

28 data_frame: DataFrame, 

29 numerator_column: str, 

30 denominator_column: str, 

31 categorical_group_columns: Union[str, Iterable], 

32 ordinal_group_column: Union[str, None] = None, 

33 interval_size: float = 0.95, 

34 correction_method: str = BONFERRONI, 

35 confidence_computer: ConfidenceComputerABC = None, 

36 confidence_grapher: ConfidenceGrapherABC = None, 

37 metric_column: Union[str, None] = None, 

38 treatment_column: Union[str, None] = None, 

39 ): 

40 super(ChiSquared, self).__init__( 

41 data_frame=data_frame.assign(**{METHOD_COLUMN_NAME: "chi-squared"}), 

42 numerator_column=numerator_column, 

43 numerator_sum_squares_column=numerator_column, 

44 denominator_column=denominator_column, 

45 categorical_group_columns=categorical_group_columns, 

46 ordinal_group_column=ordinal_group_column, 

47 interval_size=interval_size, 

48 correction_method=correction_method, 

49 confidence_computer=confidence_computer, 

50 confidence_grapher=confidence_grapher, 

51 method_column=METHOD_COLUMN_NAME, 

52 metric_column=metric_column, 

53 treatment_column=treatment_column, 

54 power=0.8, 

55 )