Skip to content

Implement Bayesian Structural Time Series (BSTS) #473

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

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ecc143b
Implement Bayesian Structural Time Series (BSTS)
cetagostini May 24, 2025
c49a179
Dependency
cetagostini May 24, 2025
22c2eba
docstring
cetagostini May 24, 2025
858db9c
Massive set of changes
cetagostini May 26, 2025
7ead617
Namings mix
cetagostini May 26, 2025
64c1e60
Fucking gpt
cetagostini May 26, 2025
da47d90
draft adding state space
cetagostini May 26, 2025
f2579f1
Integration with state space
cetagostini May 28, 2025
c48dd97
resolve conflicts with main
drbenvincent Jun 20, 2025
f4da3fb
fix mistake in ITS tests - should still be InterruptedTimeSeries clas…
drbenvincent Jun 20, 2025
0aa7942
Adding BSTS changes and notebook updates
cetagostini Jul 28, 2025
7c71519
Resolve merge conflicts: fix __init__.py imports and remove doctest-m…
cetagostini Jul 28, 2025
af4864a
Merge main into cetagostini/adding_bsts_to_causalpy
cetagostini Jul 28, 2025
3acc970
Add notebook copy file
cetagostini Jul 28, 2025
256d30c
Remove leftover notebook copy file
cetagostini Jul 28, 2025
aab6310
Update notebook execution outputs
cetagostini Jul 28, 2025
31ee9b9
Making its work better
cetagostini Jul 28, 2025
13c0a62
Delete the dot model.
cetagostini Jul 28, 2025
6fd62ce
Merge branch 'main' into cetagostini/adding_bsts_to_causalpy
drbenvincent Jul 29, 2025
163475e
Requested changes
cetagostini Aug 11, 2025
947f02a
moving to drafts
cetagostini Aug 11, 2025
aa2ff9f
Small push
cetagostini Aug 11, 2025
d83664f
quick changes
cetagostini Aug 11, 2025
e8cf6e9
Changing
cetagostini Aug 11, 2025
a2e5e40
Correcting typo
cetagostini Aug 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions causalpy/experiments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,24 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""CausalPy experiment module"""

from .diff_in_diff import DifferenceInDifferences
from .instrumental_variable import InstrumentalVariable
from .interrupted_time_series import InterruptedTimeSeries
from .inverse_propensity_weighting import InversePropensityWeighting
from .prepostnegd import PrePostNEGD
from .regression_discontinuity import RegressionDiscontinuity
from .regression_kink import RegressionKink
from .synthetic_control import SyntheticControl

__all__ = [
"DifferenceInDifferences",
"InstrumentalVariable",
"InversePropensityWeighting",
"PrePostNEGD",
"RegressionDiscontinuity",
"RegressionKink",
"SyntheticControl",
"InterruptedTimeSeries",
]
309 changes: 246 additions & 63 deletions causalpy/experiments/interrupted_time_series.py

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions causalpy/plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,25 @@ def plot_xY(
if plot_hdi_kwargs is None:
plot_hdi_kwargs = {}

# Separate fill_kwargs for az.plot_hdi, as ax.plot doesn't accept them
line_kwargs = plot_hdi_kwargs.copy()
if "fill_kwargs" in line_kwargs:
del line_kwargs["fill_kwargs"]

(h_line,) = ax.plot(
x,
Y.mean(dim=["chain", "draw"]),
ls="-",
**plot_hdi_kwargs,
label=f"{label}",
**line_kwargs, # Use kwargs without fill_kwargs
label=label, # Use the provided label for the mean line
)
ax_hdi = az.plot_hdi(
x,
Y,
hdi_prob=hdi_prob,
fill_kwargs={
"alpha": 0.25,
"label": " ",
},
smooth=False,
ax=ax,
smooth=False, # To prevent warning about resolution with few data points
# Pass original plot_hdi_kwargs which might include fill_kwargs for fill_between
**plot_hdi_kwargs,
)
# Return handle to patch. We get a list of the children of the axis. Filter for just
Expand Down
Loading