Skip to content

Commit f261386

Browse files
Remove duplicated 'positivity' check?
1 parent 2ec4026 commit f261386

File tree

1 file changed

+1
-34
lines changed

1 file changed

+1
-34
lines changed

causal_testing/testing/causal_test_case.py

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,6 @@ def execute_test(self, estimator: type(Estimator), data_collector: Observational
9898

9999
logger.info("treatments: %s", treatments)
100100
logger.info("outcomes: %s", outcome_variable)
101-
minimal_adjustment_set = causal_specification.causal_dag.identification(BaseTestCase(treatment_variable, outcome_variable))
102-
minimal_adjustment_set = minimal_adjustment_set - set(treatment_variable.name)
103-
minimal_adjustment_set = minimal_adjustment_set - set(outcome_variable.name)
104-
105-
variables_for_positivity = list(minimal_adjustment_set) + [treatment_variable.name] + [outcome_variable.name]
106-
107-
if self._check_positivity_violation(variables_for_positivity, causal_specification.scenario, data_collector.data):
108-
raise ValueError("POSITIVITY VIOLATION -- Cannot proceed.")
109101

110102
causal_test_result = self._return_causal_test_results(estimator)
111103
return causal_test_result
@@ -130,32 +122,6 @@ def _return_causal_test_results(self, estimator):
130122

131123
return causal_test_result
132124

133-
def _check_positivity_violation(self, variables_list, scenario: Scenario, df):
134-
"""Check whether the dataframe has a positivity violation relative to the specified variables list.
135-
136-
A positivity violation occurs when there is a stratum of the dataframe which does not have any data. Put simply,
137-
if we split the dataframe into covariate sub-groups, each sub-group must contain both a treated and untreated
138-
individual. If a positivity violation occurs, causal inference is still possible using a properly specified
139-
parametric estimator. Therefore, we should not throw an exception upon violation but raise a warning instead.
140-
141-
:param variables_list: The list of variables for which positivity must be satisfied.
142-
:return: True if positivity is violated, False otherwise.
143-
"""
144-
if not (set(variables_list) - {x.name for x in scenario.hidden_variables()}).issubset(
145-
df.columns
146-
):
147-
missing_variables = set(variables_list) - set(df.columns)
148-
logger.warning(
149-
"Positivity violation: missing data for variables %s.\n"
150-
"Causal inference is only valid if a well-specified parametric model is used.\n"
151-
"Alternatively, consider restricting analysis to executions without the variables:"
152-
".",
153-
missing_variables,
154-
)
155-
return True
156-
157-
return False
158-
159125
def __str__(self):
160126
treatment_config = {self.treatment_variable.name: self.treatment_value}
161127
control_config = {self.treatment_variable.name: self.control_value}
@@ -164,3 +130,4 @@ def __str__(self):
164130
f"Running {treatment_config} instead of {control_config} should cause the following "
165131
f"changes to {outcome_variable}: {self.expected_causal_effect}."
166132
)
133+

0 commit comments

Comments
 (0)