pymc-labs / CausalPy

A Python package for causal inference in quasi-experimental settings
https://causalpy.readthedocs.io
Apache License 2.0
845 stars 57 forks source link

ITS: add Bayesian Structural Timeseries model #52

Open drbenvincent opened 1 year ago

drbenvincent commented 1 year ago
NathanielF commented 1 year ago

What were you thinking for this? MVP using jax? Or waiting for a PYMC implementation?

drbenvincent commented 1 year ago

See #116

A pymc implementation would be great, but unsure of the timescale on that. So JAX wrapper seems like the quickest thing. Not sure if @juanitorduz had plans to work on this. But I think we'd be very happy if you wanted to work on it

NathanielF commented 1 year ago

That'd be cool! If there is no objection from. @juanitorduz I'll look into your contribution guide this weekend. Not sure how quick i can be on this, but from a cursory look allot of the heavy lifting seems done already.

juanitorduz commented 1 year ago

Hey! I'm just starting exploring the sts-jax library so feel free to start working on it! I guess we are open regarding the library and framework for a first iteration. I will try to catch up! 🙂 !

juanitorduz commented 1 year ago

Also, check out this project: https://github.com/jamalsenouci/causalimpact uses both statsmodels and pymc

drbenvincent commented 1 year ago

That'd be cool! If there is no objection from. @juanitorduz I'll look into your contribution guide this weekend. Not sure how quick i can be on this, but from a cursory look allot of the heavy lifting seems done already.

Sounds good. Just let me know if you need any pointers. There is a guide there, but we aren't open for general contributors yet, so it's not battle tested.

NathanielF commented 1 year ago

Sorry haven't found the time to look at this properly. Trying to get more into jax following Ravin's book club on Dynamax... but honestly not sure when i'll get to this.

drbenvincent commented 11 months ago

Just dropping in a link to the developments on state space models by @jessegrabowski here https://discourse.pymc.io/t/state-space-models-in-pymc/9146

drbenvincent commented 7 months ago

Tagging @cetagostini

jessegrabowski commented 7 months ago

How do people do causality in STS framework? I'm interested in bringing more tools related to this into what we've already got in the statespace module. I know about granger test and rotated (cholesky decomposed) IRFs, but is there more? Also does the granger test make sense in a Bayesian framework? It always struck me as a glorified t-test.

drbenvincent commented 7 months ago

It would be great to get your input @jessegrabowski. The causal side of things is rich, but possibly the most direct way of working out how time series approaches are used in causality would be to look at Interrupted Time Series:

These examples take the simplistic "linear regression as time series" approach. The next step (which CausalImpact uses) is to Bayesian structural time-series models.

It should be relatively trivial to plug that into CausalPy. We'd just need to adapt the pymc_models.LinearRegression class so that the build_model factory function returns a time series model. Ideally we'd retain the same kind of Wilkinson notation model formula to provide predictor variables, but it's not the end of the world if a slightly different API is needed.

Could be wrong, but I think it's the kind of thing that we could get done in 1 (or just a few) pair coding sessions.