Skip to content

feat: variable selection priors for SSTS covariates - #1112

Open
anevolbap wants to merge 2 commits into
issue-758-ssts-covariatesfrom
issue-758-ssts-variable-selection
Open

feat: variable selection priors for SSTS covariates#1112
anevolbap wants to merge 2 commits into
issue-758-ssts-covariatesfrom
issue-758-ssts-variable-selection

Conversation

@anevolbap

@anevolbap anevolbap commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Closes #981. Part of #758 (P0). Stacked on #1111, review that one first. Targets pymc6_and_pymcmarketing1_migration.

Adds vs_prior_type ("spike_and_slab", "horseshoe", or "normal", the same set the factory accepts) and vs_hyperparams to StateSpaceTimeSeries, mirroring InstrumentalVariableRegression and reusing causalpy/variable_selection_priors.py unchanged. When set, the beta_exog prior is built by the factory instead of the default. Passing both priors={"beta_exog": ...} and vs_prior_type lets variable selection win, with a warning, same as the IV class. Setting it without covariates raises at build time.

get_inclusion_probabilities() and get_shrinkage_factors() are thin pass-throughs to the factory, which prepares the P6 plotting item of #758.

Known caveat, documented and accepted: beta_exog point estimates shrink toward zero, because P0 (the initial state covariance, unrelated to the P0 priority label of #758) lets the regression states drift away from the parameter. Pinning the exog P0 entries fixes the statistics on paper but makes NUTS pathologically slow, 15+ minutes against about 2, so it is not done here. Counterfactual forecasts ride on the smoothed states, which do recover the truth, and selection uses the inclusion-probability ranking, which is correct.

Tests assert API shape, dims and coords only. The suite mocks pm.sample, so posterior recovery cannot be asserted there. Selection behavior was checked in a prototype and is demonstrated in the notebook in the next PR.

Verified locally with pymc 6.2.0, arviz 1.2.0, pymc-extras 0.14.0: 1407 passed, 17 skipped.

@read-the-docs-community

read-the-docs-community Bot commented Jul 30, 2026

Copy link
Copy Markdown

Documentation build overview

📚 causalpy | 🛠️ Build #33906260 | 📁 Comparing e855435 against latest (7e23946)

  🔍 Preview build  

243 files changed · + 29 added · ± 193 modified · - 21 deleted

+ Added

± Modified

- Deleted

@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.95918% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.19%. Comparing base (b9761e7) to head (e855435).

Files with missing lines Patch % Lines
...salpy/tests/test_integration_its_new_timeseries.py 91.30% 2 Missing ⚠️
Additional details and impacted files
@@                      Coverage Diff                      @@
##           issue-758-ssts-covariates    #1112      +/-   ##
=============================================================
+ Coverage                      97.17%   97.19%   +0.01%     
=============================================================
  Files                            120      120              
  Lines                          21002    21100      +98     
  Branches                        1132     1140       +8     
=============================================================
+ Hits                           20409    20508      +99     
- Misses                           395      396       +1     
+ Partials                         198      196       -2     

☔ View full report in Codecov by Harness.
📢 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.

@anevolbap
anevolbap force-pushed the issue-758-ssts-variable-selection branch from c58c9e3 to d158d16 Compare July 31, 2026 13:06
@anevolbap
anevolbap force-pushed the issue-758-ssts-variable-selection branch from d158d16 to b9da23f Compare July 31, 2026 17:28
@anevolbap
anevolbap marked this pull request as ready for review July 31, 2026 17:32
@anevolbap
anevolbap force-pushed the issue-758-ssts-variable-selection branch from b9da23f to 031c83d Compare August 3, 2026 20:19
@anevolbap
anevolbap force-pushed the issue-758-ssts-variable-selection branch from 031c83d to e13d969 Compare August 4, 2026 02:36
Wire VariableSelectionPrior (spike-and-slab, horseshoe, normal) to the
StateSpaceTimeSeries regression coefficients via vs_prior_type and
vs_hyperparams, mirroring InstrumentalVariableRegression. The generic
prior loop special-cases beta_exog when configured. Expose
get_inclusion_probabilities() and get_shrinkage_factors() pass-throughs
(groundwork for the inclusion plot in #758 P6).

Prototype-verified: sampling is clean and inclusion probabilities rank
true predictors first. beta_exog point estimates attenuate toward zero
because P0 lets the regression states drift from the parameter; pinning
the exog P0 entries fixes that on paper but makes NUTS pathologically
slow, so the caveat is documented instead. Counterfactual forecasts use
the smoothed states and are unaffected.
@anevolbap
anevolbap force-pushed the issue-758-ssts-variable-selection branch from e13d969 to e855435 Compare August 4, 2026 11:23
@drbenvincent drbenvincent added the review:high High-impact change requiring thorough human review label Aug 10, 2026
@drbenvincent

Copy link
Copy Markdown
Collaborator

Automated triage

Recommendation: review:high — no decision gate identified.

Why:

  • Adds variable-selection prior support (spike-and-slab, horseshoe, normal) to StateSpaceTimeSeries — a public API and behavioural change for a causal model class.
  • Introduces new public methods get_inclusion_probabilities() and get_shrinkage_factors().
  • 103 new lines in causalpy/pymc_models.py and 182 new test lines. Targets pymc6_and_pymcmarketing1_migration release branch.
  • All CI checks pass cleanly; patch coverage is verified. Stacked on feat: covariate support for StateSpaceTimeSeries #1111.

Review focus:

  1. Confirm the variable-selection prior factory integration matches the pattern established by InstrumentalVariableRegression.
  2. Verify the documented P0 covariance caveat (NUTS slowdown when pinning exog P0 entries) is acceptable at this stage.
  3. Check that mocked-sample tests sufficiently cover API shape/dims/coords until posterior-behaviour tests land in the follow-up notebook PR.

Confidence: high

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:high High-impact change requiring thorough human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants