Skip to main content

Local polynomial methods for boundary discontinuity designs

Project description

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.

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"]

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rd2d-0.2.0.post1.tar.gz (27.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rd2d-0.2.0.post1-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

Details for the file rd2d-0.2.0.post1.tar.gz.

File metadata

  • Download URL: rd2d-0.2.0.post1.tar.gz
  • Upload date:
  • Size: 27.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rd2d-0.2.0.post1.tar.gz
Algorithm Hash digest
SHA256 5bec8400efe7b08912645872db62b95870fae83bcf9acdb4f793f938deccf554
MD5 fc1899c52023b9476565f43ed8b7eda9
BLAKE2b-256 5c30e3e68214f2f8dfbcbd9f94adbaf3177dcd59b3a0ce5b63e417da2c0c96ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for rd2d-0.2.0.post1.tar.gz:

Publisher: python-publish.yml on rdpackages/rd2d

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rd2d-0.2.0.post1-py3-none-any.whl.

File metadata

  • Download URL: rd2d-0.2.0.post1-py3-none-any.whl
  • Upload date:
  • Size: 27.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rd2d-0.2.0.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 4089e78d122c978cf32c567b16d70daa240cdc8481fb505cee828cdb26d44ac7
MD5 766a9c4286cc007186564eefe2e02e09
BLAKE2b-256 781b9b54ff7d1d63dce4f9c2096cf1938d42ad5ebc2d262a009e73acb16f574b

See more details on using hashes here.

Provenance

The following attestation bundles were made for rd2d-0.2.0.post1-py3-none-any.whl:

Publisher: python-publish.yml on rdpackages/rd2d

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page