Skip to content

BayesianBasisExpansionTimeSeries default priors collapse to a flat-line fit on large-magnitude series #935

Description

@kylejcaron

Summary

The default priors on BayesianBasisExpansionTimeSeries (and its sub-components LinearTrend + YearlyFourier/WeeklyFourier) assume data on smaller magnitudes. When fit on time series with magnitude ~10⁴ or larger, the posterior collapses and the counterfactual is essentially a flat line at the intercept, with no trend or seasonality picked up at all.

Nothing in the docs or warnings flags this and basically causes a silent failure.

Solutions could include target scaling or scaling priors based on the pre-intervention dataset

Reproducer

import numpy as np, pandas as pd, causalpy
from causalpy.pymc_models import BayesianBasisExpansionTimeSeries
from pymc_marketing.mmm import WeeklyFourier

rng = np.random.default_rng(0)
n = 800
dates = pd.date_range("2023-01-01", periods=n, freq="D")

# realistic-scale series: trend + weekly seasonality + noise
trend = 50_000 + np.arange(n) * 20
weekly = 8_000 * np.sin(2 * np.pi * np.arange(n) / 7)
y = trend + weekly + rng.normal(0, 3_000, n)
df = pd.DataFrame({"treated": y}, index=dates)

model = BayesianBasisExpansionTimeSeries(n_order=6)
its = causalpy.InterruptedTimeSeries(
  data=df,
  treatment_time=pd.Timestamp("2024-12-01"),
  formula="treated ~ 1",
  model=model,
)
its.plot()  # → near-flat line; no trend, no weekly cycle

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions