Skip to content

Commit 4bf81b2

Browse files
black + pylint
1 parent 2c09cc3 commit 4bf81b2

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

causal_testing/testing/estimators.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ def compute_confidence_intervals(self) -> list[float, float]:
8585

8686

8787
class RegressionEstimator(Estimator):
88-
""" """
88+
"""An abstract class extending the Estimator functionality to add support for formulae, which are used in
89+
regression based estimators.
90+
91+
"""
8992

9093
def __init__(
9194
# pylint: disable=too-many-arguments
@@ -121,7 +124,14 @@ def add_modelling_assumptions(self):
121124
must hold if the resulting causal inference is to be considered valid.
122125
"""
123126

124-
def get_terms_from_formula(self):
127+
def get_terms_from_formula(self) -> tuple(str, str, list[str]):
128+
"""
129+
Parse all the terms from a Patsy formula string into outcome, treatment and covariate variables.
130+
131+
Formulae are expected to only have a single left hand side term.
132+
133+
:return: a truple containing the outcome, treatment and covariate variable names in string format
134+
"""
125135
desc = ModelDesc.from_formula(self.formula)
126136
if len(desc.lhs_termlist) > 1:
127137
raise ValueError("More than 1 left hand side term provided in formula, only single term is accepted")
@@ -138,6 +148,14 @@ def get_terms_from_formula(self):
138148
return outcome, self.treatment, covariates
139149

140150
def validate_formula(self, causal_dag: CausalDAG):
151+
"""
152+
Validate the provided Patsy formula string using the constructive backdoor criterion method found in the
153+
CausalDAG class
154+
155+
:param causal_dag: A CausalDAG object containing for the current test scenario
156+
:return: True for a formula that does not violate the criteria and False if the formula does violate the
157+
criteria
158+
"""
141159
outcome, treatment, covariates = self.get_terms_from_formula()
142160
proper_backdoor_graph = causal_dag.get_proper_backdoor_graph(treatments=[treatment], outcomes=[outcome])
143161
return causal_dag.constructive_backdoor_criterion(

0 commit comments

Comments
 (0)