Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiply robust #35

Merged
merged 11 commits into from
Jul 30, 2023
Merged

Multiply robust #35

merged 11 commits into from
Jul 30, 2023

Conversation

sami6mz
Copy link
Contributor

@sami6mz sami6mz commented Jul 7, 2023

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
Copy link
Contributor Author

sami6mz commented Jul 7, 2023

my bad, beb5f26 should be named solving #34

src/benchmark_mediation.py Outdated Show resolved Hide resolved
src/benchmark_mediation.py Outdated Show resolved Hide resolved
src/benchmark_mediation.py Outdated Show resolved Hide resolved
direct effect on the unexposed,
indirect effect on the exposed,
indirect effect on the unexposed,
number of clipped samples]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure this is the wanted behavior, the last returned value should have the same meaning in all methods, so the number of discarded observations by trimming, not an alternance of clipped and trimmed examples. WDYT @sami6mz @bthirion?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for consistency

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More importantly, there should be 6 output arguments, not one list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure this is the wanted behavior, the last returned value should have the same meaning in all methods, so the number of discarded observations by trimming, not an alternance of clipped and trimmed examples. WDYT @sami6mz @bthirion?

Then should we keep clipping? Or replace clipping by trimming?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep clipping but not return the number of clipped examples. And potentially open an issue to implement trimming in this method. And another issue to implement clipping in all methods and return 6 results instead of 5 in that case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up removing clipping count with df600a9 + putting the clipping code in issue #39

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep clipping but not return the number of clipped examples. And potentially open an issue to implement trimming in this method. And another issue to implement clipping in all methods and return 6 results instead of 5 in that case

Let's just implement trimming for now, and remove clipping

src/benchmark_mediation.py Outdated Show resolved Hide resolved
src/benchmark_mediation.py Outdated Show resolved Hide resolved
src/benchmark_mediation.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@bthirion bthirion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for the great job !

@@ -66,20 +66,22 @@ def get_interactions(interaction, *args):
[ 2., 3., 1., 2., 2., 3., 4., 6., 2.],
[ 4., 5., 1., 2., 4., 5., 8., 10., 2.]])
"""
variables = args
variables = list(args)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any reason to sue this patterns. Arguments should be passed explicitly.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean to use args directly rather than renaming it variables?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually you can specify a list of variables between which you want to compute interaction terms. Do you think this should be done differently?

src/benchmark_mediation.py Outdated Show resolved Hide resolved
src/benchmark_mediation.py Outdated Show resolved Hide resolved
direct effect on the unexposed,
indirect effect on the exposed,
indirect effect on the unexposed,
number of clipped samples]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for consistency

direct effect on the unexposed,
indirect effect on the exposed,
indirect effect on the unexposed,
number of clipped samples]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More importantly, there should be 6 output arguments, not one list.

src/benchmark_mediation.py Outdated Show resolved Hide resolved
src/benchmark_mediation.py Show resolved Hide resolved
src/benchmark_mediation.py Outdated Show resolved Hide resolved
@judithabk6 judithabk6 merged commit a2d8e02 into judithabk6:main Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants