class_docstr_tok: []
docstr: Helper function for _get_statistical_significance() (via
  _calculate_significance() function).
  
  :param sample_dict: dictionary of binary samples for equal variance
      comparison.
  :param ref_group: Group to use as reference group for statistical
      significance calculation.
  :param alpha: Level at which to determine statistical significance.
      Default is 5e-2 (0.05).
  
  :return: Dictionary indicating whether each group has equal variance
  (in comparison with reference group)
docstr_tok: ["Helper","function","for","_get_statistical_significance","(",")","(","via","_calculate_significance","(",")","function",")",".",":","param","sample_dict",":","dictionary","of","binary","samples","for","equal","variance","comparison",".",":","param","ref_group",":","Group","to","use","as","reference","group","for","statistical","significance","calculation",".",":","param","alpha",":","Level","at","which","to","determine","statistical","significance",".","Default","is","5e-2","(","0.05",")",".",":","return",":","Dictionary","indicating","whether","each","group","has","equal","variance","(","in","comparison","with","reference","group",")"]
code: def _check_equal_variance(sample_dict, ref_group, alpha=5e-2):
      """
      Helper function for _get_statistical_significance() (via
      _calculate_significance() function).
  
      :param sample_dict: dictionary of binary samples for equal variance
          comparison.
      :param ref_group: Group to use as reference group for statistical
          significance calculation.
      :param alpha: Level at which to determine statistical significance.
          Default is 5e-2 (0.05).
  
      :return: Dictionary indicating whether each group has equal variance
      (in comparison with reference group)
      """
  
      # Immediately set ref_group status for equal variance (with itself): True
  
      eq_variance = {ref_group: True}
  
      for attr_value, sample in sample_dict.items():
          # make default normality_p value (only used when len(sample) < 20)
          # large enough that it is always greater than alpha
          normality_p = np.inf
  
          # skew test requires at least 20 samples
          if len(sample) > 20:
              _, normality_p = stats.normaltest(
                  sample, axis=None, nan_policy="omit"
              )
  
          # if tested normality is False or less than 8 samples, use levene
          # test to check equal variance between groups
          if normality_p < alpha or len(sample) <= 20:
              # if ref_group is not normal, can't use f-test or bartlett test
              # for any samples, so check for equal variance against ref_group
              # using levene test for all groups and return dict
              # (since includes all groups)
              if attr_value == ref_group:
                  for group, sample_list in sample_dict.items():
                      _, equal_variance_p = stats.levene(
                          sample_dict[ref_group],
                          sample_list,
                          center="median",
                      )
  
                      eq_variance[group] = equal_variance_p >= alpha
  
                  return eq_variance
  
              # if a non-ref group is not normal, can't use f-test or bartlett
              # for that group, check for equal variance (against ref_group)
              # using levene test and add result to dictionary
              _, equal_variance_p = stats.levene(
                  sample_dict[ref_group], sample, center="median"
              )
  
              eq_variance[attr_value] = equal_variance_p >= alpha
  
      # for all normally distributed non-ref groups, use bartlett test to
      # check for equal variance (against ref_group). Add results to dict
      untested_groups = (
          sample_dict.keys() - eq_variance.keys() - set(ref_group)
      )
      untested = {
          key: val
          for (key, val) in sample_dict.items()
          if key in untested_groups
      }
      for attr_value, sample_list in untested.items():
          _, equal_variance_p = stats.bartlett(
              sample_dict[ref_group], sample_list
          )
  
          eq_variance[attr_value] = equal_variance_p >= alpha
  
      return eq_variance
  
file_path: aequitas/src/aequitas/bias.py
imports: import logging
  from aequitas.plotting import assemble_ref_groups
  import numpy
  import pandas
  from scipy import stats
label_desc: Use image node_id 8 for calling the Bias obj's underlying member method code with example usage: obj._check_equal_variance(sample_dict, ref_group, alpha) and returns: eq_variance, eq_variance