Skip to content

Commit ed75d9a

Browse files
committed
Tidy up + format linting
1 parent 77b3377 commit ed75d9a

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

causal_testing/testing/estimators.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,11 @@ def _get_confidence_intervals(self, model):
444444
)
445445
return [ci_low.values[0], ci_high.values[0]]
446446

447-
# https://github.com/carloscinelli/sensemakr/blob/master/R/sensitivity_stats.R
448-
# Line 132
449-
def estimate_robustness(self, model, q = 1, alpha = 1):
447+
def estimate_robustness(self, model, q=1, alpha=1):
448+
"""Calculate the robustness of a linear regression model. This allow
449+
the user to identify how large an unidentified confounding variable
450+
would need to be to nullify the causal relationship under test."""
451+
450452
dof = model.df_resid
451453
t_values = model.tvalues
452454

@@ -458,8 +460,14 @@ def estimate_robustness(self, model, q = 1, alpha = 1):
458460

459461
return rv
460462

463+
def estimate_e_value(
464+
self, risk_ratio, confidence_intervals: tuple[float, float]
465+
) -> tuple[float, tuple[float, float]]:
466+
"""Calculate the E value from a risk ratio. This allow
467+
the user to identify how large a risk an unidentified confounding
468+
variable would need to be to nullify the causal relationship
469+
under test."""
461470

462-
def estimate_e_value(self, risk_ratio, confidence_intervals: tuple[float, float]) -> tuple[float, tuple[float, float]]:
463471
if risk_ratio >= 1:
464472
e = risk_ratio + math.sqrt(risk_ratio * (risk_ratio - 1))
465473

@@ -470,7 +478,7 @@ def estimate_e_value(self, risk_ratio, confidence_intervals: tuple[float, float]
470478
lower_limit = lower_limit + math.sqrt(lower_limit * (lower_limit - 1))
471479

472480
return (e, (lower_limit, 1))
473-
481+
474482
else:
475483
risk_ratio_prime = 1 / risk_ratio
476484
e = risk_ratio_prime + math.sqrt(risk_ratio_prime * (risk_ratio_prime - 1))

0 commit comments

Comments
 (0)