Skip to content

Commit 5e099c2

Browse files
committed
update summary method to make this work + re-run example notebook
1 parent 6e47576 commit 5e099c2

File tree

2 files changed

+47
-19
lines changed

2 files changed

+47
-19
lines changed

causalpy/pymc_experiments.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ def __init__(
992992
**kwargs,
993993
):
994994
super().__init__(model=model, **kwargs)
995-
self.expt_type = "Regression Discontinuity"
995+
self.expt_type = "Regression Kink"
996996
self.data = data
997997
self.formula = formula
998998
self.running_variable_name = running_variable_name
@@ -1084,12 +1084,7 @@ def _input_validation(self):
10841084
)
10851085

10861086
def _is_treated(self, x):
1087-
"""Returns ``True`` if `x` is greater than or equal to the treatment threshold.
1088-
1089-
.. warning::
1090-
1091-
Assumes treatment is given to those ABOVE the treatment threshold.
1092-
"""
1087+
"""Returns ``True`` if `x` is greater than or equal to the treatment threshold.""" # noqa: E501
10931088
return np.greater_equal(x, self.kink_point)
10941089

10951090
def plot(self):
@@ -1148,11 +1143,9 @@ def summary(self) -> None:
11481143
print(f"{self.expt_type:=^80}")
11491144
print(f"Formula: {self.formula}")
11501145
print(f"Running variable: {self.running_variable_name}")
1151-
print(f"Threshold on running variable: {self.kink_point}")
1146+
print(f"Kink point on running variable: {self.kink_point}")
11521147
print("\nResults:")
1153-
print(
1154-
f"Discontinuity at threshold = {self.discontinuity_at_threshold.mean():.2f}"
1155-
)
1148+
print(f"Change in slope at kink point = {self.gradient_change.mean():.2f}")
11561149
self.print_coefficients()
11571150

11581151

docs/source/notebooks/rkink_pymc.ipynb

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,41 @@
345345
"We know that the correct gradient change is 2, and that we have correctly recovered it as the posterior distribution is centred around 2."
346346
]
347347
},
348+
{
349+
"cell_type": "markdown",
350+
"metadata": {},
351+
"source": [
352+
"We can also ask for summary information:"
353+
]
354+
},
355+
{
356+
"cell_type": "code",
357+
"execution_count": 8,
358+
"metadata": {},
359+
"outputs": [
360+
{
361+
"name": "stdout",
362+
"output_type": "stream",
363+
"text": [
364+
"================================Regression Kink=================================\n",
365+
"Formula: y ~ 1 + x + I((x-0.5)*treated)\n",
366+
"Running variable: x\n",
367+
"Kink point on running variable: 0.5\n",
368+
"\n",
369+
"Results:\n",
370+
"Change in slope at kink point = 1.93\n",
371+
"Model coefficients:\n",
372+
"Intercept -0.01, 94% HDI [-0.02, 0.01]\n",
373+
"x -0.99, 94% HDI [-1.01, -0.96]\n",
374+
"I((x - 0.5) * treated) 1.93, 94% HDI [1.77, 2.10]\n",
375+
"sigma 0.04, 94% HDI [0.03, 0.05]\n"
376+
]
377+
}
378+
],
379+
"source": [
380+
"result1.summary()"
381+
]
382+
},
348383
{
349384
"cell_type": "markdown",
350385
"metadata": {},
@@ -368,7 +403,7 @@
368403
},
369404
{
370405
"cell_type": "code",
371-
"execution_count": 8,
406+
"execution_count": 9,
372407
"metadata": {},
373408
"outputs": [
374409
{
@@ -400,7 +435,7 @@
400435
},
401436
{
402437
"cell_type": "code",
403-
"execution_count": 9,
438+
"execution_count": 10,
404439
"metadata": {},
405440
"outputs": [
406441
{
@@ -461,7 +496,7 @@
461496
"name": "stderr",
462497
"output_type": "stream",
463498
"text": [
464-
"Sampling 4 chains for 5_000 tune and 1_000 draw iterations (20_000 + 4_000 draws total) took 10 seconds.\n",
499+
"Sampling 4 chains for 5_000 tune and 1_000 draw iterations (20_000 + 4_000 draws total) took 11 seconds.\n",
465500
"Sampling: [beta, sigma, y_hat]\n",
466501
"Sampling: [y_hat]\n",
467502
"Sampling: [y_hat]\n",
@@ -510,7 +545,7 @@
510545
},
511546
{
512547
"cell_type": "code",
513-
"execution_count": 10,
548+
"execution_count": 11,
514549
"metadata": {},
515550
"outputs": [
516551
{
@@ -542,7 +577,7 @@
542577
},
543578
{
544579
"cell_type": "code",
545-
"execution_count": 11,
580+
"execution_count": 12,
546581
"metadata": {},
547582
"outputs": [
548583
{
@@ -576,7 +611,7 @@
576611
},
577612
{
578613
"cell_type": "code",
579-
"execution_count": 12,
614+
"execution_count": 13,
580615
"metadata": {},
581616
"outputs": [
582617
{
@@ -611,7 +646,7 @@
611646
},
612647
{
613648
"cell_type": "code",
614-
"execution_count": 13,
649+
"execution_count": 14,
615650
"metadata": {},
616651
"outputs": [
617652
{
@@ -709,7 +744,7 @@
709744
},
710745
{
711746
"cell_type": "code",
712-
"execution_count": 14,
747+
"execution_count": 15,
713748
"metadata": {},
714749
"outputs": [
715750
{

0 commit comments

Comments
 (0)