dowhy
dowhy copied to clipboard
Effect estimation fails when an effect modifier has only one unique value
Describe the bug
When an effect modifier has only one unique value, effect estimation fails and issues logs as below.
ValueError: zero-size array to reduction operation maximum which has no identity
Steps to reproduce the behavior
- Prepare a causal graph and a dataset, in which an effect modifier has only one unique value
- Identify effect
- Estimate effect
- See
ValueError: zero-size array to reduction operation maximum which has no identity
import dowhy.datasets
from dowhy.do_samplers.weighting_sampler import WeightingSampler
from dowhy import CausalModel
df = dowhy.datasets.linear_dataset(
beta=10,
num_common_causes=1,
num_samples=500,
num_treatments=1,
num_effect_modifiers=1,
treatment_is_category=False,
treatment_is_binary=True,
stddev_treatment_noise=10,
stddev_outcome_noise=5,
)
intervention_variable = "v0"
target_variable = "y"
# Effect moddifier's values are modified to a unique value
df_modified = df['df'].copy()
df_modified["X0"] = 1
model =CausalModel(
data=df_modified,
treatment=intervention_variable,
outcome=target_variable,
graph=df['gml_graph'],
test_significance=None,
)
model.view_model()
# Identification
identification = model.identify_effect(proceed_when_unidentifiable=True)
# Estimate effect
estimate = model.estimate_effect(
identification,
method_name="backdoor.linear_regression",
treatment_value=1,
control_value=0,
)
Expected behavior Effect estimation works successfully. I'm not sure if this error is an expected one or a bug that could be fixed.
Version information:
- DoWhy version 0.8
Additional context Nothing.
Thanks for flagging this @1betatsu . If the effect modifier has only one unique value, I'm not sure that the model can learn conditional effects. Essentially, it will learn the same effect for all inputs.
So the code should raise an error, but I agree that we should make the error more informative.
As of version 0.11.1 this no longer raises an error. Should this issue be closed @amit-sharma?
Thanks for checking, @j-at-ch . Yes, let me close this issue.
Thanks @amit-sharma - I'd like to contribute, so was looking for good first issues. :)