Skip to content

Enable multiple treated units in synthetic control quasi experiments #494

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

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

drbenvincent
Copy link
Collaborator

@drbenvincent drbenvincent commented Jun 28, 2025

Closes #456


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

Copy link

codecov bot commented Jun 28, 2025

Codecov Report

Attention: Patch coverage is 98.50374% with 6 lines in your changes missing coverage. Please review.

Project coverage is 95.13%. Comparing base (632c457) to head (25608ef).

Files with missing lines Patch % Lines
causalpy/tests/test_pymc_models.py 98.20% 3 Missing ⚠️
causalpy/pymc_models.py 95.74% 2 Missing ⚠️
causalpy/experiments/synthetic_control.py 97.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #494      +/-   ##
==========================================
+ Coverage   94.59%   95.13%   +0.54%     
==========================================
  Files          28       28              
  Lines        2053     2384     +331     
==========================================
+ Hits         1942     2268     +326     
- Misses        111      116       +5     

☔ 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.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@drbenvincent
Copy link
Collaborator Author

Note to self

Relatively happy with where this is at now.

I should do more manual inspection of the tests (which were vibe coded).

There is definitely scope to remove some conditional branching if we set the likelihood of all models to be 1 dimensions. So it would change from (n_obs,) and turn into (n_obs,1). But I think I'll leave that for another PR potentially.

@drbenvincent drbenvincent requested a review from Copilot June 29, 2025 13:07
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enables handling multiple treated units throughout the synthetic control workflow by updating documentation, extending the PyMC models, and adding comprehensive multi-unit tests.

  • Added sphinx-togglebutton for interactive docs
  • Extended PyMCModel and WeightedSumFitter to accept and process multiple treated units
  • Updated SyntheticControl class and added end-to-end tests for multi-unit scenarios

Reviewed Changes

Copilot reviewed 6 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pyproject.toml Added sphinx-togglebutton to docs dependencies
docs/source/conf.py Registered sphinx_togglebutton extension
causalpy/tests/test_pymc_models.py Added fixtures and tests for multi-unit WeightedSumFitter
causalpy/tests/test_integration_pymc_examples.py Added fixtures and integration tests for multi-unit SyntheticControl
causalpy/pymc_models.py Updated _data_setter, predict, score, and coefficient printing to support multi-unit
causalpy/experiments/synthetic_control.py Renamed dims (control_unitscoeffs), parameterized plots and data getters for treated units

The likelihood of all models is now 2 dimensional. This means we don't have to do conditional branching for single vs multiple treatment units. So we've been able to remove a lot of the code in PyMCModel. This has touched a number of experiment classes which are not related to synthetic control.
@drbenvincent
Copy link
Collaborator Author

That last commit was quite a big one. Model likelihoods are now 2-dimensional. This means we can avoid a lot of conditional branching based on single vs multiple treated unit situations.

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.

Upgrade synthetic control to model multiple treated units
1 participant