Skip to content

Conversation

jessegrabowski
Copy link
Member

This PR adds support for exogenous variables in BayesianVARMAX via the observation intercept. Same deal as SARIMAX -- it's implemented in a way that minimizes the number of states in the system.

Unlike Statsmodels, we have support for each observed state to have its own regressors by passing a dictionary. If you just pass a list, everyone shares the same data.

Example 1: Everyone shares data, data names are auto-assigned

mod = BayesianVARMAX(
        endog_names=["y1", "y2", "y3"],
        order=(1, 0),
        k_exog=2,
    )

Example 2: Everyone shares data, data names are provided

mod = BayesianVARMAX(
        endog_names=["y1", "y2", "y3"],
        order=(1, 0),
        exog_state_names=['x1', 'x2']
    )

Example 3: Each observes state (endogenous state) has its own exogenous regressors. y3 has no exogenous regressors at all, so it is omitted from the dictionary. It just so happens that each observed has its own regressors, but they could also share all or a subset.

mod = BayesianVARMAX(
        endog_names=["y1", "y2", "y3"],
        order=(1, 0),
        exog_state_names={'y1':['x1', 'x2'], 'y2':['x3']}
    )

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 adds support for exogenous regressors to the BayesianVARMAX model via observation intercepts. The implementation allows for flexible configuration where exogenous variables can be shared across all endogenous states or specified individually for each state.

Key changes include:

  • Added exog_state_names and k_exog parameters to support different exogenous variable configurations
  • Implemented data handling and parameter creation for exogenous regression coefficients
  • Added comprehensive validation logic for parameter combinations
  • Extended test coverage for all exogenous variable configuration scenarios

Reviewed Changes

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

File Description
pymc_extras/statespace/models/VARMAX.py Core implementation adding exogenous regressor support with parameter validation, data handling, and symbolic graph construction
tests/statespace/models/test_VARMAX.py Comprehensive test suite covering all exogenous variable configuration cases and error conditions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@jessegrabowski jessegrabowski requested a review from Copilot August 25, 2025 15:06
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@jessegrabowski jessegrabowski requested a review from Copilot August 25, 2025 16:51
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Contributor

@AlexAndorra AlexAndorra left a comment

Choose a reason for hiding this comment

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

Quite the monster review! Thanks @jessegrabowski 🤩

@AlexAndorra AlexAndorra merged commit d5f8f76 into pymc-devs:main Aug 26, 2025
17 checks passed
andreacate pushed a commit to andreacate/pymc-extras that referenced this pull request Aug 27, 2025
* First pass on exogenous variables in VARMA

* Adjust state names for API consistency

* Allow exogenous variables in BayesianVARMAX

* Eagerly simplify model where possible

* Typo fix
jessegrabowski added a commit that referenced this pull request Sep 6, 2025
* Added new file DFM.py for GSOC 2025 Dynamical Factor Models

* Add initial notebook on custom DFM implementation

* Update of DFM draft implementation

In the notebook a comparison between the custom DFM and the implemented DFM (which has an hardcoded version of make_symbolic_graph, that work just in this case)

* Aligning the order of vector state with statsmodel and updating the test

* Added test_DFM_update_matches_statsmodels and small corrections to DFM.py

* Updating test following test_ETS.py and small adjustment for exog variables in DFM.py

* Added support for joint VAR modelling (error_var=True)

* Adding a first implemntation of exogeneous variable support based on pymc_extras/statespace/models/structural/components/regression.py

* Completing the implementation of exogeneous varibales support

* Small adjustments and improvements in DFM.py

* Small adjustments and improvements in DFM.py

* Adjustments after Jesse review

* Adjustments following Jesse suggestions and added tests for exog support

* Added new DFM example notebook and deleted an old version of custom DFM example

* Add tests for names/dims/coords

* De-duplicate exogenous dim between DFM and SARIMAX

* Small adjustments and refactoring after code review

* Allow exogenous regressors in `BayesianVARMAX` (#567)

* First pass on exogenous variables in VARMA

* Adjust state names for API consistency

* Allow exogenous variables in BayesianVARMAX

* Eagerly simplify model where possible

* Typo fix

* Small adjustments in the tests after review

* Harmonizing names for EXOG dimension between DFM and VARMAX

* Corrections in the notebook and add a small comment in DFM.py

* Add deterministic advi (#564)

* Add first version of deterministic ADVI

* Update API

* Add a notebook example

* Add to API and add a docstring

* Change import in notebook

* Add jax to dependencies

* Add pytensor version

* Fix handling of pymc model

* Add (probably suboptimal) handling of the two backends

* Add transformation

* Follow Ricardo's advice to simplify the transformation step

* Fix naming bug

* Document and clean up

* Fix example

* Update pymc_extras/inference/deterministic_advi/dadvi.py

Co-authored-by: Ricardo Vieira <[email protected]>

* Respond to comments

* Fix with pre commit checks

* Update pymc_extras/inference/deterministic_advi/dadvi.py

Co-authored-by: Jesse Grabowski <[email protected]>

* Implement suggestions

* Rename parameter because it's duplicated otherwise

* Rename to be consistent in use of dadvi

* Rename to `optimizer_method` and drop jac=True

* Add jac=True back in since trust-ncg complained

* Make hessp and jac optional

* Harmonize naming with existing code

* Fix example

* Switch to `better_optimize`

* Replace with pt.split

---------

Co-authored-by: Martin Ingram <[email protected]>
Co-authored-by: Ricardo Vieira <[email protected]>
Co-authored-by: Jesse Grabowski <[email protected]>

* Small adjustments in the notebook

---------

Co-authored-by: jessegrabowski <[email protected]>
Co-authored-by: Jesse Grabowski <[email protected]>
Co-authored-by: Martin Ingram <[email protected]>
Co-authored-by: Martin Ingram <[email protected]>
Co-authored-by: Ricardo Vieira <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancements New feature or request statespace
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants