class_docstr: Add an unobserved confounder for refutation.
  
  AddUnobservedCommonCause class supports three methods:
      1) Simulation of an unobserved confounder
      2) Linear partial R2 : Sensitivity Analysis for linear models.
      3) Non-Parametric partial R2 based : Sensitivity Analyis for non-parametric models.
  
  Supports additional parameters that can be specified in the refute_estimate() method.
class_docstr_tok: ["Add","an","unobserved","confounder","for","refutation",".","AddUnobservedCommonCause","class","supports","three","methods",":","1",")","Simulation","of","an","unobserved","confounder","2",")","Linear","partial","R2",":","Sensitivity","Analysis","for","linear","models",".","3",")","Non-Parametric","partial","R2","based",":","Sensitivity","Analyis","for","non-parametric","models",".","Supports","additional","parameters","that","can","be","specified","in","the","refute_estimate","(",")","method","."]
docstr: Initialize the parameters required for the refuter.
  
  For direct_simulation, if effect_strength_on_treatment or effect_strength_on_outcome is not
  given, it is calculated automatically as a range between the
  minimum and maximum effect strength of observed confounders on treatment
  and outcome respectively.
  
  :param simulation_method: The method to use for simulating effect of unobserved confounder. Possible values are ["direct-simulation", "linear-partial-R2", "non-parametric-partial-R2", "e-value"].
  :param confounders_effect_on_treatment: str : The type of effect on the treatment due to the unobserved confounder. Possible values are ['binary_flip', 'linear']
  :param confounders_effect_on_outcome: str : The type of effect on the outcome due to the unobserved confounder. Possible values are ['binary_flip', 'linear']
  :param effect_strength_on_treatment: float, numpy.ndarray: [Used when simulation_method="direct-simulation"] Strength of the confounder's effect on treatment. When confounders_effect_on_treatment is linear,  it is the regression coefficient. When the confounders_effect_on_treatment is binary flip, it is the probability with which effect of unobserved confounder can invert the value of the treatment.
  :param effect_strength_on_outcome: float, numpy.ndarray: Strength of the confounder's effect on outcome. Its interpretation depends on confounders_effect_on_outcome and the simulation_method. When simulation_method is direct-simulation, for a linear effect it behaves like the regression coefficient and for a binary flip, it is the probability with which it can invert the value of the outcome.
  :param partial_r2_confounder_treatment: float, numpy.ndarray: [Used when simulation_method is linear-partial-R2 or non-parametric-partial-R2] Partial R2 of the unobserved confounder wrt the treatment conditioned on the observed confounders. Only in the case of general non-parametric-partial-R2, it is the fraction of variance in the reisz representer that is explained by the unobserved confounder; specifically  (1-r), where r is the ratio of variance of reisz representer, alpha^2, based on observed confounders and that based on all confounders.
  :param partial_r2_confounder_outcome: float, numpy.ndarray: [Used when simulation_method is linear-partial-R2 or non-parametric-partial-R2] Partial R2 of the unobserved confounder wrt the outcome conditioned on the treatment and observed confounders.
  :param frac_strength_treatment: float: This parameter decides the effect strength of the simulated confounder as a fraction of the effect strength of observed confounders on treatment. Defaults to 1.
  :param frac_strength_outcome: float: This parameter decides the effect strength of the simulated confounder as a fraction of the effect strength of observed confounders on outcome. Defaults to 1.
  :param plotmethod: string: Type of plot to be shown. If None, no plot is generated. This parameter is used only only when more than one treatment confounder effect values or outcome confounder effect values are provided. Default is "colormesh". Supported values are "contour", "colormesh" when more than one value is provided for both confounder effect value parameters; "line" when provided for only one of them.
  :param percent_change_estimate: It is the percentage of reduction of treatment estimate that could alter the results (default = 1).
                                  if percent_change_estimate = 1, the robustness value describes the strength of association of confounders with treatment and outcome in order to reduce the estimate by 100% i.e bring it down to 0. (relevant only for Linear Sensitivity Analysis, ignore for rest)
  :param confounder_increases_estimate: True implies that confounder increases the absolute value of estimate and vice versa. (Default = False). (relevant only for Linear Sensitivity Analysis, ignore for rest)
  :param benchmark_common_causes: names of variables for bounding strength of confounders. (relevant only for partial-r2 based simulation methods)
  :param significance_level: confidence interval for statistical inference(default = 0.05). (relevant only for partial-r2 based simulation methods)
  :param null_hypothesis_effect: assumed effect under the null hypothesis. (relevant only for linear-partial-R2, ignore for rest)
  :param plot_estimate: Generate contour plot for estimate while performing sensitivity analysis. (default = True).
                        (relevant only for partial-r2 based simulation methods)
  :param num_splits: number of splits for cross validation. (default = 5). (relevant only for non-parametric-partial-R2 simulation method)
  :param shuffle_data : shuffle data or not before splitting into folds (default = False). (relevant only for non-parametric-partial-R2 simulation method)
  :param shuffle_random_seed: seed for randomly shuffling data. (relevant only for non-parametric-partial-R2 simulation method)
  :param alpha_s_estimator_param_list: list of dictionaries with parameters for finding alpha_s. (relevant only for non-parametric-partial-R2 simulation method)
  :param g_s_estimator_list: list of estimator objects for finding g_s. These objects should have fit() and predict() functions implemented. (relevant only for non-parametric-partial-R2 simulation method)
  :param g_s_estimator_param_list: list of dictionaries with parameters for tuning respective estimators in "g_s_estimator_list". The order of the dictionaries in the list should be consistent with the estimator objects order in "g_s_estimator_list". (relevant only for non-parametric-partial-R2 simulation method)
