@@ -359,7 +359,7 @@ def summary(self) -> None:
359359 ... ),
360360 ... )
361361 >>> result.summary()
362- ===============================Synthetic Control ===============================
362+ ==================================Pre-Post Fit=== ===============================
363363 Formula: actual ~ 0 + a + b + c + d + e + f + g
364364 Model coefficients:
365365 a 0.33, 94% HDI [0.30, 0.38]
@@ -757,7 +757,7 @@ def _plot_causal_impact_arrow(self, ax):
757757 def _causal_impact_summary_stat (self ) -> str :
758758 """Computes the mean and 94% credible interval bounds for the causal impact."""
759759 percentiles = self .causal_impact .quantile ([0.03 , 1 - 0.03 ]).values
760- ci = r "$CI_{94\ %}$" + f"[{ percentiles [0 ]:.2f} , { percentiles [1 ]:.2f} ]"
760+ ci = "$CI_{94%}$" + f"[{ percentiles [0 ]:.2f} , { percentiles [1 ]:.2f} ]"
761761 causal_impact = f"{ self .causal_impact .mean ():.2f} , "
762762 return f"Causal impact = { causal_impact + ci } "
763763
@@ -767,16 +767,31 @@ def summary(self) -> None:
767767
768768 Example
769769 --------
770- Assuming `result` is a DiD experiment
771-
770+ >>> import causalpy as cp
771+ >>> df = cp.load_data("did")
772+ >>> seed = 42
773+ >>> result = cp.pymc_experiments.DifferenceInDifferences(
774+ ... df,
775+ ... formula="y ~ 1 + group*post_treatment",
776+ ... time_variable_name="t",
777+ ... group_variable_name="group",
778+ ... model=cp.pymc_models.LinearRegression(
779+ ... sample_kwargs={
780+ ... "target_accept": 0.95,
781+ ... "random_seed": seed,
782+ ... "progressbar": False,
783+ ... }
784+ ... )
785+ ... )
772786 >>> result.summary()
773- ==========================Difference in Differences=========================
787+ =========================== Difference in Differences=== =========================
774788 Formula: y ~ 1 + group*post_treatment
789+ <BLANKLINE>
775790 Results:
776791 Causal impact = 0.51, $CI_{94%}$[0.41, 0.61]
777792 Model coefficients:
778793 Intercept 1.08, 94% HDI [1.03, 1.13]
779- post_treatment[T.True] 0.98, 94% HDI [0.91 , 1.06 ]
794+ post_treatment[T.True] 0.98, 94% HDI [0.92 , 1.05 ]
780795 group 0.16, 94% HDI [0.09, 0.23]
781796 group:post_treatment[T.True] 0.51, 94% HDI [0.41, 0.61]
782797 sigma 0.08, 94% HDI [0.07, 0.10]
@@ -995,19 +1010,35 @@ def summary(self) -> None:
9951010
9961011 Example
9971012 --------
1013+ >>> import causalpy as cp
1014+ >>> df = cp.load_data("rd")
1015+ >>> seed = 42
1016+ >>> result = cp.pymc_experiments.RegressionDiscontinuity(
1017+ ... df,
1018+ ... formula="y ~ 1 + x + treated + x:treated",
1019+ ... model=cp.pymc_models.LinearRegression(
1020+ ... sample_kwargs={
1021+ ... "target_accept": 0.95,
1022+ ... "random_seed": seed,
1023+ ... "progressbar": False,
1024+ ... },
1025+ ... ),
1026+ ... treatment_threshold=0.5,
1027+ ... )
9981028 >>> result.summary()
999- ============================Regression Discontinuity==========================
1029+ ============================Regression Discontinuity============================
10001030 Formula: y ~ 1 + x + treated + x:treated
10011031 Running variable: x
10021032 Threshold on running variable: 0.5
1033+ <BLANKLINE>
10031034 Results:
1004- Discontinuity at threshold = 0.92
1035+ Discontinuity at threshold = 0.91
10051036 Model coefficients:
1006- Intercept 0.09, 94% HDI [0.00, 0.17]
1007- treated[T.True] 2.48 , 94% HDI [1.66, 3.27 ]
1037+ Intercept 0.09, 94% HDI [- 0.00, 0.17]
1038+ treated[T.True] 2.45 , 94% HDI [1.66, 3.28 ]
10081039 x 1.32, 94% HDI [1.14, 1.50]
1009- x:treated[T.True] -3.12 , 94% HDI [-4.17, -2.05]
1010- sigma 0.35 , 94% HDI [0.31, 0.41]
1040+ x:treated[T.True] -3.08 , 94% HDI [-4.17, -2.05]
1041+ sigma 0.36 , 94% HDI [0.31, 0.41]
10111042 """
10121043
10131044 print (f"{ self .expt_type :=^80} " )
@@ -1182,7 +1213,7 @@ def plot(self):
11821213 def _causal_impact_summary_stat (self ) -> str :
11831214 """Computes the mean and 94% credible interval bounds for the causal impact."""
11841215 percentiles = self .causal_impact .quantile ([0.03 , 1 - 0.03 ]).values
1185- ci = r"$CI_{94\ %}$" + f"[{ percentiles [0 ]:.2f} , { percentiles [1 ]:.2f} ]"
1216+ ci = r"$CI_{94%}$" + f"[{ percentiles [0 ]:.2f} , { percentiles [1 ]:.2f} ]"
11861217 causal_impact = f"{ self .causal_impact .mean ():.2f} , "
11871218 return f"Causal impact = { causal_impact + ci } "
11881219
@@ -1192,14 +1223,31 @@ def summary(self) -> None:
11921223
11931224 Example
11941225 --------
1226+ >>> import causalpy as cp
1227+ >>> df = cp.load_data("anova1")
1228+ >>> seed = 42
1229+ >>> result = cp.pymc_experiments.PrePostNEGD(
1230+ ... df,
1231+ ... formula="post ~ 1 + C(group) + pre",
1232+ ... group_variable_name="group",
1233+ ... pretreatment_variable_name="pre",
1234+ ... model=cp.pymc_models.LinearRegression(
1235+ ... sample_kwargs={
1236+ ... "target_accept": 0.95,
1237+ ... "random_seed": seed,
1238+ ... "progressbar": False,
1239+ ... }
1240+ ... )
1241+ ... )
11951242 >>> result.summary()
1196- =================Pretest/posttest Nonequivalent Group Design================
1243+ ================== Pretest/posttest Nonequivalent Group Design=== ================
11971244 Formula: post ~ 1 + C(group) + pre
1245+ <BLANKLINE>
11981246 Results:
1199- Causal impact = 1.89 , $CI_{94%}$[1.70 , 2.07]
1247+ Causal impact = 1.88 , $CI_{94%}$[1.69 , 2.07]
12001248 Model coefficients:
1201- Intercept -0.46 , 94% HDI [-1.17 , 0.22 ]
1202- C(group)[T.1] 1.89 , 94% HDI [1.70 , 2.07]
1249+ Intercept -0.47 , 94% HDI [-1.16 , 0.24 ]
1250+ C(group)[T.1] 1.88 , 94% HDI [1.69 , 2.07]
12031251 pre 1.05, 94% HDI [0.98, 1.12]
12041252 sigma 0.51, 94% HDI [0.46, 0.56]
12051253
0 commit comments