BiomedSciAI / causallib

A Python package for modular causal inference analysis and model evaluations
Apache License 2.0
728 stars 97 forks source link

Matching more neighbors than the number of examples in the treatment group #37

Closed michalshap closed 2 years ago

michalshap commented 2 years ago

Hello,

If I have 10 examples in my "treated" group and 1000 in the "control" group, Is it possible to do one-side matching (match control to treatment) of more than 10 neighbors (e.g. 50)?

I tried using the "matching_mode" argument in causallib.estimation.Matching for one-directional matching, but still got the error "Expected n_neighbors <= n_samples" when using matcher.match.

Thank you!

mmdanziger commented 2 years ago

That's a good point. Behind the scenes both directions are calculated at once which is why the matching_mode keyword does not stop the error from occurring. I think a valid behavior would be to reduce the number of neighbors for the problematic direction and then calculate both directions, and to issue a warning so that the user knows that one direction is not actually using the desired number of neighbors. I'll open a PR addressing this shortly.

ehudkr commented 2 years ago

Changes are now available in version 0.9.0 https://github.com/IBM/causallib/releases/tag/v0.9.0