dowhy icon indicating copy to clipboard operation
dowhy copied to clipboard

Problems with multi-valued treatment and parameter 'evaluate_effect_strength'

Open xyb151158 opened this issue 3 years ago • 1 comments

Hi, I encountered two problems when using this library:

1.When my treatment is multi-valued (eg, 0,1,2,3...), how should I set the values of the two parameters ‘control_value’ and ‘treatment_value’ in the CausalModel.estimate_effect() function?

2.Another problem is that when I use the CausalModel.estimate_effect() function, when I set the parameter 'evaluate_effect_strength=True', the program has an error. The error is as follows:

Traceback (most recent call last): File "D:/code/Causal_Inference/dowhy_test.py", line 27, in evaluate_effect_strength=True) File "D:\anconda\install\envs\causal_inference\lib\site-packages\dowhy\causal_model.py", line 316, in estimate_effect estimate = self.causal_estimator.estimate_effect() File "D:\anconda\install\envs\causal_inference\lib\site-packages\dowhy\causal_estimator.py", line 200, in estimate_effect effect_strength_dict = self.evaluate_effect_strength(est) File "D:\anconda\install\envs\causal_inference\lib\site-packages\dowhy\causal_estimator.py", line 592, in evaluate_effect_strength fraction_effect_explained = self._evaluate_effect_strength(estimate, method="fraction-effect") File "D:\anconda\install\envs\causal_inference\lib\site-packages\dowhy\causal_estimator.py", line 606, in _evaluate_effect_strength naive_obs_estimate = self.estimate_effect_naive() File "D:\anconda\install\envs\causal_inference\lib\site-packages\dowhy\causal_estimator.py", line 207, in estimate_effect_naive df_withtreatment = self._data.loc[self._data[self._treatment_name] == 1] File "D:\anconda\install\envs\causal_inference\lib\site-packages\pandas\core\indexing.py", line 879, in getitem return self._getitem_axis(maybe_callable, axis=axis) File "D:\anconda\install\envs\causal_inference\lib\site-packages\pandas\core\indexing.py", line 1097, in _getitem_axis raise ValueError("Cannot index with multidimensional key") ValueError: Cannot index with multidimensional key

xyb151158 avatar May 15 '22 12:05 xyb151158

For the first, you will need to enter the two values that you want to compare (e.g., 0 and 2). If you want to compare multiple values, then you can either 1) run the analysis multiple times, 2) if you believe there is some ordering between the discrete variables, then you can try passing it in as a continuous treatment and fitting a single model.

The second one seems like a bug. Will need some investigation.

amit-sharma avatar Jun 26 '22 09:06 amit-sharma