pymc-labs/CausalPy

Showcase use of splines in interrupted time series

Open

#475 创建于 2025年5月26日

在 GitHub 查看
 (2 评论) (0 反应) (0 负责人)Python (111 fork)auto 404
documentationgood first issue

仓库指标

Star
 (1,162 star)
PR 合并指标
 (PR 指标待抓取)

描述

At the moment we only have one example of using splines in CausalPy, and that's in a non-Bayesian example of the regression discontinuity design.

I would be interesting to see splines used more, particular in a Bayesian notebook. The easiest way to do this would be to extend the existing Excess deaths due to COVID-19 notebook example which just has a basic linear trend. For example, we could modify the equation to standardize(deaths) ~ 0 + cr(t, df=6) + C(month) + temp to model the trend with a natural cubic spline.

I did give that a quick go, and was able to get a better pre-treatment fit ($R^2=0.75$) than the linear trend model ($R^2=0.71$), however there were $\hat{R}$ convergence problems. This could be also be related to the mismatch between the scale of the data and the (not cleverly chosen priors), and that is what probably lead me to use the standardize function in the patsy model formula. One solution to that might end up being better / automated priors (related to, but not the same as, #387).

It would also be interesting to optionally add in cyclic splines to model annual seasonality.

贡献者指南