Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1079 commits
Select commit Hold shift + click to select a range
aa9920a
code simplification relating to _get_score_title
drbenvincent Jun 28, 2025
ebddbb5
another code simplification - related to scoring
drbenvincent Jun 28, 2025
eac1ef3
code simplification in _ols_plot
drbenvincent Jun 28, 2025
1a5f9bd
code simplification related to PyMCModel._data_setter
drbenvincent Jun 28, 2025
e67a28c
add sphinx-togglebutton for a collapsible admonition + other updates …
drbenvincent Jun 29, 2025
d0fc0d3
update uml diagrams
drbenvincent Jun 29, 2025
b6f5ca8
PyMCModel.score always to get xr.DataArray arguments
drbenvincent Jun 29, 2025
8badc05
simplification to PyMC.print_coefficients
drbenvincent Jun 29, 2025
4a78a50
simplification of WeightedSumFitter.build_model
drbenvincent Jun 29, 2025
f1849b1
clean up PyMCModel.predict + PyMCModel._data_setter
drbenvincent Jun 29, 2025
a55f97d
remove a numerical index in favour of a named dimension
drbenvincent Jun 29, 2025
6341e53
make code comment more specific
drbenvincent Jun 29, 2025
2befccb
consolidate tests, fix doctest
drbenvincent Jun 29, 2025
990104d
point to the conftest file in make command
williambdean Jun 29, 2025
632c457
Merge pull request #493 from pymc-labs/code-cov
drbenvincent Jun 29, 2025
c3b6423
Merge branch 'main' into mock-sample
williambdean Jun 29, 2025
78be544
Merge branch 'main' into multi-cell-geolift
drbenvincent Jun 29, 2025
37e8de7
set fixture scope to module
drbenvincent Jun 30, 2025
4911fed
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jun 30, 2025
d0c520f
towards a more unified scoring (r2) approach
drbenvincent Jun 30, 2025
3ee430e
more unification with score (r2) in terms of unified naming: unit_{n}_r2
drbenvincent Jun 30, 2025
adf04f9
refactor PyMCModel.score
drbenvincent Jun 30, 2025
25608ef
the grand simplification
drbenvincent Jun 30, 2025
2fba338
tweak docstring
drbenvincent Jun 30, 2025
8b26d42
Merge pull request #497 from pymc-labs/pre-commit-ci-update-config
drbenvincent Jul 3, 2025
fdce5b0
Merge pull request #489 from williambdean/mock-sample
drbenvincent Jul 5, 2025
4e63dfa
Merge branch 'main' into multi-cell-geolift
drbenvincent Jul 5, 2025
04ace83
update class diagram
drbenvincent Jul 5, 2025
192327d
re-run relevant notebooks
drbenvincent Jul 5, 2025
2243004
add new data set
NathanielF Jul 6, 2025
b4ee4f1
adding latent prop_score notebook
NathanielF Jul 6, 2025
96098cb
using ps in outcome model
NathanielF Jul 7, 2025
8200202
update interrupted time series notebook
drbenvincent Jul 7, 2025
123331f
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jul 7, 2025
a834d84
adding spline function on the propensity score
NathanielF Jul 8, 2025
71b3741
adding centred and non-centred options
NathanielF Jul 8, 2025
acd8112
tidying
NathanielF Jul 8, 2025
5367e1a
Merge pull request #502 from pymc-labs/pre-commit-ci-update-config
drbenvincent Jul 9, 2025
e094981
proving feedback issue and corrective
NathanielF Jul 9, 2025
ad4e6c3
update with write up
NathanielF Jul 9, 2025
0fd40cc
tidying spellings
NathanielF Jul 9, 2025
e9df0d5
improving the simulation study
NathanielF Jul 10, 2025
a18f83b
full run through
NathanielF Jul 10, 2025
8ab06ac
adding plots of prop score distributions
NathanielF Jul 11, 2025
d2035f8
adding some tests and a conclusion
NathanielF Jul 11, 2025
6aea139
adding video resource and notebook to how-to
NathanielF Jul 11, 2025
ec8173f
adding some more test coverage
NathanielF Jul 11, 2025
6f3aa02
fixing spelling error
NathanielF Jul 11, 2025
127698a
adjusting for some Juan's comments
NathanielF Jul 12, 2025
e88e4c0
fixing typos
NathanielF Jul 12, 2025
b48b82c
adding datasets
NathanielF Jul 12, 2025
0c806b8
remove beta_ps interaction
NathanielF Jul 12, 2025
98cca2f
fix observed keyword for student liklihood
NathanielF Jul 13, 2025
855b499
demonstrate the usefulness of spline component
NathanielF Jul 13, 2025
6160a3f
update colour scheme on graphs
NathanielF Jul 13, 2025
2f5eada
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jul 14, 2025
185a03e
Merge pull request #503 from pymc-labs/pre-commit-ci-update-config
drbenvincent Jul 15, 2025
8579a14
less confusing variable names
drbenvincent Jul 16, 2025
3101cdc
improve type hints
drbenvincent Jul 16, 2025
b213b0f
combined=True in az.plot_forest in brexit synthetic control example
drbenvincent Jul 16, 2025
5998680
Merge branch 'main' into its-notebook-clarification
drbenvincent Jul 16, 2025
0449370
Merge pull request #494 from pymc-labs/multi-cell-geolift
drbenvincent Jul 16, 2025
0288dc4
Merge branch 'main' into its-notebook-clarification
drbenvincent Jul 16, 2025
a4e0a95
fix typo
drbenvincent Jul 16, 2025
04e31df
flesh out more detail about causal impact in the interrupted time ser…
drbenvincent Jul 17, 2025
60bab33
streamline the text and fix some grammatical issues
drbenvincent Jul 18, 2025
b63860d
Merge pull request #504 from pymc-labs/its-causal-impact-details
drbenvincent Jul 18, 2025
2644412
Merge branch 'main' into its-notebook-clarification
drbenvincent Jul 18, 2025
3ade07c
manually resolve notebook conflicts 🤷🏻‍♂️
drbenvincent Jul 18, 2025
ac22b5c
elaborate on the mean causal impact, including adding an equation
drbenvincent Jul 18, 2025
a58f671
update with ben's comments
NathanielF Jul 18, 2025
2970854
add new data set
NathanielF Jul 6, 2025
e6d9b30
Merge branch 'main' into propensity_score_latent
NathanielF Jul 18, 2025
e6f6a53
add reference
NathanielF Jul 19, 2025
2da3007
add simple regression to highlight effect of prop score,
NathanielF Jul 19, 2025
e290244
fix issue with N not being used
drbenvincent Jul 19, 2025
67d550d
Add explanation about np.ones
drbenvincent Jul 19, 2025
8f2f136
"business decisions" -> "decisions"
drbenvincent Jul 19, 2025
6566232
Merge pull request #501 from pymc-labs/its-notebook-clarification
drbenvincent Jul 19, 2025
548d723
allow priors on propensity score parameters
NathanielF Jul 19, 2025
e933420
Handle integer treated variable in RegressionDiscontinuity
drbenvincent Jul 19, 2025
05fccdd
remove redundant alpha parameter in model class
NathanielF Jul 19, 2025
ae451cd
add winsorisation option and better priors for nhefs
NathanielF Jul 19, 2025
4d79f45
Update UML Diagrams
github-actions[bot] Jul 21, 2025
1bfa065
Merge pull request #508 from pymc-labs/update-uml-diagrams
drbenvincent Jul 21, 2025
50df840
version bump
drbenvincent Jul 24, 2025
54a4b57
Merge pull request #510 from pymc-labs/version-bump-0.5.0
drbenvincent Jul 24, 2025
318dd6c
[pre-commit.ci] pre-commit autoupdate (#509)
pre-commit-ci[bot] Jul 24, 2025
7fbe255
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jul 28, 2025
0aa7942
Adding BSTS changes and notebook updates
cetagostini Jul 28, 2025
7c71519
Resolve merge conflicts: fix __init__.py imports and remove doctest-m…
cetagostini Jul 28, 2025
af4864a
Merge main into cetagostini/adding_bsts_to_causalpy
cetagostini Jul 28, 2025
3acc970
Add notebook copy file
cetagostini Jul 28, 2025
256d30c
Remove leftover notebook copy file
cetagostini Jul 28, 2025
aab6310
Update notebook execution outputs
cetagostini Jul 28, 2025
31ee9b9
Making its work better
cetagostini Jul 28, 2025
13c0a62
Delete the dot model.
cetagostini Jul 28, 2025
229b4ec
Merge pull request #512 from pymc-labs/pre-commit-ci-update-config
drbenvincent Jul 29, 2025
ae81faa
address ben's final comments
NathanielF Jul 29, 2025
d4ba5be
Merge pull request #500 from NathanielF/propensity_score_latent
NathanielF Jul 29, 2025
3d3f482
Merge pull request #506 from pymc-labs/regression-discontinuity-treat…
drbenvincent Jul 29, 2025
09adfd7
Merge pull request #505 from pymc-labs/gen-time-series-data
drbenvincent Jul 29, 2025
6fd62ce
Merge branch 'main' into cetagostini/adding_bsts_to_causalpy
drbenvincent Jul 29, 2025
7ff87ee
update quasi dag for pre/post NEGD
drbenvincent Aug 1, 2025
2d6944e
Multiple refinements
drbenvincent Aug 2, 2025
1908b7c
remove redundant stuff
drbenvincent Aug 2, 2025
7313813
callout box for why tau is the ATE
drbenvincent Aug 4, 2025
cfee6f1
correct the discussion about backdoor path 3 and U_1
drbenvincent Aug 4, 2025
f7bde1e
add the do operator to make the intervention more clear
drbenvincent Aug 4, 2025
090772b
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Aug 4, 2025
9f5c8a4
update DAG formatting + sentence on conditional ignorability
drbenvincent Aug 5, 2025
6d2e5a7
fix typo
drbenvincent Aug 5, 2025
07e1119
Merge pull request #517 from pymc-labs/ancova
drbenvincent Aug 5, 2025
2016ff8
Merge pull request #518 from pymc-labs/pre-commit-ci-update-config
drbenvincent Aug 5, 2025
163475e
Requested changes
cetagostini Aug 11, 2025
947f02a
moving to drafts
cetagostini Aug 11, 2025
aa2ff9f
Small push
cetagostini Aug 11, 2025
d83664f
quick changes
cetagostini Aug 11, 2025
e8cf6e9
Changing
cetagostini Aug 11, 2025
a2e5e40
Correcting typo
cetagostini Aug 11, 2025
d7fcb43
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Aug 25, 2025
20f498a
Merge pull request #520 from pymc-labs/pre-commit-ci-update-config
drbenvincent Aug 28, 2025
e999480
Update UML Diagrams
github-actions[bot] Aug 28, 2025
e6e0037
Merge pull request #523 from pymc-labs/update-uml-diagrams
drbenvincent Aug 29, 2025
23e0f3e
Improve clarity of TWFE explanation (#522)
mercury0100 Aug 29, 2025
91ecda2
[pre-commit.ci] pre-commit autoupdate (#525)
pre-commit-ci[bot] Sep 27, 2025
b264193
remove spaces from previous code-block (#527)
williambdean Sep 29, 2025
77f8d59
drop python 3.10, add 3.13 (#529)
drbenvincent Sep 29, 2025
540893b
Support for custom priors via Prior class (#488)
williambdean Oct 3, 2025
673e805
[pre-commit.ci] pre-commit autoupdate (#530)
pre-commit-ci[bot] Oct 3, 2025
cdb4986
Merge branch 'main' into cetagostini/adding_bsts_to_causalpy
cetagostini Oct 3, 2025
89c7191
Changes by Nathaniel
cetagostini Oct 3, 2025
51689b8
[pre-commit.ci] pre-commit autoupdate (#531)
pre-commit-ci[bot] Oct 7, 2025
cbffe8e
attempt to get intersphinx mapping working with pymc-extras
drbenvincent Oct 11, 2025
b5ec091
run `make uml`
drbenvincent Oct 11, 2025
d78c0d6
[pre-commit.ci] pre-commit autoupdate (#535)
pre-commit-ci[bot] Oct 14, 2025
edb7f8d
[pre-commit.ci] pre-commit autoupdate (#536)
pre-commit-ci[bot] Oct 21, 2025
a9ccbfb
adding knowledgebase on SCM
NathanielF Oct 23, 2025
6c620a8
tidying spell check
NathanielF Oct 23, 2025
1d79fee
improve binary modelling with BART
NathanielF Oct 23, 2025
72c8104
update with CATE RUN
NathanielF Oct 24, 2025
6da45fd
add visual of probabilistic causal inference
NathanielF Oct 24, 2025
b01c6a3
update cate and po section
NathanielF Oct 25, 2025
c180054
fixing typos
NathanielF Oct 25, 2025
e359210
add PO diagram
NathanielF Oct 25, 2025
8999d91
added empirical example
NathanielF Oct 26, 2025
e682822
fix typo
NathanielF Oct 26, 2025
a6ddda9
Fix calculation/plotting mistake to now focus on posterior expectatio…
drbenvincent Oct 27, 2025
2d06be5
Fix bug in `SyntheticControl.get_plot_data` (#540)
drbenvincent Oct 27, 2025
9a88b01
Don't change matplotlib style on import of causalpy + misc dev fixes …
drbenvincent Oct 27, 2025
762137b
add fish tank analogy
NathanielF Oct 27, 2025
4807bec
Merge branch 'main' into cate_example
NathanielF Oct 27, 2025
4531097
fix typo
NathanielF Oct 27, 2025
0628b91
tidying text
NathanielF Oct 28, 2025
65db0b4
further tidying
NathanielF Oct 28, 2025
1d69dee
[pre-commit.ci] pre-commit autoupdate (#541)
pre-commit-ci[bot] Oct 28, 2025
9b27f64
added conclusion
NathanielF Oct 28, 2025
d92b135
Refactored scikit-learn flavour of `DifferenceInDifferences` and allo…
roesta07 Oct 28, 2025
34e2fe3
More sign posting
NathanielF Oct 28, 2025
8787868
update references and write up
NathanielF Oct 29, 2025
d5016b7
add CTA to the end.
NathanielF Oct 29, 2025
5cc9366
add bayes factor plot
NathanielF Oct 30, 2025
79beb30
hide table inputs for param comparison
NathanielF Oct 30, 2025
d941b77
tightening the introduction
NathanielF Oct 30, 2025
828ba2e
feat(Makefile): Add self-documenting commands and re-organise (#543)
louismagowan Oct 30, 2025
cbaba03
tightening
NathanielF Oct 30, 2025
373f011
tidying
NathanielF Oct 31, 2025
22753d3
fix typo
NathanielF Oct 31, 2025
b406d53
small fix
NathanielF Oct 31, 2025
eb05301
tightening the conclusion with advice
NathanielF Nov 1, 2025
757d150
Add module docstring for experiments module (#546)
louismagowan Nov 3, 2025
81eb020
[pre-commit.ci] pre-commit autoupdate (#549)
pre-commit-ci[bot] Nov 3, 2025
f620e25
tighten writing and add spike and slab model for nhefs
NathanielF Nov 7, 2025
62c27ed
tightening intro
NathanielF Nov 8, 2025
1f4f695
adding vs module
NathanielF Nov 10, 2025
cc4accb
[pre-commit.ci] pre-commit autoupdate (#551)
pre-commit-ci[bot] Nov 10, 2025
1b967b9
break up joint model function
NathanielF Nov 10, 2025
4abb697
Add `AGENTS.md` file (#552)
drbenvincent Nov 12, 2025
bc2fbae
Add Type Hints to `simulate_data.py` (#544)
louismagowan Nov 12, 2025
42bfcda
Add MyPy Checks (#556)
juanitorduz Nov 12, 2025
7dea992
Add reporting layer (#554)
drbenvincent Nov 12, 2025
9de06b2
small fix for Ben
NathanielF Nov 12, 2025
921c9f7
Merge pull request #537 from NathanielF/cate_example
NathanielF Nov 12, 2025
860c1bc
Add ITS lift testing notebook for MMM calibration (#547)
drbenvincent Nov 14, 2025
114d037
Add example use of custom priors to the notebook docs (#533)
drbenvincent Nov 14, 2025
efde473
bump version to 0.6.0 (#561)
drbenvincent Nov 14, 2025
f14c72d
Merge main into cetagostini/adding_bsts_to_causalpy
cetagostini Nov 18, 2025
0d875f8
Fix: Initialize second_model properly in StateSpaceTimeSeries
cetagostini Nov 18, 2025
c7d4b67
dev notebook
cetagostini Nov 18, 2025
0b4764d
[pre-commit.ci] pre-commit autoupdate (#566)
pre-commit-ci[bot] Nov 19, 2025
2a01933
Merge branch 'main' into vs_module
NathanielF Nov 19, 2025
db1e81d
adding demo notebook
NathanielF Nov 20, 2025
db0522e
trying to fix doctests
NathanielF Nov 20, 2025
1670af4
adding fix
NathanielF Nov 20, 2025
83061e4
another fix
NathanielF Nov 20, 2025
05dc20d
update fix
NathanielF Nov 20, 2025
73e6a8d
adding tests
NathanielF Nov 20, 2025
8d6251f
update adding more tests
NathanielF Nov 21, 2025
4577106
add normal test vs_prior
NathanielF Nov 21, 2025
91b2874
Merge branch 'main' into cetagostini/adding_bsts_to_causalpy
drbenvincent Nov 21, 2025
59c58ea
get new models to issue warnings that they are experimental
drbenvincent Nov 21, 2025
abdbf6b
create markdown file of issues to resolve given this initial BSTS imp…
drbenvincent Nov 21, 2025
1fc193b
Merge pull request #473 from pymc-labs/cetagostini/adding_bsts_to_cau…
cetagostini Nov 21, 2025
fd1bfb7
improving test coverage
NathanielF Nov 21, 2025
7375aa5
updating notebook
NathanielF Nov 21, 2025
896ee57
update index
NathanielF Nov 21, 2025
1bb79d3
Merge branch 'main' into vs_module
NathanielF Nov 21, 2025
068c922
update spelling
NathanielF Nov 21, 2025
13b320e
add binary treatment case to IV model
NathanielF Nov 22, 2025
0bc9b8b
Update pre-commit hooks and fix CSV data value (#573)
drbenvincent Nov 24, 2025
c1cd88f
Add code quality and linting guidelines to AGENTS.md (#572)
drbenvincent Nov 24, 2025
5309a1f
[pre-commit.ci] pre-commit autoupdate (#576)
pre-commit-ci[bot] Nov 24, 2025
0961b30
Refactor PyMC time series models to use xarray API
cetagostini Nov 26, 2025
6210116
adding more write up
NathanielF Nov 26, 2025
bf5b404
update heading
NathanielF Nov 26, 2025
b16ef30
hide cells
NathanielF Nov 26, 2025
e2ae2e8
Three period ITS (#575)
JeanVanDyk Nov 29, 2025
5ee6651
Merge branch 'main' into cetagostini/bsts_tech_debt_v0
drbenvincent Nov 29, 2025
d06b0c6
Refactor time series model API to use xarray coordinates
drbenvincent Nov 29, 2025
387f748
get tests passing
drbenvincent Nov 29, 2025
b0b39ac
minor tweaks to dev notebook
drbenvincent Nov 29, 2025
d5700e8
increase code coverage
drbenvincent Nov 29, 2025
a15e17f
delete refactoring concerns doc
drbenvincent Nov 29, 2025
20cc071
Merge pull request #577 from pymc-labs/cetagostini/bsts_tech_debt_v0
cetagostini Nov 29, 2025
2b29e48
[pre-commit.ci] pre-commit autoupdate (#580)
pre-commit-ci[bot] Dec 1, 2025
a388bc7
Improve UML workflow branch and PR handling (#581)
drbenvincent Dec 5, 2025
f90ddde
Update `pyproject.toml`, including stricter linting rules (#571)
drbenvincent Dec 5, 2025
160eca3
Update UML Diagrams (#585)
github-actions[bot] Dec 8, 2025
8e672f2
[pre-commit.ci] pre-commit autoupdate (#586)
pre-commit-ci[bot] Dec 8, 2025
b88271e
better story telling
NathanielF Dec 9, 2025
c452650
tidying
NathanielF Dec 9, 2025
a5dd60f
hide cell inputs
NathanielF Dec 9, 2025
2578cce
Merge branch 'main' into vs_module
NathanielF Dec 9, 2025
a7c1090
fixing linting
NathanielF Dec 9, 2025
78ed0ce
fix linting error
NathanielF Dec 9, 2025
9e6ede0
update typing
NathanielF Dec 9, 2025
dbc8614
spell check
NathanielF Dec 9, 2025
d7af946
Add CausalPy skills and command documentation
cetagostini Dec 11, 2025
f6a9d0b
Update causalpy_extras.md
cetagostini Dec 11, 2025
516bc90
Merge pull request #589 from pymc-labs/cetagostini/marimo_demo
cetagostini Dec 15, 2025
6516f49
Improve load_data function documentation with complete dataset list (…
Copilot Dec 18, 2025
dd7dfc4
[pre-commit.ci] pre-commit autoupdate (#590)
pre-commit-ci[bot] Dec 18, 2025
2d6bba7
Fix overlapping x-axis date labels in time series plots (#597)
Copilot Dec 20, 2025
12936a4
update for juan's comments.
NathanielF Dec 22, 2025
97090b8
update tests to include outcome parameter in vs_hyperparams
NathanielF Dec 22, 2025
6e7accf
Merge branch 'main' into vs_module
NathanielF Dec 22, 2025
4b315fd
add type hints
NathanielF Dec 23, 2025
ca37024
bug fix
NathanielF Dec 23, 2025
18da6c4
fixing the warning message
NathanielF Dec 23, 2025
a466161
update iv_vs_priors notebook
NathanielF Dec 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .claude/skills/designing-experiments/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: designing-experiments
description: Selects the appropriate quasi-experimental method (DiD, ITS, SC) based on data structure and research questions. Use when the user is unsure which method to apply.
---

# Designing Experiments

Helps select the appropriate causal inference method.

## Decision Framework

1. **Control Group?**
* **Yes**: Go to Step 2.
* **No**: Consider **Interrupted Time Series (ITS)**.

2. **Unit Structure?**
* **Single Treated Unit**:
* With multiple controls: **Synthetic Control (SC)**.
* No controls: **ITS**.
* **Multiple Treated Units**:
* With control group: **Difference-in-Differences (DiD)**.

3. **Time Structure?**
* **Panel Data** (Multiple units over time): Required for DiD and SC.
* **Time Series** (Single unit over time): Required for ITS.

## Method Quick Reference

* **Difference-in-Differences (DiD)**: Compares trend changes between treated and control groups. Assumes **Parallel Trends**.
* **Interrupted Time Series (ITS)**: Analyzes trend/level change for a single unit after intervention. Assumes **Trend Continuity**.
* **Synthetic Control (SC)**: Constructs a synthetic counterfactual from weighted control units. Assumes **Convex Hull** (treated unit within range of controls).
30 changes: 30 additions & 0 deletions .claude/skills/loading-datasets/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: loading-datasets
description: Loads internal CausalPy example datasets. Use when the user needs example data or asks about available demos.
---

# Loading Datasets

Loads example datasets provided with CausalPy.

## Usage

```python
import causalpy as cp
df = cp.load_data("dataset_name")
```

## Available Datasets

| Key | Description |
| :--- | :--- |
| `did` | Generic Difference-in-Differences |
| `its` | Generic Interrupted Time Series |
| `sc` | Generic Synthetic Control |
| `banks` | DiD (Banks) |
| `brexit` | Synthetic Control (Brexit) |
| `covid` | ITS (Covid) |
| `drinking` | Regression Discontinuity (Drinking Age) |
| `rd` | Generic Regression Discontinuity |
| `geolift1` | GeoLift (Single cell) |
| `geolift_multi_cell` | GeoLift (Multi cell) |
28 changes: 28 additions & 0 deletions .claude/skills/performing-causal-analysis/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: performing-causal-analysis
description: Fits causal models, estimates impacts, and plots results using CausalPy. Use when performing analysis with DiD, ITS, SC, or RD.
---

# Performing Causal Analysis

Executes causal analysis using CausalPy experiment classes.

## Workflow

1. **Load Data**: Ensure data is in a Pandas DataFrame.
2. **Initialize Experiment**: Use the appropriate class (see References).
3. **Fit & Model**: Models are fitted automatically upon initialization if arguments are provided.
4. **Analyze Results**: Use `summary()`, `print_coefficients()`, and `plot()`.

## Core Methods

* `experiment.summary()`: Prints model summary and main results.
* `experiment.plot()`: Visualizes observed vs. counterfactual.
* `experiment.print_coefficients()`: Shows model coefficients.

## References

Detailed usage for specific methods:
* [Difference-in-Differences](reference/diff_in_diff.md)
* [Interrupted Time Series](reference/interrupted_time_series.md)
* [Synthetic Control](reference/synthetic_control.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Causal Difference-in-Differences (DiD)

Difference-in-Differences (DiD) estimates the causal effect of a treatment by comparing the changes in outcomes over time between a treatment group and a control group.

## Class: `DifferenceInDifferences`

```python
causalpy.experiments.DifferenceInDifferences(
data,
formula,
time_variable_name,
group_variable_name,
post_treatment_variable_name="post_treatment",
model=None,
**kwargs
)
```

### Parameters
* **`data`** (`pd.DataFrame`): Input dataframe containing panel data.
* **`formula`** (`str`): Statistical formula (e.g., `"y ~ 1 + group * post_treatment"`).
* **`time_variable_name`** (`str`): Column name for the time variable.
* **`group_variable_name`** (`str`): Column name for the group indicator (0=Control, 1=Treated). **Must be dummy coded**.
* **`post_treatment_variable_name`** (`str`): Column name indicating the post-treatment period (0=Pre, 1=Post). Default is `"post_treatment"`.
* **`model`**: A PyMC model (e.g., `cp.pymc_models.LinearRegression`) or a Scikit-Learn Regressor.

### How it Works
1. **Fit**: The model fits all available data (pre/post, treatment/control).
2. **Counterfactual**: Predicted by setting the interaction term between `group` and `post_treatment` to 0.
3. **Impact**: The causal impact is the difference between observed and counterfactual.

### Example

```python
import causalpy as cp
import causalpy.pymc_models as cp_pymc

df = cp.load_data("did")

result = cp.DifferenceInDifferences(
df,
formula="y ~ 1 + group*post_treatment",
time_variable_name="t",
group_variable_name="group",
model=cp_pymc.LinearRegression(sample_kwargs={"target_accept": 0.9})
)

result.summary()
result.plot()
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Causal Interrupted Time Series (ITS)

Interrupted Time Series (ITS) analyzes the effect of an intervention on a single time series by comparing the trend before and after the intervention.

## Class: `InterruptedTimeSeries`

```python
causalpy.experiments.InterruptedTimeSeries(
data,
treatment_time,
formula,
model=None,
**kwargs
)
```

### Parameters
* **`data`** (`pd.DataFrame`): Input dataframe. Index should ideally be a `pd.DatetimeIndex`.
* **`treatment_time`** (`Union[int, float, pd.Timestamp]`): The point in time when the intervention occurred.
* **`formula`** (`str`): Statistical formula (e.g., `"y ~ 1 + t + C(month)"`).
* **`model`**: A PyMC model (e.g., `cp.pymc_models.LinearRegression`) or a Scikit-Learn Regressor.

### How it Works
1. **Split**: Data is split into pre- and post-intervention.
2. **Fit**: Model is trained **only on pre-intervention data**.
3. **Predict**: Fitted model predicts the outcome for the post-intervention period.
4. **Impact**: Difference between observed post-intervention data and counterfactual predictions.

### Example

```python
import causalpy as cp
import causalpy.pymc_models as cp_pymc
import pandas as pd

df = cp.load_data("its")
df["date"] = pd.to_datetime(df["date"])
df.set_index("date", inplace=True)

treatment_time = pd.to_datetime("2017-01-01")

result = cp.InterruptedTimeSeries(
df,
treatment_time,
formula="y ~ 1 + t + C(month)",
model=cp_pymc.LinearRegression()
)

result.summary()
result.plot()
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Causal Synthetic Control (SCG)

Synthetic Control constructs a "synthetic" counterfactual unit using a weighted combination of untreated control units.

## Class: `SyntheticControl`

```python
causalpy.experiments.SyntheticControl(
data,
treatment_time,
control_units,
treated_units,
model=None,
**kwargs
)
```

### Parameters
* **`data`** (`pd.DataFrame`): Input dataframe containing panel data.
* **`treatment_time`** (`Union[int, float, pd.Timestamp]`): The time of intervention.
* **`control_units`** (`List[str]`): List of column names representing the control units.
* **`treated_units`** (`List[str]`): List of column names representing the treated unit(s).
* **`model`**: A PyMC model (typically `cp.pymc_models.WeightedSumFitter`) or a Scikit-Learn Regressor.

### How it Works
1. **Fit**: Model learns weights for `control_units` to approximate `treated_units` using **only pre-intervention data**.
2. **Predict**: Weights are applied to `control_units` in post-intervention period.
3. **Impact**: Difference between observed treated unit and synthetic counterfactual.

### Example

```python
import causalpy as cp
import causalpy.pymc_models as cp_pymc

df = cp.load_data("sc")
treatment_time = 70

result = cp.SyntheticControl(
df,
treatment_time,
control_units=["a", "b", "c", "d", "e"],
treated_units=["actual"],
model=cp_pymc.WeightedSumFitter()
)

result.summary()
result.plot()
```
25 changes: 25 additions & 0 deletions .claude/skills/running-placebo-analysis/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: running-placebo-analysis
description: Performs placebo-in-time sensitivity analysis to validate causal claims. Use when checking model robustness, verifying lack of pre-intervention effects, or ensuring observed effects are not spurious.
---

# Running Placebo Analysis

Executes placebo-in-time sensitivity analysis to validate causal experiments.

## Workflow

1. **Define Experiment Factory**: Create a function that returns a fitted CausalPy experiment (e.g., ITS, DiD, SC) given a dataset and time boundaries.
2. **Configure Analysis**: Initialize `PlaceboAnalysis` with the factory, dataset, intervention dates, and number of folds (cuts).
3. **Run Analysis**: Execute `.run()` to fit models on pre-intervention data folds.
4. **Evaluate Results**: Compare placebo effects (which should be null) to the actual intervention effect. Use histograms and hierarchical models to quantify the "status quo" distribution.

## Key Concepts

* **Placebo-in-time**: Simulating an intervention at a time when none occurred to check if the model falsely detects an effect.
* **Fold**: A slice of pre-intervention data used to test a placebo period.
* **Factory Pattern**: Decouples the placebo logic from the specific CausalPy experiment type.

## References

* [Placebo-in-time Implementation](reference/placebo_in_time.md): Full code for the `PlaceboAnalysis` class, usage examples, and hierarchical status-quo modeling.
Loading