Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions .cursor/commands/causalpy_demos.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Causal Demos

This command points to the `loading-datasets` Skill in `.github/skills/loading-datasets/`.
Use that Skill for dataset discovery and example usage.
Use `causalpy.load_data(name)` to load example datasets. See the `load_data()` docstring for available dataset names.
2 changes: 1 addition & 1 deletion .cursor/commands/causalpy_estimators.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Causal Estimators

This command points to the `performing-causal-analysis` Skill in
`.github/skills/performing-causal-analysis/` for estimation, summaries, and plots.
`causalpy/skills/performing-causal-analysis/` for estimation, summaries, and plots.
2 changes: 1 addition & 1 deletion .cursor/commands/causalpy_extras.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Causal Extras

This command points to the `running-placebo-analysis` Skill in
`.github/skills/running-placebo-analysis/` for the placebo-in-time workflow.
`causalpy/skills/running-placebo-analysis/` for the placebo-in-time workflow.
2 changes: 1 addition & 1 deletion .cursor/commands/causalpy_methods.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Causal Methods

This command points to Skills in `.github/skills/`:
This command points to Skills in `causalpy/skills/`:

- `designing-experiments` for method selection
- `performing-causal-analysis` for method usage and references
2 changes: 1 addition & 1 deletion .cursor/commands/causalpy_research.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Causal Research

This command points to the `designing-experiments` Skill in
`.github/skills/designing-experiments/` for method selection guidance.
`causalpy/skills/designing-experiments/` for method selection guidance.
30 changes: 0 additions & 30 deletions .github/skills/loading-datasets/SKILL.md

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ dist/
docs/build/
docs/jupyter_execute/
docs/source/api/generated/

.cursor/plans
.marimo/

Expand Down
10 changes: 6 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ creation, bug reports, and issue evaluation workflows.

## Skills Location

Canonical skills live in `.github/skills/`. The `.claude/skills` and
`.cursor/skills` paths are symlinks to that directory. On Windows, symlink
support may require Developer Mode or elevated permissions; if symlinks are not
available, mirror `.github/skills/` into those locations and keep them in sync.
Skills are split into two categories with separate homes:

- **Developer skills** live in `.github/skills/` and are auto-discovered by agents working on the repo via the `.cursor/skills`, `.claude/skills`, and `.agents/skills` symlinks. These cover environment setup, PR workflows, issue triage, and other maintainer tasks.
- **User skills** live in `causalpy/skills/` inside the source tree. They teach AI agents how to use CausalPy for causal inference tasks. They are **not** symlinked into the auto-discovery paths — a developer agent should not see experiment-design skills mixed in with PR review skills. User skills are distributed via [Decision AI Hub](https://hub.decision.ai).

On Windows, symlink support for developer skills may require Developer Mode or elevated permissions; if symlinks are not available, mirror `.github/skills/` into `.cursor/skills/`, `.claude/skills/`, and `.agents/skills/` and keep them in sync.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ Alternatively, if you want the very latest version of the package you can instal
pip install git+https://github.com/pymc-labs/CausalPy.git
```

## AI Agent Skills

CausalPy includes agent skills that teach AI coding assistants how to use the library for causal inference. Skills are available via [Decision AI Hub](https://hub.decision.ai) and live in `causalpy/skills/` in the source tree.

## Quickstart

```python
Expand Down
13 changes: 13 additions & 0 deletions causalpy/skills/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# User-Facing Agent Skills

Markdown skills in this directory teach AI coding agents how to use CausalPy for causal inference tasks. They are distributed to end users via [Decision AI Hub](https://hub.decision.ai).

Developer-focused skills (environment setup, PR workflows, testing conventions, etc.) live in `.github/skills/` and are auto-discovered in-repo via platform symlinks. They are **not** included here.

## Layout

| Path | Purpose |
|------|---------|
| `designing-experiments/` | Choosing the right quasi-experimental method |
| `performing-causal-analysis/` | Fitting models, estimating impacts, plotting results |
| `running-placebo-analysis/` | Placebo-in-time sensitivity checks |
21 changes: 21 additions & 0 deletions causalpy/skills/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2026 - 2026 The PyMC Labs Developers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""CausalPy agent skills for AI-assisted causal inference.

User-facing skills that teach AI agents how to use CausalPy.
Distributed via Decision AI Hub (https://hub.decision.ai).

Developer skills live in ``.github/skills/`` and are auto-discovered
in-repo via platform symlinks; they are **not** included here.
"""
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ 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)
* [Regression Discontinuity](reference/regression_discontinuity.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Causal Regression Discontinuity (RD)

Regression Discontinuity exploits a cutoff or threshold in an assignment variable to identify causal effects. Units just above and below the threshold are compared to estimate the treatment effect at the discontinuity.

## Class: `RegressionDiscontinuity`

```python
causalpy.experiments.RegressionDiscontinuity(
data,
formula,
treatment_threshold,
model=None,
running_variable_name="x",
epsilon=0.001,
bandwidth=np.inf,
donut_hole=0.0,
**kwargs
)
```

### Parameters

* **`data`** (`pd.DataFrame`): Input dataframe.
* **`formula`** (`str`): Statistical formula (e.g., `"y ~ 1 + x + treated + x:treated"`).
* **`treatment_threshold`** (`float`): The cutoff value of the running variable where treatment is assigned.
* **`model`**: A PyMC model (e.g., `cp.pymc_models.LinearRegression`) or a Scikit-Learn Regressor.
* **`running_variable_name`** (`str`): Column name of the running variable. Default is `"x"`.
* **`epsilon`** (`float`): Small offset above/below the threshold for evaluating the causal impact. Default is `0.001`.
* **`bandwidth`** (`float`): Data outside this distance from the threshold is excluded from fitting. Default is `np.inf` (use all data).
* **`donut_hole`** (`float`): Observations within this distance from the threshold are excluded from fitting (robustness check). Default is `0.0`.

### How it Works

1. **Fit**: Model is trained on data within the bandwidth, optionally excluding the donut hole.
2. **Predict**: Counterfactual predicted at the threshold by evaluating the model just above and just below.
3. **Impact**: The causal effect is the discontinuous jump in the outcome at the threshold.

### Example

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

df = cp.load_data("drinking")
df = df.rename(columns={"agecell": "age"}).assign(treated=lambda d: d.age > 21)

result = cp.RegressionDiscontinuity(
df,
formula="all ~ 1 + age + treated + age:treated",
running_variable_name="age",
model=cp_pymc.LinearRegression(),
treatment_threshold=21,
)

result.summary()
result.plot()
```