docstr_tok: ["Initialize","the","parameters","required","for","the","refuter",".","For","direct_simulation",",","if","effect_strength_on_treatment","or","effect_strength_on_outcome","is","not","given",",","it","is","calculated","automatically","as","a","range","between","the","minimum","and","maximum","effect","strength","of","observed","confounders","on","treatment","and","outcome","respectively",".",":","param","simulation_method",":","The","method","to","use","for","simulating","effect","of","unobserved","confounder",".","Possible","values","are","[","``","direct-simulation","''",",","``","linear-partial-R2","''",",","``","non-parametric-partial-R2","''",",","``","e-value","''","]",".",":","param","confounders_effect_on_treatment",":","str",":","The","type","of","effect","on","the","treatment","due","to","the","unobserved","confounder",".","Possible","values","are","[","'binary_flip","'",",","'linear","'","]",":","param","confounders_effect_on_outcome",":","str",":","The","type","of","effect","on","the","outcome","due","to","the","unobserved","confounder",".","Possible","values","are","[","'binary_flip","'",",","'linear","'","]",":","param","effect_strength_on_treatment",":","float",",","numpy.ndarray",":","[","Used","when","simulation_method=","''","direct-simulation","''","]","Strength","of","the","confounder","'s","effect","on","treatment",".","When","confounders_effect_on_treatment","is","linear",",","it","is","the","regression","coefficient",".","When","the","confounders_effect_on_treatment","is","binary","flip",",","it","is","the","probability","with","which","effect","of","unobserved","confounder","can","invert","the","value","of","the","treatment",".",":","param","effect_strength_on_outcome",":","float",",","numpy.ndarray",":","Strength","of","the","confounder","'s","effect","on","outcome",".","Its","interpretation","depends","on","confounders_effect_on_outcome","and","the","simulation_method",".","When","simulation_method","is","direct-simulation",",","for","a","linear","effect","it","behaves","like","the","regression","coefficient","and","for","a","binary","flip",",","it","is","the","probability","with","which","it","can","invert","the","value","of","the","outcome",".",":","param","partial_r2_confounder_treatment",":","float",",","numpy.ndarray",":","[","Used","when","simulation_method","is","linear-partial-R2","or","non-parametric-partial-R2","]","Partial","R2","of","the","unobserved","confounder","wrt","the","treatment","conditioned","on","the","observed","confounders",".","Only","in","the","case","of","general","non-parametric-partial-R2",",","it","is","the","fraction","of","variance","in","the","reisz","representer","that","is","explained","by","the","unobserved","confounder",";","specifically","(","1-r",")",",","where","r","is","the","ratio","of","variance","of","reisz","representer",",","alpha^2",",","based","on","observed","confounders","and","that","based","on","all","confounders",".",":","param","partial_r2_confounder_outcome",":","float",",","numpy.ndarray",":","[","Used","when","simulation_method","is","linear-partial-R2","or","non-parametric-partial-R2","]","Partial","R2","of","the","unobserved","confounder","wrt","the","outcome","conditioned","on","the","treatment","and","observed","confounders",".",":","param","frac_strength_treatment",":","float",":","This","parameter","decides","the","effect","strength","of","the","simulated","confounder","as","a","fraction","of","the","effect","strength","of","observed","confounders","on","treatment",".","Defaults","to","1.",":","param","frac_strength_outcome",":","float",":","This","parameter","decides","the","effect","strength","of","the","simulated","confounder","as","a","fraction","of","the","effect","strength","of","observed","confounders","on","outcome",".","Defaults","to","1.",":","param","plotmethod",":","string",":","Type","of","plot","to","be","shown",".","If","None",",","no","plot","is","generated",".","This","parameter","is","used","only","only","when","more","than","one","treatment","confounder","effect","values","or","outcome","confounder","effect","values","are","provided",".","Default","is","``","colormesh","''",".","Supported","values","are","``","contour","''",",","``","colormesh","''","when","more","than","one","value","is","provided","for","both","confounder","effect","value","parameters",";","``","line","''","when","provided","for","only","one","of","them",".",":","param","percent_change_estimate",":","It","is","the","percentage","of","reduction","of","treatment","estimate","that","could","alter","the","results","(","default","=","1",")",".","if","percent_change_estimate","=","1",",","the","robustness","value","describes","the","strength","of","association","of","confounders","with","treatment","and","outcome","in","order","to","reduce","the","estimate","by","100","%","i.e","bring","it","down","to","0",".","(","relevant","only","for","Linear","Sensitivity","Analysis",",","ignore","for","rest",")",":","param","confounder_increases_estimate",":","True","implies","that","confounder","increases","the","absolute","value","of","estimate","and","vice","versa",".","(","Default","=","False",")",".","(","relevant","only","for","Linear","Sensitivity","Analysis",",","ignore","for","rest",")",":","param","benchmark_common_causes",":","names","of","variables","for","bounding","strength","of","confounders",".","(","relevant","only","for","partial-r2","based","simulation","methods",")",":","param","significance_level",":","confidence","interval","for","statistical","inference","(","default","=","0.05",")",".","(","relevant","only","for","partial-r2","based","simulation","methods",")",":","param","null_hypothesis_effect",":","assumed","effect","under","the","null","hypothesis",".","(","relevant","only","for","linear-partial-R2",",","ignore","for","rest",")",":","param","plot_estimate",":","Generate","contour","plot","for","estimate","while","performing","sensitivity","analysis",".","(","default","=","True",")",".","(","relevant","only","for","partial-r2","based","simulation","methods",")",":","param","num_splits",":","number","of","splits","for","cross","validation",".","(","default","=","5",")",".","(","relevant","only","for","non-parametric-partial-R2","simulation","method",")",":","param","shuffle_data",":","shuffle","data","or","not","before","splitting","into","folds","(","default","=","False",")",".","(","relevant","only","for","non-parametric-partial-R2","simulation","method",")",":","param","shuffle_random_seed",":","seed","for","randomly","shuffling","data",".","(","relevant","only","for","non-parametric-partial-R2","simulation","method",")",":","param","alpha_s_estimator_param_list",":","list","of","dictionaries","with","parameters","for","finding","alpha_s",".","(","relevant","only","for","non-parametric-partial-R2","simulation","method",")",":","param","g_s_estimator_list",":","list","of","estimator","objects","for","finding","g_s",".","These","objects","should","have","fit","(",")","and","predict","(",")","functions","implemented",".","(","relevant","only","for","non-parametric-partial-R2","simulation","method",")",":","param","g_s_estimator_param_list",":","list","of","dictionaries","with","parameters","for","tuning","respective","estimators","in","``","g_s_estimator_list","''",".","The","order","of","the","dictionaries","in","the","list","should","be","consistent","with","the","estimator","objects","order","in","``","g_s_estimator_list","''",".","(","relevant","only","for","non-parametric-partial-R2","simulation","method",")"]
code: def __init__(self, *args, **kwargs):
      """
      Initialize the parameters required for the refuter.
  
      For direct_simulation, if effect_strength_on_treatment or effect_strength_on_outcome is not
      given, it is calculated automatically as a range between the
      minimum and maximum effect strength of observed confounders on treatment
      and outcome respectively.
  
      :param simulation_method: The method to use for simulating effect of unobserved confounder. Possible values are ["direct-simulation", "linear-partial-R2", "non-parametric-partial-R2", "e-value"].
      :param confounders_effect_on_treatment: str : The type of effect on the treatment due to the unobserved confounder. Possible values are ['binary_flip', 'linear']
      :param confounders_effect_on_outcome: str : The type of effect on the outcome due to the unobserved confounder. Possible values are ['binary_flip', 'linear']
      :param effect_strength_on_treatment: float, numpy.ndarray: [Used when simulation_method="direct-simulation"] Strength of the confounder's effect on treatment. When confounders_effect_on_treatment is linear,  it is the regression coefficient. When the confounders_effect_on_treatment is binary flip, it is the probability with which effect of unobserved confounder can invert the value of the treatment.
      :param effect_strength_on_outcome: float, numpy.ndarray: Strength of the confounder's effect on outcome. Its interpretation depends on confounders_effect_on_outcome and the simulation_method. When simulation_method is direct-simulation, for a linear effect it behaves like the regression coefficient and for a binary flip, it is the probability with which it can invert the value of the outcome.
      :param partial_r2_confounder_treatment: float, numpy.ndarray: [Used when simulation_method is linear-partial-R2 or non-parametric-partial-R2] Partial R2 of the unobserved confounder wrt the treatment conditioned on the observed confounders. Only in the case of general non-parametric-partial-R2, it is the fraction of variance in the reisz representer that is explained by the unobserved confounder; specifically  (1-r), where r is the ratio of variance of reisz representer, alpha^2, based on observed confounders and that based on all confounders.
      :param partial_r2_confounder_outcome: float, numpy.ndarray: [Used when simulation_method is linear-partial-R2 or non-parametric-partial-R2] Partial R2 of the unobserved confounder wrt the outcome conditioned on the treatment and observed confounders.
      :param frac_strength_treatment: float: This parameter decides the effect strength of the simulated confounder as a fraction of the effect strength of observed confounders on treatment. Defaults to 1.
      :param frac_strength_outcome: float: This parameter decides the effect strength of the simulated confounder as a fraction of the effect strength of observed confounders on outcome. Defaults to 1.
      :param plotmethod: string: Type of plot to be shown. If None, no plot is generated. This parameter is used only only when more than one treatment confounder effect values or outcome confounder effect values are provided. Default is "colormesh". Supported values are "contour", "colormesh" when more than one value is provided for both confounder effect value parameters; "line" when provided for only one of them.
      :param percent_change_estimate: It is the percentage of reduction of treatment estimate that could alter the results (default = 1).
                                      if percent_change_estimate = 1, the robustness value describes the strength of association of confounders with treatment and outcome in order to reduce the estimate by 100% i.e bring it down to 0. (relevant only for Linear Sensitivity Analysis, ignore for rest)
      :param confounder_increases_estimate: True implies that confounder increases the absolute value of estimate and vice versa. (Default = False). (relevant only for Linear Sensitivity Analysis, ignore for rest)
      :param benchmark_common_causes: names of variables for bounding strength of confounders. (relevant only for partial-r2 based simulation methods)
      :param significance_level: confidence interval for statistical inference(default = 0.05). (relevant only for partial-r2 based simulation methods)
      :param null_hypothesis_effect: assumed effect under the null hypothesis. (relevant only for linear-partial-R2, ignore for rest)
      :param plot_estimate: Generate contour plot for estimate while performing sensitivity analysis. (default = True).
                            (relevant only for partial-r2 based simulation methods)
      :param num_splits: number of splits for cross validation. (default = 5). (relevant only for non-parametric-partial-R2 simulation method)
      :param shuffle_data : shuffle data or not before splitting into folds (default = False). (relevant only for non-parametric-partial-R2 simulation method)
      :param shuffle_random_seed: seed for randomly shuffling data. (relevant only for non-parametric-partial-R2 simulation method)
      :param alpha_s_estimator_param_list: list of dictionaries with parameters for finding alpha_s. (relevant only for non-parametric-partial-R2 simulation method)
      :param g_s_estimator_list: list of estimator objects for finding g_s. These objects should have fit() and predict() functions implemented. (relevant only for non-parametric-partial-R2 simulation method)
      :param g_s_estimator_param_list: list of dictionaries with parameters for tuning respective estimators in "g_s_estimator_list". The order of the dictionaries in the list should be consistent with the estimator objects order in "g_s_estimator_list". (relevant only for non-parametric-partial-R2 simulation method)
      """
      super().__init__(*args, **kwargs)
      self.simulation_method = (
          kwargs["simulation_method"]
          if "simulation_method" in kwargs
          else "direct-simulation"
      )
      self.effect_on_t = (
          kwargs["confounders_effect_on_treatment"]
          if "confounders_effect_on_treatment" in kwargs
          else "binary_flip"
      )
      self.effect_on_y = (
          kwargs["confounders_effect_on_outcome"]
          if "confounders_effect_on_outcome" in kwargs
          else "linear"
      )
      if self.simulation_method == "direct-simulation":
          self.kappa_t = (
              kwargs["effect_strength_on_treatment"]
              if "effect_strength_on_treatment" in kwargs
              else None
          )
          self.kappa_y = (
              kwargs["effect_strength_on_outcome"]
              if "effect_strength_on_outcome" in kwargs
              else None
          )
      elif self.simulation_method in [
          "linear-partial-R2",
          "non-parametric-partial-R2",
      ]:
          self.kappa_t = (
              kwargs["partial_r2_confounder_treatment"]
              if "partial_r2_confounder_treatment" in kwargs
              else None
          )
          self.kappa_y = (
              kwargs["partial_r2_confounder_outcome"]
              if "partial_r2_confounder_outcome" in kwargs
              else None
          )
      elif self.simulation_method == "e-value":
          pass
      else:
          raise ValueError(
              "simulation method is not supported. Try direct-simulation, linear-partial-R2, non-parametric-partial-R2, or e-value"
          )
      self.frac_strength_treatment = (
          kwargs["effect_fraction_on_treatment"]
          if "effect_fraction_on_treatment" in kwargs
          else 1
      )
      self.frac_strength_outcome = (
          kwargs["effect_fraction_on_outcome"]
          if "effect_fraction_on_outcome" in kwargs
          else 1
      )
  
      self.plotmethod = (
          kwargs["plotmethod"]
          if "plotmethod" in kwargs
          else "colormesh"
      )
      self.percent_change_estimate = (
          kwargs["percent_change_estimate"]
          if "percent_change_estimate" in kwargs
          else 1.0
      )
      self.significance_level = (
          kwargs["significance_level"]
          if "significance_level" in kwargs
          else 0.05
      )
      self.confounder_increases_estimate = (
          kwargs["confounder_increases_estimate"]
          if "confounder_increases_estimate" in kwargs
          else False
      )
      self.benchmark_common_causes = (
          kwargs["benchmark_common_causes"]
          if "benchmark_common_causes" in kwargs
          else None
      )
      self.null_hypothesis_effect = (
          kwargs["null_hypothesis_effect"]
          if "null_hypothesis_effect" in kwargs
          else 0
      )
      self.plot_estimate = (
          kwargs["plot_estimate"] if "plot_estimate" in kwargs else True
      )
      self.num_splits = (
          kwargs["num_splits"] if "num_splits" in kwargs else 5
      )
      self.shuffle_data = (
          kwargs["shuffle_data"] if "shuffle_data" in kwargs else False
      )
      self.shuffle_random_seed = (
          kwargs["shuffle_random_seed"]
          if "shuffle_random_seed" in kwargs
          else None
      )
      self.alpha_s_estimator_param_list = (
          kwargs["alpha_s_estimator_param_list"]
          if "alpha_s_estimator_param_list" in kwargs
          else None
      )
      self.alpha_s_estimator_list = (
          kwargs["alpha_s_estimator_list"]
          if "alpha_s_estimator_list" in kwargs
          else None
      )
      self.g_s_estimator_list = (
          kwargs["g_s_estimator_list"]
          if "g_s_estimator_list" in kwargs
          else None
      )
      self.g_s_estimator_param_list = (
          kwargs["g_s_estimator_param_list"]
          if "g_s_estimator_param_list" in kwargs
          else None
      )
      self.plugin_reisz = (
          kwargs["plugin_reisz"] if "plugin_reisz" in kwargs else False
      )
      self.logger = logging.getLogger(__name__)
  
imports: import copy
  import logging
  import math
  from typing import Dict, List, Optional, Union
  import numpy
  import pandas
  import scipy.stats
  import statsmodels.api
  from sklearn.linear_model import LogisticRegression
  from sklearn.preprocessing import StandardScaler
  from tqdm.auto import tqdm
  from dowhy.causal_estimator import CausalEstimate
  from dowhy.causal_estimators.econml import Econml
  from dowhy.causal_estimators.linear_regression_estimator import LinearRegressionEstimator
  from dowhy.causal_estimators.regression_estimator import RegressionEstimator
  from dowhy.causal_identifier.identified_estimand import IdentifiedEstimand
  from dowhy.causal_refuter import CausalRefutation, CausalRefuter, choose_variables
  from dowhy.causal_refuters.evalue_sensitivity_analyzer import EValueSensitivityAnalyzer
  from dowhy.causal_refuters.linear_sensitivity_analyzer import LinearSensitivityAnalyzer
label_desc: Use image node_id 1 to create a new AddUnobservedCommonCause object from inherited base classes: CausalRefuter with example: obj = AddUnobservedCommonCause()