class_docstr_tok: []
docstr: Helper function for _get_statistical_significance. Pulls samples from
  original df, checks for equal variance between population groups and
  reference group, runs t-test between groups and reference group, and
  adds p-values to disparity_df for a given measure (ex: false positives)
  
  :param original_df: a dataframe containing a required raw 'score' column
      and possible raw 'label_value' column.
  :param disparity_df: Expansion of get_crosstabs() output with additional
      columns for disparity metrics and each metric's reference group to
      which significance must be added
  :param attribute: Attribute for which to calculate statistical
      significance of a measure
  :param measure: Measure for which to calculate statistical significance
  :param ref_dict: Dictionary indicating reference group for each
      attribute/ measure combination
  :param alpha: Level at which to determine statistical significance.
      Default is 5e-2 (0.05).
  
  :return: dataframe with same number of rows as the input (crosstab)
      but with additional disparity metrics columns, ref_group_values, and
      statistical significance (p-values) of specific metrics.
docstr_tok: ["Helper","function","for","_get_statistical_significance",".","Pulls","samples","from","original","df",",","checks","for","equal","variance","between","population","groups","and","reference","group",",","runs","t-test","between","groups","and","reference","group",",","and","adds","p-values","to","disparity_df","for","a","given","measure","(","ex",":","false","positives",")",":","param","original_df",":","a","dataframe","containing","a","required","raw","'score","'","column","and","possible","raw","'label_value","'","column",".",":","param","disparity_df",":","Expansion","of","get_crosstabs","(",")","output","with","additional","columns","for","disparity","metrics","and","each","metric","'s","reference","group","to","which","significance","must","be","added",":","param","attribute",":","Attribute","for","which","to","calculate","statistical","significance","of","a","measure",":","param","measure",":","Measure","for","which","to","calculate","statistical","significance",":","param","ref_dict",":","Dictionary","indicating","reference","group","for","each","attribute\/","measure","combination",":","param","alpha",":","Level","at","which","to","determine","statistical","significance",".","Default","is","5e-2","(","0.05",")",".",":","return",":","dataframe","with","same","number","of","rows","as","the","input","(","crosstab",")","but","with","additional","disparity","metrics","columns",",","ref_group_values",",","and","statistical","significance","(","p-values",")","of","specific","metrics","."]
code: def _calculate_significance(
      cls,
      original_df,
      disparity_df,
      attribute,
      measure,
      ref_dict,
      alpha=5e-2,
  ):
      """
      Helper function for _get_statistical_significance. Pulls samples from
      original df, checks for equal variance between population groups and
      reference group, runs t-test between groups and reference group, and
      adds p-values to disparity_df for a given measure (ex: false positives)
  
      :param original_df: a dataframe containing a required raw 'score' column
          and possible raw 'label_value' column.
      :param disparity_df: Expansion of get_crosstabs() output with additional
          columns for disparity metrics and each metric's reference group to
          which significance must be added
      :param attribute: Attribute for which to calculate statistical
          significance of a measure
      :param measure: Measure for which to calculate statistical significance
      :param ref_dict: Dictionary indicating reference group for each
          attribute/ measure combination
      :param alpha: Level at which to determine statistical significance.
          Default is 5e-2 (0.05).
  
      :return: dataframe with same number of rows as the input (crosstab)
          but with additional disparity metrics columns, ref_group_values, and
          statistical significance (p-values) of specific metrics.
  
      """
      binaries_lookup = {
          "label_value": "label_value",
          "binary_fpr": "fpr",
          "binary_tpr": "tpr",
          "binary_tnr": "tnr",
          "binary_fnr": "fnr",
          "binary_score": "score",
          "binary_precision": "precision",
          "binary_npv": "npv",
          "binary_for": "for",
          "binary_fdr": "fdr",
          "binary_ppr": "ppr",
          "binary_pprev": "pprev",
      }
  
      ref_group = ref_dict[attribute][binaries_lookup.get(measure)]
  
      # create dictionary of "samples" (binary values for false positive,
      # false negative, label value, score) based on original data frame
      sample_dict = cls._get_measure_sample(
          original_df=original_df, attribute=attribute, measure=measure
      )
  
      # run SciPy equal variance tests between each group and a given
      # reference group, store results in dictionary to pass to statistical
      # significance tests
      eq_variance_dict = cls._check_equal_variance(
          sample_dict=sample_dict, ref_group=ref_group, alpha=alpha
      )
      # run SciPy statistical significance test between each group and
      # reference group
      for attr_val, eq_var in sample_dict.items():
          _, difference_significance_p = stats.ttest_ind(
              sample_dict[ref_group],
              sample_dict[attr_val],
              axis=None,
              equal_var=eq_variance_dict[attr_val],
              nan_policy="omit",
          )
  
          measure = measure.replace("binary_", "")
  
          # add column to crosstab to indicate statistical significance
          disparity_df.loc[
              disparity_df["attribute_value"] == attr_val,
              measure + "_significance",
          ] = difference_significance_p
  
      return disparity_df
  
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 9 for calling the Bias obj's underlying member method code with example usage: obj._calculate_significance(cls, original_df, disparity_df, attribute, measure, ref_dict, alpha) and returns: disparity_df