dowhy icon indicating copy to clipboard operation
dowhy copied to clipboard

Effect estimation fails when an effect modifier has only one unique value

Open 1betatsu opened this issue 3 years ago • 1 comments
trafficstars

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

  1. Prepare a causal graph and a dataset, in which an effect modifier has only one unique value
  2. Identify effect
  3. Estimate effect
  4. 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.

1betatsu avatar Nov 09 '22 03:11 1betatsu

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.

amit-sharma avatar Nov 15 '22 07:11 amit-sharma

As of version 0.11.1 this no longer raises an error. Should this issue be closed @amit-sharma?

j-at-ch avatar Apr 02 '24 09:04 j-at-ch

Thanks for checking, @j-at-ch . Yes, let me close this issue.

amit-sharma avatar Apr 02 '24 09:04 amit-sharma

Thanks @amit-sharma - I'd like to contribute, so was looking for good first issues. :)

j-at-ch avatar Apr 02 '24 10:04 j-at-ch