Skip to main content

rd2d

rd2d provides local polynomial estimation, robust bias-corrected inference, and bandwidth helpers for boundary discontinuity designs with bivariate running variables. The package includes location-based and distance-based methods, sharp and fuzzy designs, pointwise confidence intervals, covariance-backed summary inference, uniform confidence bands, and aggregate boundary effect summaries. The default fitting method is the joint treatment-interacted regression; use fitmethod="separate" to reproduce the earlier two-sample fitting path.

from rd2d import rd2d, rdbw2d, rd2d_dist, rdbw2d_dist, summary

Main Functions

  • rd2d(): location-based estimation and inference.
  • rdbw2d(): location-based bandwidth selection.
  • rd2d_dist() and rd2d_distance(): distance-based estimation and inference.
  • rdbw2d_dist() and rdbw2d_distance(): distance-based bandwidth selection.
  • summary(): summary tables with optional uniform bands, WBATE, and LBATE.

In the source repository, the sibling scripts ../rd2d_illustration.py and ../rd2d_plot.py read ../rd2d_data.csv and run the same dataset-based illustration workflow as the R and Stata examples. They do not create an output/ folder or save fitted objects, tables, or plot files.

Installation

python -m pip install rd2d

For local development:

python -m pip install -e .

Optional plotting and testing dependencies can be installed with:

python -m pip install -e ".[plots,test]"

Basic Usage

import numpy as np
from rd2d import rd2d

rng = np.random.default_rng(123)
n = 800
x1 = rng.normal(size=n)
x2 = rng.normal(size=n)
assignment = (x1 >= 0).astype(float)
y = 3 + 2 * x1 + 1.5 * x2 + assignment + rng.normal(size=n)
x = np.column_stack([x1, x2])
b = np.array([[0.0, 0.0], [0.0, 1.0]])

fit = rd2d(y, x, assignment, b, h=0.9, params_cov="main")
fit.main
fit.summary(cbands="main", repp=999).tables["main"]

Pre-intervention covariates can be supplied for efficiency adjustment. The same covariate coefficient is used across treatment sides, matching the R package.

z = np.column_stack([x1 + rng.normal(size=n), x2 + rng.normal(size=n)])
fit_cov = rd2d(y, x, assignment, b, h=0.9, covs_eff=z, fitmethod="joint")

For distance-based designs, pass one signed-distance column per evaluation point. Nonnegative distances identify observations on the treated side.

from rd2d import rd2d_dist

distance = x1.reshape(-1, 1)
fit_dist = rd2d_dist(y, distance, h=0.5, b=np.array([[0.0, 0.0]]))
fit_dist.main

Development

From this directory:

python -m pytest

Publishing From GitHub

The workflow .github/workflows/python-publish.yml builds, checks, tests, and publishes the Python package to PyPI with trusted publishing. Configure:

  • PyPI project: rd2d.
  • Trusted publisher owner: rdpackages.
  • Trusted publisher repository: rd2d.
  • Trusted publisher workflow: python-publish.yml.
  • Trusted publisher environment: pypi.

In GitHub, create an environment named pypi. Add required reviewers there if you want each PyPI upload to require manual approval. Publish by creating a GitHub Release or by running the Publish Python package workflow manually.

Metadata

Release files for rd2d 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rd2d 1.0.0
File Size Uploaded
rd2d-1.0.0.tar.gz 34.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rd2d 1.0.0
File Interpreter ABI Platform
rd2d-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 67.5 kB

Release files / rd2d-1.0.0.tar.gz

Download URL rd2d-1.0.0.tar.gz
Size 34.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9d84f21a350a677202a8b2debf993f44d4c9f38ab9e4920cb7afde9d51d127c7
BLAKE2b-256 checksum
How to use checksums
7726c661eca01cb8316239ed82f7cc1b452760f090c1838d738d61e0e1c45ce0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 27, 2026.

Transparency log

Release files / rd2d-1.0.0-py3-none-any.whl

Download URL rd2d-1.0.0-py3-none-any.whl
Size 33.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cce13f62b5c8f3c2390e8e661bf0ababe1f2b0398ded26baf0c9e09d30f8631e
BLAKE2b-256 checksum
How to use checksums
d846a1e69a52bd9a242da2b071a5474cab5ee42a63acff56736e78f84f8c41c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 27, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page