class_docstr: Class to perform sensitivity analysis
  See: https://carloscinelli.com/files/Cinelli%20and%20Hazlett%20(2020)%20-%20Making%20Sense%20of%20Sensitivity.pdf
  
  :param estimator: linear estimator of the causal model
  :param data: Pandas dataframe
  :param treatment_name: name of treatment
   :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.
  :param null_hypothesis_effect: assumed effect under the null hypothesis
  :param confounder_increases_estimate: True implies that confounder increases the absolute value of estimate and vice versa. (Default = True)
  :param benchmark_common_causes: names of variables for bounding strength of confounders
  :param significance_level: confidence interval for statistical inference(default = 0.05)
  :param frac_strength_treatment: strength of association between unobserved confounder and treatment compared to benchmark covariate
  :param frac_strength_outcome: strength of association between unobserved confounder and outcome compared to benchmark covariate
  :param common_causes_order: The order of column names in OLS regression data
class_docstr_tok: ["Class","to","perform","sensitivity","analysis","See",":","https",":","\/\/carloscinelli.com\/files\/Cinelli","%","20and","%","20Hazlett","%","20","(","2020",")","%","20-","%","20Making","%","20Sense","%","20of","%","20Sensitivity.pdf",":","param","estimator",":","linear","estimator","of","the","causal","model",":","param","data",":","Pandas","dataframe",":","param","treatment_name",":","name","of","treatment",":","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.",":","param","null_hypothesis_effect",":","assumed","effect","under","the","null","hypothesis",":","param","confounder_increases_estimate",":","True","implies","that","confounder","increases","the","absolute","value","of","estimate","and","vice","versa",".","(","Default","=","True",")",":","param","benchmark_common_causes",":","names","of","variables","for","bounding","strength","of","confounders",":","param","significance_level",":","confidence","interval","for","statistical","inference","(","default","=","0.05",")",":","param","frac_strength_treatment",":","strength","of","association","between","unobserved","confounder","and","treatment","compared","to","benchmark","covariate",":","param","frac_strength_outcome",":","strength","of","association","between","unobserved","confounder","and","outcome","compared","to","benchmark","covariate",":","param","common_causes_order",":","The","order","of","column","names","in","OLS","regression","data"]
docstr: Function to perform sensitivity analysis.
  :param plot: plot = True generates a plot of point estimate and the variations with respect to unobserved confounding.
               plot = False overrides the setting
  
  :returns: instance of LinearSensitivityAnalyzer class
docstr_tok: ["Function","to","perform","sensitivity","analysis",".",":","param","plot",":","plot","=","True","generates","a","plot","of","point","estimate","and","the","variations","with","respect","to","unobserved","confounding",".","plot","=","False","overrides","the","setting",":","returns",":","instance","of","LinearSensitivityAnalyzer","class"]
code: def check_sensitivity(self, plot=True):
      """
      Function to perform sensitivity analysis.
      :param plot: plot = True generates a plot of point estimate and the variations with respect to unobserved confounding.
                   plot = False overrides the setting
  
      :returns: instance of LinearSensitivityAnalyzer class
      """
  
      self.standard_error = np.array(
          self.estimator_model.bse[1 : (len(self.treatment_name) + 1)]
      )[0]
      self.degree_of_freedom = int(self.estimator_model.df_resid)
      self.estimate = np.array(
          self.estimator_model.params[
              1 : (len(self.treatment_name) + 1)
          ]
      )[0]
      self.t_stats = np.array(
          self.estimator_model.tvalues[self.treatment_name]
      )[0]
  
      # partial R^2 (r2yt_w) is the proportion of variation in outcome uniquely explained by treatment
      partial_r2 = self.partial_r2_func(
          self.estimator_model, self.treatment_name
      )
      RVq = self.robustness_value_func()
      RV_qalpha = self.robustness_value_func(
          alpha=self.significance_level
      )
  
      if self.confounder_increases_estimate:
          self.null_hypothesis_effect = self.estimate * (
              1 - self.percent_change_estimate
          )
      else:
          self.null_hypothesis_effect = self.estimate * (
              1 + self.percent_change_estimate
          )
  
      self.t_stats = (
          self.estimate - self.null_hypothesis_effect
      ) / self.standard_error
      self.partial_f2 = self.t_stats**2 / self.degree_of_freedom
  
      # build a new regression model by considering treatment variables as outcome
      treatment_linear_model = self.treatment_regression()
  
      # r2twj_w is partial R^2 of covariate wj with treatment "t", after conditioning on covariates w(excluding wj)
      # r2ywj_tw is partial R^2 of covariate wj with outcome "y", after conditioning on covariates w(excluding wj) and treatment "t"
      self.r2twj_w = []
      self.r2ywj_tw = []
  
      for covariate in self.benchmark_common_causes:
          self.r2ywj_tw.append(
              self.partial_r2_func(self.estimator_model, covariate)
          )
          self.r2twj_w.append(
              self.partial_r2_func(treatment_linear_model, covariate)
          )
  
      for i in range(len(self.benchmark_common_causes)):
          r2twj_w = self.r2twj_w[i]
          r2ywj_tw = self.r2ywj_tw[i]
  
          # r2tu_w is the partial r^2 from regressing u on t after conditioning on w
          self.r2tu_w = self.frac_strength_treatment * (
              r2twj_w / (1 - r2twj_w)
          )
          if any(val >= 1 for val in self.r2tu_w):
              raise ValueError(
                  "r2tu_w can not be >= 1. Try a lower frac_strength_treatment value"
              )
  
          r2uwj_wt = (
              self.frac_strength_treatment
              * (r2twj_w**2)
              / (
                  (1 - self.frac_strength_treatment * r2twj_w)
                  * (1 - r2twj_w)
              )
          )
          if any(val >= 1 for val in r2uwj_wt):
              raise ValueError(
                  "r2uwj_wt can not be >= 1. Try a lower frac_strength_treatment value"
              )
  
          self.r2yu_tw = (
              (np.sqrt(self.frac_strength_outcome) + np.sqrt(r2uwj_wt))
              / np.sqrt(1 - r2uwj_wt)
          ) ** 2 * (r2ywj_tw / (1 - r2ywj_tw))
          if any(val > 1 for val in self.r2yu_tw):
              for i in range(len(self.r2yu_tw)):
                  if self.r2yu_tw[i] > 1:
                      self.r2yu_tw[i] = 1
              self.logger.warning(
                  "Warning: r2yu_tw can not be > 1. Try a lower frac_strength_treatment. Setting r2yu_tw to 1"
              )
  
          # Compute bias adjusted terms
  
      self.benchmarking_results = self.compute_bias_adjusted(
          self.r2tu_w, self.r2yu_tw
      )
  
      if plot == True:
          self.plot()
  
      self.stats = {
          "estimate": self.estimate,
          "standard_error": self.standard_error,
          "degree of freedom": self.degree_of_freedom,
          "t_statistic": self.t_stats,
          "r2yt_w": partial_r2,
          "partial_f2": self.partial_f2,
          "robustness_value": RVq,
          "robustness_value_alpha": RV_qalpha,
      }
  
      self.benchmarking_results = pd.DataFrame.from_dict(
          self.benchmarking_results
      )
      return self
  
file_path: dowhy/dowhy/causal_refuters/linear_sensitivity_analyzer.py
imports: import logging
  import matplotlib.pyplot
  import numpy
  import pandas
  import statsmodels.api
  from scipy.stats import t
  from dowhy.utils.api import parse_state
label_desc: Use image node_id 6 for calling the LinearSensitivityAnalyzer obj's underlying member method code with example usage: obj.check_sensitivity(plot) and returns: self