Skip to content

Commit 837e670

Browse files
committed
improving docstring
2 parents 08463b5 + 77f8d59 commit 837e670

File tree

6 files changed

+171
-100
lines changed

6 files changed

+171
-100
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
python-version: ["3.10", "3.11", "3.12"]
14+
python-version: ["3.11", "3.12", "3.13"]
1515

1616
steps:
1717
- uses: actions/checkout@v4

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ repos:
2525
exclude: &exclude_pattern 'iv_weak_instruments.ipynb'
2626
args: ["--maxkb=1500"]
2727
- repo: https://github.com/astral-sh/ruff-pre-commit
28-
rev: v0.12.10
28+
rev: v0.13.1
2929
hooks:
3030
# Run the linter
3131
- id: ruff

causalpy/pymc_models.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -755,19 +755,29 @@ class InterventionTimeEstimator(PyMCModel):
755755
r"""
756756
Custom PyMC model to estimate the time an intervention took place.
757757
758-
defines the PyMC model :
758+
This model implements three types of changepoints: level shift, trend change, and impulse response.
759+
760+
In words:
761+
- `beta` represents the regression coefficients for the baseline signal `μ`.
762+
- `tau` is the changepoint time, and `w` is a sigmoid function to smooth the transition.
763+
- `level` and `trend` model a linear shift after the changepoint.
764+
- `A` and `lambda` define an impulse response at the changepoint.
765+
- `mu_in` combines the level, trend, and impulse contributions.
766+
- `mu_ts` is the total mean, including baseline and intervention.
767+
- `sigma` is the observation noise.
768+
- Finally, `y` is drawn from a Normal distribution with mean `mu_ts` and standard deviation `sigma`.
759769
760770
.. math::
761-
\beta &\sim \mathrm{Normal}(0, 1) \\
771+
\beta &\sim \mathrm{Normal}(0, 5) \\
762772
\mu &= \beta \cdot X\\
763773
\\
764-
\tau &\sim \mathrm{Uniform}(0, 1) \\
774+
\tau &\sim \mathrm{Uniform}(\text{lower_bound}, \text{upper_bound}) \\
765775
w &= sigmoid(t-\tau) \\
766776
\\
767-
\text{level} &\sim \mathrm{Normal}(0, 1) \\
768-
\text{trend} &\sim \mathrm{Normal}(0, 1) \\
769-
A &\sim \mathrm{Normal}(0, 1) \\
770-
\lambda &\sim \mathrm{HalfNormal}(0, 1) \\
777+
\text{level} &\sim \mathrm{Normal}(0, 5) \\
778+
\text{trend} &\sim \mathrm{Normal}(0, 0.5) \\
779+
A &\sim \mathrm{Normal}(0, 5) \\
780+
\lambda &\sim \mathrm{HalfNormal}(0, 5) \\
771781
\text{impulse} &= A \cdot exp(-\lambda \cdot |t-\tau|) \\
772782
\mu_{in} &= \text{level} + \text{trend} \cdot (t-\tau) + \text{impulse}\\
773783
\\

docs/source/index.md

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,52 +13,50 @@ A Python package focussing on causal inference for quasi-experiments. The packag
1313
To get the latest release you can use pip:
1414

1515
```bash
16-
pip install CausalPy
16+
pip install CausalPy
1717
```
1818

1919
or conda:
2020

2121
```bash
22-
conda install causalpy -c conda-forge
22+
conda install causalpy -c conda-forge
2323
```
2424

2525
Alternatively, if you want the very latest version of the package you can install from GitHub:
2626

2727
```bash
28-
pip install git+https://github.com/pymc-labs/CausalPy.git
28+
pip install git+https://github.com/pymc-labs/CausalPy.git
2929
```
3030

3131
## Quickstart
3232

3333
```python
34-
35-
import causalpy as cp
36-
import matplotlib.pyplot as plt
37-
38-
39-
# Import and process data
40-
df = (
41-
cp.load_data("drinking")
42-
.rename(columns={"agecell": "age"})
43-
.assign(treated=lambda df_: df_.age > 21)
44-
)
45-
46-
# Run the analysis
47-
result = cp.RegressionDiscontinuity(
48-
df,
49-
formula="all ~ 1 + age + treated",
50-
running_variable_name="age",
51-
model=cp.pymc_models.LinearRegression(),
52-
treatment_threshold=21,
53-
)
54-
55-
# Visualize outputs
56-
fig, ax = result.plot();
57-
58-
# Get a results summary
59-
result.summary()
60-
61-
plt.show()
34+
import causalpy as cp
35+
import matplotlib.pyplot as plt
36+
37+
38+
# Import and process data
39+
df = (
40+
cp.load_data("drinking")
41+
.rename(columns={"agecell": "age"})
42+
.assign(treated=lambda df_: df_.age > 21)
43+
)
44+
45+
# Run the analysis
46+
result = cp.RegressionDiscontinuity(
47+
df,
48+
formula="all ~ 1 + age + treated",
49+
running_variable_name="age",
50+
model=cp.pymc_models.LinearRegression(),
51+
treatment_threshold=21,
52+
)
53+
54+
# Visualize outputs
55+
fig, ax = result.plot()
56+
# Get a results summary
57+
result.summary()
58+
59+
plt.show()
6260
```
6361

6462
## Videos

docs/source/notebooks/its_no_treatment_time.ipynb

Lines changed: 122 additions & 59 deletions
Large diffs are not rendered by default.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ description = "Causal inference for quasi-experiments in Python"
1818
readme = "README.md"
1919
license = { file = "LICENSE" }
2020
authors = [{ name = "Ben Vincent", email = "[email protected]" }]
21-
requires-python = ">=3.10"
21+
requires-python = ">=3.11"
2222

2323
# This field lists other packages that your project depends on to run.
2424
# Any package you put here will be installed by pip when your project is

0 commit comments

Comments
 (0)