@@ -444,9 +444,11 @@ def _get_confidence_intervals(self, model):
444
444
)
445
445
return [ci_low .values [0 ], ci_high .values [0 ]]
446
446
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
+
450
452
dof = model .df_resid
451
453
t_values = model .tvalues
452
454
@@ -458,8 +460,14 @@ def estimate_robustness(self, model, q = 1, alpha = 1):
458
460
459
461
return rv
460
462
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."""
461
470
462
- def estimate_e_value (self , risk_ratio , confidence_intervals : tuple [float , float ]) -> tuple [float , tuple [float , float ]]:
463
471
if risk_ratio >= 1 :
464
472
e = risk_ratio + math .sqrt (risk_ratio * (risk_ratio - 1 ))
465
473
@@ -470,7 +478,7 @@ def estimate_e_value(self, risk_ratio, confidence_intervals: tuple[float, float]
470
478
lower_limit = lower_limit + math .sqrt (lower_limit * (lower_limit - 1 ))
471
479
472
480
return (e , (lower_limit , 1 ))
473
-
481
+
474
482
else :
475
483
risk_ratio_prime = 1 / risk_ratio
476
484
e = risk_ratio_prime + math .sqrt (risk_ratio_prime * (risk_ratio_prime - 1 ))
0 commit comments