Skip to content

Propensity score Joint Estimation Versus 2 stage Estimation #500

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

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

NathanielF
Copy link
Contributor

@NathanielF NathanielF commented Jul 6, 2025

Working on a draft PR to improve or augment the existing propensity scoring weighting implementation. In particular to make it a bit faster and more "Bayesian". As it currently stands we are performing a two-step strategy where we fit a propensity score model and then push the values of the posterior estimate for the propensity score through a re-weighting routine to estimate the causal contrast.

But we could try and explore a more properly Bayesian model where we fit the propensity score outcome and the model outcome at once in the same model context. This more properly Bayesian and a good bit faster.

See for instance, work here: https://github.com/ajnafa/Latent-Bayesian-MSM by Jordan Nafa and Andrew Heiss

---- EDIT ----

So i think i've finally understood the role of the propensity score in Bayesian estimation and I demonstrate that the two-stage method is what we actually want. The changes i've made are actually quite small. I've added a function to the PyMC model associated with the inverse propensity experiment class.

But in the notebook example i show why this two-stage process is to be preferred over the joint fit model.


📚 Documentation preview 📚: https://causalpy--500.org.readthedocs.build/en/500/

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link

codecov bot commented Jul 6, 2025

Codecov Report

Attention: Patch coverage is 96.36364% with 2 lines in your changes missing coverage. Please review.

Project coverage is 94.62%. Comparing base (fdce5b0) to head (6160a3f).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
causalpy/pymc_models.py 95.12% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #500      +/-   ##
==========================================
+ Coverage   94.59%   94.62%   +0.03%     
==========================================
  Files          28       28              
  Lines        2053     2104      +51     
==========================================
+ Hits         1942     1991      +49     
- Misses        111      113       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@NathanielF NathanielF marked this pull request as ready for review July 11, 2025 22:58
@NathanielF NathanielF changed the title Propensity score latent - DRAFT Propensity score Joint Estimation Versus 2 stage Estimation Jul 11, 2025
Copy link

review-notebook-app bot commented Jul 12, 2025

View / edit / reply to this conversation on ReviewNB

juanitorduz commented on 2025-07-12T08:29:09Z
----------------------------------------------------------------

Can you briefly describe what you want to compare, just to keep the storyline flow?


Copy link

review-notebook-app bot commented Jul 12, 2025

View / edit / reply to this conversation on ReviewNB

juanitorduz commented on 2025-07-12T08:29:10Z
----------------------------------------------------------------

Can you please remove this output ?


Copy link

review-notebook-app bot commented Jul 12, 2025

View / edit / reply to this conversation on ReviewNB

juanitorduz commented on 2025-07-12T08:29:11Z
----------------------------------------------------------------

@NathanielF Thank you for this simulation! I wanted to do this for years, and this makes everything very clear!


Copy link

review-notebook-app bot commented Jul 12, 2025

View / edit / reply to this conversation on ReviewNB

juanitorduz commented on 2025-07-12T08:29:11Z
----------------------------------------------------------------

Could you please add an explanation for this section?


Copy link

review-notebook-app bot commented Jul 12, 2025

View / edit / reply to this conversation on ReviewNB

juanitorduz commented on 2025-07-12T08:29:12Z
----------------------------------------------------------------

Can you please add explanation on what these numbers represent (again, for the non-expert users)


Copy link

review-notebook-app bot commented Jul 12, 2025

View / edit / reply to this conversation on ReviewNB

juanitorduz commented on 2025-07-12T08:29:12Z
----------------------------------------------------------------

can you please remove this output?


Copy link

review-notebook-app bot commented Jul 12, 2025

View / edit / reply to this conversation on ReviewNB

juanitorduz commented on 2025-07-12T08:29:13Z
----------------------------------------------------------------

Can you add explanation of this model comparison


Copy link

review-notebook-app bot commented Jul 12, 2025

View / edit / reply to this conversation on ReviewNB

juanitorduz commented on 2025-07-12T08:29:13Z
----------------------------------------------------------------

Again, can you please add some explanatory test here?


Copy link

review-notebook-app bot commented Jul 12, 2025

View / edit / reply to this conversation on ReviewNB

juanitorduz commented on 2025-07-12T08:29:14Z
----------------------------------------------------------------

Can you please remove this output?


Copy link

review-notebook-app bot commented Jul 12, 2025

View / edit / reply to this conversation on ReviewNB

juanitorduz commented on 2025-07-12T08:29:14Z
----------------------------------------------------------------

Can you please remove this output?


Copy link

review-notebook-app bot commented Jul 12, 2025

View / edit / reply to this conversation on ReviewNB

juanitorduz commented on 2025-07-12T08:29:15Z
----------------------------------------------------------------

can you please add a watemark to get the package versions ?


@juanitorduz
Copy link
Collaborator

@NathanielF I love these examples 💪 ! Maybe you can ask Andrew Heiss or Jordan Nafa for feedback (maybe once we merge it so that this is not a blocker?)

@juanitorduz
Copy link
Collaborator

I left some minor comments about adding more explanatory tests is some sections.

@NathanielF
Copy link
Contributor Author

Thanks @juanitorduz ! Good idea to ask them. Appreciate the quick feedback!!!

Signed-off-by: Nathaniel <[email protected]>
Signed-off-by: Nathaniel <[email protected]>
@NathanielF NathanielF requested a review from drbenvincent July 13, 2025 05:28
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.

2 participants