How to use the dowhy.causal_refuter.CausalRefutation function in dowhy

To help you get started, we’ve selected a few dowhy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / dowhy / dowhy / causal_refuters / placebo_treatment_refuter.py View on Github external
def refute_estimate(self):
        num_rows = self._data.shape[0]
        if self._placebo_type == "permute":
            new_treatment = self._data[self._treatment_name].sample(frac=1).values
        else:
            new_treatment = np.random.randn(num_rows)
        new_data = self._data.assign(placebo=new_treatment)

        self.logger.debug(new_data[0:10])
        estimator_class = self._estimate.params['estimator_class']
        identified_estimand = copy.deepcopy(self._target_estimand)
        identified_estimand.treatment_variable = ["placebo"]

        new_estimator = self.get_estimator_object(new_data, identified_estimand, self._estimate)
        new_effect = new_estimator.estimate_effect()
        refute = CausalRefutation(self._estimate.value, new_effect.value,
                                  refutation_type="Refute: Use a Placebo Treatment")
        return refute
github microsoft / dowhy / dowhy / causal_refuters / add_unobserved_common_cause.py View on Github external
def refute_estimate(self):
        new_data = copy.deepcopy(self._data)
        new_data = self.include_confounders_effect(new_data)

        new_estimator = self.get_estimator_object(new_data, self._target_estimand, self._estimate)
        new_effect = new_estimator.estimate_effect()
        refute = CausalRefutation(self._estimate.value, new_effect.value,
                                  refutation_type="Refute: Add an Unobserved Common Cause")
        return refute
github microsoft / dowhy / dowhy / causal_refuters / random_common_cause.py View on Github external
# Adding a new backdoor variable to the identified estimand
        identified_estimand.backdoor_variables = new_backdoor_variables
        new_estimator = estimator_class(
                new_data,
                identified_estimand,
                self._treatment_name, self._outcome_name, #names of treatment and outcome
                test_significance=None,
                evaluate_effect_strength=False,
                confidence_intervals = self._estimate.params["confidence_intervals"],
                target_units = self._estimate.params["target_units"],
                effect_modifiers = self._estimate.params["effect_modifiers"],
                params=self._estimate.params["method_params"]
                )
        new_effect = new_estimator.estimate_effect()
        refute = CausalRefutation(self._estimate.value, new_effect.value,
                                  refutation_type="Refute: Add a Random Common Cause")
        return refute
github microsoft / dowhy / dowhy / causal_refuters / data_subset_refuter.py View on Github external
def refute_estimate(self):
        new_data = self._data.sample(frac=self._subset_fraction)

        new_estimator = self.get_estimator_object(new_data, self._target_estimand, self._estimate)
        new_effect = new_estimator.estimate_effect()

        refute = CausalRefutation(
            self._estimate.value,
            new_effect.value,
            refutation_type="Refute: Use a subset of data"
        )
        return refute