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 31 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.42857% with 2 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@b63860d). Learn more about missing BASE report.
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
causalpy/pymc_models.py 95.23% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #500   +/-   ##
=======================================
  Coverage        ?   95.15%           
=======================================
  Files           ?       28           
  Lines           ?     2435           
  Branches        ?        0           
=======================================
  Hits            ?     2317           
  Misses          ?      118           
  Partials        ?        0           

☔ 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
Contributor Author

Honestly it's super annoying. Think related to a bug or mismatch between pymc and apple mac: https://discourse.pymc.io/t/dataset-size-dependent-eoferror/11977/14


View entire conversation on ReviewNB

Copy link
Contributor Author

Done.


View entire conversation on ReviewNB

Copy link
Contributor Author

Not sure i remember how to link section headings?


View entire conversation on ReviewNB

Copy link
Contributor Author

I left this as it was


View entire conversation on ReviewNB

Copy link
Contributor Author

added a box to this effect


View entire conversation on ReviewNB

Copy link
Contributor Author

Left this as it was. Seemed overkill


View entire conversation on ReviewNB

Copy link
Contributor Author

added dims


View entire conversation on ReviewNB

Copy link
Contributor Author

added a box to highlight.

Re: IV models. I think it's different the equations aren't directly influencing one another. The outcomes of the two equations in the IV are being modelled in the likelihood as a bivariate potentially correlated pair. I think an instrument plays a different role than a propensity score and the modularity isn't required in the same way.


View entire conversation on ReviewNB

Copy link
Contributor Author

renamed


View entire conversation on ReviewNB

Copy link
Contributor Author

I.E. one prediction doesn't feed into the next, we just allow that there maybe some correlation between both predictions


View entire conversation on ReviewNB

Copy link
Contributor Author

I've added the Fan li reference throughout. It's mainly her talk and paper that i'm referring to here. Added again in the conclusion, rather than here because it's more likely to spur follow up there.


View entire conversation on ReviewNB

Copy link
Contributor Author

Added


View entire conversation on ReviewNB

Copy link
Contributor Author

used item accessor to tidy


View entire conversation on ReviewNB

Copy link
Contributor Author

used item accessor to tidy


View entire conversation on ReviewNB

Copy link
Contributor Author

Fixed


View entire conversation on ReviewNB

Copy link
Contributor Author

hidden


View entire conversation on ReviewNB

Copy link
Contributor Author

added.


View entire conversation on ReviewNB

Copy link
Contributor Author

added reference to Hernan's book here.


View entire conversation on ReviewNB

Copy link
Contributor Author

hidden


View entire conversation on ReviewNB

Copy link
Contributor Author

added more citations


View entire conversation on ReviewNB

Copy link
Contributor Author

hidden


View entire conversation on ReviewNB

Copy link
Contributor Author

added a spline plot and admonition box explaining the idea


View entire conversation on ReviewNB

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