judithabk6 / med_bench

BSD 3-Clause "New" or "Revised" License
8 stars 3 forks source link

Multiply robust #35

Closed sami6mz closed 11 months ago

sami6mz commented 1 year ago

Multiply_robust estimator is fully implemented according Tchetgen Tchetgen 2012 and Huber 2016. For linear generated data (even with x multidimensional), relative error is around 5% even for indirect effects, which is a noteworthy performance. Docstring was changed, code was made readable, and .ravel() input was rectified (solving #34 and making #14 to progress).

Test code :

from med_bench.src.get_simulated_data import simulate_data
from med_bench.src.benchmark_mediation import *
data = simulate_data(1000, default_rng(4), False, False, 5, 1, 7, "binary", 0.5, 0.5, 0.5, 0.5)
x = data[0]
t = data[1]
m = data[2]
y = data[3]
effects = np.array(data[4:9])

effects_chap = multiply_robust_efficient(y, t, m, x)[0:5]
error = abs((effects_chap - effects) / effects)
print(effects)
print(error)

print(multiply_robust_efficient(y.ravel(), t.ravel(), m, x) == multiply_robust_efficient(y, t, m, x))
sami6mz commented 1 year ago

my bad, beb5f26 should be named solving https://github.com/judithabk6/med_bench/issues/34