Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0c7ae25
Reporting enhancements
JeanVanDyk Nov 24, 2025
8eb35fc
Adding comparison in summary
JeanVanDyk Nov 24, 2025
08ff806
Updating Plots
JeanVanDyk Nov 24, 2025
ed6d759
Merge branch 'main' of https://github.com/pymc-labs/CausalPy into thr…
JeanVanDyk Nov 24, 2025
af5c78d
Updating doctest
JeanVanDyk Nov 24, 2025
69c4587
Delete planning.md
JeanVanDyk Nov 24, 2025
8f3edad
Delete fix_seasonality.py
JeanVanDyk Nov 24, 2025
7fd3fce
Delete issue.md
JeanVanDyk Nov 24, 2025
61f57b3
Delete simplify_data.py
JeanVanDyk Nov 24, 2025
9ccaa6c
Fixing pre commit
JeanVanDyk Nov 24, 2025
9c0b3c5
Merge branch 'three_period' of https://github.com/JeanVanDyk/CausalPy…
JeanVanDyk Nov 24, 2025
01de784
Merge branch 'three_period' of https://github.com/JeanVanDyk/CausalPy…
JeanVanDyk Nov 24, 2025
a7f92f9
Merge branch 'three_period' of https://github.com/JeanVanDyk/CausalPy…
JeanVanDyk Nov 24, 2025
467dc51
Moving note up and updating in its_pymc
JeanVanDyk Nov 24, 2025
ce448cf
Updating Intro an Title of its_post_intervention_analysis
JeanVanDyk Nov 24, 2025
2a75e7a
Updating visualisation and summary
JeanVanDyk Nov 24, 2025
74d3e77
Adding it into index
JeanVanDyk Nov 24, 2025
2375ab1
Update lift test
JeanVanDyk Nov 24, 2025
73ea19c
Update lift test
JeanVanDyk Nov 24, 2025
9751f9f
Updating docs
JeanVanDyk Nov 25, 2025
102f441
Merge branch 'main' into pr/575
drbenvincent Nov 29, 2025
42cb3aa
tweaks to new fixed intervention ITS notebook
drbenvincent Nov 29, 2025
e3e0f2f
fix cross reference
drbenvincent Nov 29, 2025
9ef98ad
clarification on fixed point intervention definition
drbenvincent Nov 29, 2025
2ffcd46
minor notebook tweaks
drbenvincent Nov 29, 2025
50dc878
minor tweaks to the its lift test notebook
drbenvincent Nov 29, 2025
3328951
wrap text output + minor simplification + re-run
drbenvincent Nov 29, 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
816 changes: 778 additions & 38 deletions causalpy/experiments/interrupted_time_series.py

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions causalpy/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,12 +629,13 @@ def _compute_statistics(
cumulative=True,
relative=True,
min_effect=None,
time_dim="obs_ind",
):
"""Compute all summary statistics from posterior draws."""
stats = {}

# Average effect over window
avg_effect = impact.mean(dim="obs_ind")
avg_effect = impact.mean(dim=time_dim)
stats["avg"] = {
"mean": float(avg_effect.mean(dim=["chain", "draw"]).values),
"median": float(avg_effect.median(dim=["chain", "draw"]).values),
Expand Down Expand Up @@ -677,9 +678,9 @@ def _compute_statistics(
# Cumulative effect
if cumulative:
# Use cumulative sum over window
cum_effect = impact.cumsum(dim="obs_ind")
cum_effect = impact.cumsum(dim=time_dim)
# Take final value (cumulative over entire window)
cum_final = cum_effect.isel(obs_ind=-1)
cum_final = cum_effect.isel({time_dim: -1})

stats["cum"] = {
"mean": float(cum_final.mean(dim=["chain", "draw"]).values),
Expand Down Expand Up @@ -720,7 +721,7 @@ def _compute_statistics(
# Relative effects
if relative:
epsilon = 1e-8 # Guard against division by zero
counterfactual_mean = counterfactual.mean(dim="obs_ind")
counterfactual_mean = counterfactual.mean(dim=time_dim)
rel_avg = (avg_effect / (counterfactual_mean + epsilon)) * 100

stats["avg"]["relative_mean"] = float(
Expand All @@ -746,7 +747,9 @@ def _compute_statistics(

if cumulative:
# Relative cumulative: (cumulative effect / cumulative counterfactual) * 100
counterfactual_cum = counterfactual.cumsum(dim="obs_ind").isel(obs_ind=-1)
counterfactual_cum = counterfactual.cumsum(dim=time_dim).isel(
{time_dim: -1}
)
rel_cum = (cum_final / (counterfactual_cum + epsilon)) * 100

stats["cum"]["relative_mean"] = float(
Expand Down Expand Up @@ -850,6 +853,7 @@ def _generate_prose(
direction="increase",
cumulative=True,
relative=True,
prefix="Post-period",
):
"""Generate prose summary from statistics."""
hdi_pct = int((1 - alpha) * 100)
Expand Down Expand Up @@ -883,7 +887,7 @@ def fmt_num(x, decimals=2):
direction_text = "effect"

prose_parts = [
f"Post-period ({window_str}), the average effect was {fmt_num(avg_mean)} "
f"{prefix} ({window_str}), the average effect was {fmt_num(avg_mean)} "
f"({hdi_pct}% HDI [{fmt_num(avg_lower)}, {fmt_num(avg_upper)}]), "
f"with a posterior probability of an {direction_text} of {fmt_num(p_val, 3)}."
]
Expand Down Expand Up @@ -1138,6 +1142,7 @@ def _generate_prose_ols(
alpha=0.05,
cumulative=True,
relative=True,
prefix="Post-period",
):
"""Generate prose summary for OLS models."""
ci_pct = int((1 - alpha) * 100)
Expand All @@ -1161,7 +1166,7 @@ def fmt_num(x, decimals=2):
p_val = stats["avg"]["p_value"]

prose_parts = [
f"Post-period ({window_str}), the average effect was {fmt_num(avg_mean)} "
f"{prefix} ({window_str}), the average effect was {fmt_num(avg_mean)} "
f"({ci_pct}% CI [{fmt_num(avg_lower)}, {fmt_num(avg_upper)}]), "
f"with a p-value of {fmt_num(p_val, 3)}."
]
Expand Down
Loading