Skip to content

feat: R-compatible summary format with full CausalImpactResults#6

Merged
YuminosukeSato merged 3 commits into
mainfrom
feat/summary-r-compat
Mar 22, 2026
Merged

feat: R-compatible summary format with full CausalImpactResults#6
YuminosukeSato merged 3 commits into
mainfrom
feat/summary-r-compat

Conversation

@YuminosukeSato
Copy link
Copy Markdown
Owner

@YuminosukeSato YuminosukeSato commented Mar 22, 2026

Summary

  • Add 14 new fields to CausalImpactResults to match R CausalImpact summary output
  • Replace "-" placeholders in Actual / Prediction (s.d.) rows with computed values
  • Clamp all s.d. fields to 0 when n_samples=1 to prevent ddof=1 NaN

Changed files

File Change
python/causal_impact/analysis.py Add 14 fields to CausalImpactResults + cross-sample aggregation in compute_effects
python/causal_impact/summary.py R-compatible format (Actual row, Prediction(s.d.) row, 3 CI rows, always show Posterior prob.)
tests/test_summary.py Fix Absolute effect CI row index (7→8) due to new format layout

summary() output (Before → After)

Before:

Actual                   -              -
Prediction (s.d.)        -              -
95% CI                   [9.08, 10.98]  [272.39, 329.38]

After:

Actual                   15.02          450.67
Prediction (s.d.)        10.03 (0.48)   300.89 (14.40)
95% CI                   [9.08, 10.98]  [272.39, 329.38]

Absolute effect (s.d.)   4.99 (0.48)    149.78 (14.40)
95% CI                   [4.04, 5.94]   [121.29, 178.28]

Relative effect (s.d.)   49.8% (4.8%)   49.8% (4.8%)
95% CI                   [40.3%, 59.3%] [40.3%, 59.3%]

Posterior tail-area probability p: 0.001
Posterior prob. of a causal effect: 99.90%

Test plan

  • test_analysis.py: 28 passed (2 previously Red tests now Green)
  • test_summary.py: 8 passed (all 8 previously Red tests now Green)
  • Full test suite: 180 passed
  • ruff check / ruff format: passed

…ible summary format

CausalImpactResults に14個の新フィールドを追加し、summary() 出力を
R CausalImpact と同等のフォーマットに改修。

Why: v0.1.0の summary() 出力には「-」プレースホルダーが残っており、
Actual行やPrediction (s.d.)行が表示できない状態だった。

Changes:
- analysis.py: actual, predictions_sd, average_prediction_sd/lower/upper,
  cumulative_prediction_sd/lower/upper, average_effect_sd,
  cumulative_effect_sd, relative_effect_sd/lower/upper の14フィールド追加
- analysis.py: compute_effects() に cross-sample 集約計算を追加
  (n_samples=1 の ddof=1 NaN を 0 にクランプ)
- summary.py: R互換フォーマット実装 (Actual行、Prediction(s.d.)行、
  3つのCI行、Posterior prob. 常時表示)
- test_summary.py: CI行の行番号修正 (7→8、新フォーマットで行位置変更)
- test_plot.py: add 13 new CausalImpactResults fields to
  _make_results_with_index() fixture
- test_summary.py: shorten test method name to fix E501
- test_analysis.py: shorten two test method names to fix E501
@YuminosukeSato YuminosukeSato merged commit 266ca0c into main Mar 22, 2026
13 checks passed
YuminosukeSato added a commit that referenced this pull request Mar 23, 2026
feat: R-compatible summary format with full CausalImpactResults
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant