Skip to content

Commit 22c2eba

Browse files
committed
docstring
1 parent c49a179 commit 22c2eba

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

causalpy/experiments/structured_time_series.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,14 @@ class StructuredTimeSeries(BaseExperiment):
9292
... model=bsts_model,
9393
... )
9494
>>> result.summary() # doctest: +ELLIPSIS
95-
=========================Structured Time Series Fit=========================
95+
===========================Structured Time Series Fit===========================
9696
Formula: y ~ x1
97+
<BLANKLINE>
98+
Model coefficients (Exogenous Regressors and Error Sigma):
9799
Model coefficients:
98-
...
100+
Intercept 0.0058, 94% HDI [-0.1, 0.099]
101+
x1 1.5, 94% HDI [1.5, 1.5]
102+
sigma 0.31, 94% HDI [0.29, 0.32]
99103
>>> fig, ax = result.plot()
100104
"""
101105

@@ -260,6 +264,16 @@ def summary(self, round_to: Optional[int] = 2) -> None:
260264

261265
print("\nModel coefficients (Exogenous Regressors and Error Sigma):")
262266
if self.labels: # If there were exogenous regressors
267+
# Correctly extract intercept and beta for printing
268+
if "Intercept" in self.model.idata.posterior.coords:
269+
# This branch is unlikely to be hit if patsy handles Intercept
270+
# and we remove it before passing to model, but good for robustness
271+
intercept_samples = az.extract(
272+
self.model.idata.posterior, var_names="Intercept"
273+
)
274+
print(
275+
f" Intercept: {round_num(intercept_samples.mean().data, round_to)}, 94% HDI [{round_num(intercept_samples.quantile(0.03).data, round_to)}, {round_num(intercept_samples.quantile(1 - 0.03).data, round_to)}]"
276+
)
263277
self.model.print_coefficients(labels=self.labels, round_to=round_to)
264278
else:
265279
print(" No exogenous regressors in the model.")

0 commit comments

Comments
 (0)