Skip to main content

Plotting utilities for comparing event-study estimates across estimators.

Project description

dml-plotting

dml-plotting provides lightweight plotting utilities for comparing event-study estimates across estimators, including support for publication-style line plots with optional confidence bands.

Install

pip install dml-plotting

Quick Start

from dml_plotting import example_event_study_input, plot_event_study

plot_event_study(
    example_event_study_input(),
    output_path="event_study.png",
    title="ERA pooled ATT event-study estimates across estimators",
    y_limits=(0.05, 0.05),
)

To add confidence bands and a caption:

from dml_plotting import example_event_study_input, plot_event_study

plot_event_study(
    example_event_study_input(),
    output_path="event_study_with_ci.png",
    title="ERA pooled ATT event-study estimates across estimators",
    caption="Confidence bands show 95 percent intervals around each series.",
    show_confidence_bands=True,
    y_limits=(0.05, 0.05),
)

Control-Group Size Plotter

Use ControlGroupSizePoint for each observed run, then pass three cumulative covariate panels to plot_control_group_size_tradeoffs_grid(). The control group sample-size axis is log-scaled and defaults to running from 1,000 through 1 billion people.

from dml_plotting import (
    ControlGroupSizePanel,
    ControlGroupSizePoint,
    SQRT_ASYMPTOTIC,
    XLOGX,
    plot_control_group_size_tradeoffs_grid,
)

fit_specs = {
    "runtime_minutes": XLOGX,
    "outcome_mse": XLOGX,
    "pooled_att_estimate": SQRT_ASYMPTOTIC,
}

basic_points = [
    ControlGroupSizePoint(20, outcome_mse=0.99, runtime_minutes=3.2, pooled_att_estimate=-2900),
    ControlGroupSizePoint(40, outcome_mse=0.81, runtime_minutes=7.4, pooled_att_estimate=-1850),
    ControlGroupSizePoint(80, outcome_mse=0.65, runtime_minutes=17.5, pooled_att_estimate=-950),
]

panels = [
    ControlGroupSizePanel("Basic covariates", basic_points, feature_count=42, fit_specs=fit_specs),
    ControlGroupSizePanel("Basic + county indicators", basic_points, feature_count=96, fit_specs=fit_specs),
    ControlGroupSizePanel("Basic + county + tract characteristics", basic_points, feature_count=178, fit_specs=fit_specs),
]

plot_control_group_size_tradeoffs_grid(
    panels,
    output_path="control_group_size_grid.png",
    title="DoubleML runtime and performance: Low-complexity LightGBM models on ERA data",
    footnote="LightGBM parameters: num_leaves=31, learning_rate=0.05, n_estimators=250.",
    x_limits=(1_000, 100_000_000),
    show_fit_lines={"outcome_mse": False},
    y_axis_limits={
        "runtime_minutes": (0, 600),
        "outcome_mse": (0.4, 1.05),
        "pooled_att_estimate": (-3200, 100),
    },
)

colors and show_fit_lines accept any subset of runtime_minutes, outcome_mse, and pooled_att_estimate. By default, runtime uses OI navy, outcome-model MSE uses OI red, and pooled ATT uses OI blue.

For a quick smoke test with bundled example data:

python -m dml_plotting.examples

This writes example images to dist/control_group_size_plot_examples/.

The former aipw_analysis import path is still available as a compatibility alias in this package.

Public API

  • EventStudySeries: dataclass for one event-study series
  • plot_event_study(): save a multi-series event-study figure
  • ControlGroupSizePoint: dataclass for one runtime/performance run
  • ControlGroupSizePanel: dataclass for one covariate-specification panel
  • plot_control_group_size_tradeoffs_grid(): save the 2x3 control-group-size figure
  • example_event_study_input(): generate example plotting inputs

Development

source .venv/bin/activate
python -m pip install -e . --no-build-isolation
python -m build --no-isolation
python -m twine check dist/*

Publishing

This repo includes GitHub Actions trusted publishing in .github/workflows/publish.yml. Publishing is triggered by pushing a tag like:

git tag v0.1.5
git push origin v0.1.5

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

dml_plotting-0.1.6.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

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

dml_plotting-0.1.6-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file dml_plotting-0.1.6.tar.gz.

File metadata

  • Download URL: dml_plotting-0.1.6.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dml_plotting-0.1.6.tar.gz
Algorithm Hash digest
SHA256 7ffad8e6e0b0954dae903eaad14821fabbaf90285cb1038e079a06f4be2d5570
MD5 1e62c5bd4ef2953905c7e302efaa2c62
BLAKE2b-256 e6872db2d1289ad0f437deb646383aa4cbbf0a741a19eaf5da75e3f0640e26e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for dml_plotting-0.1.6.tar.gz:

Publisher: publish.yml on coreygb1/2604_aipw

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

File details

Details for the file dml_plotting-0.1.6-py3-none-any.whl.

File metadata

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

File hashes

Hashes for dml_plotting-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9eeed3137fb354a226bd5e3548aeffdebb6b8ac9bf5a69974cf303a75f8622ad
MD5 60a43d2df7007bc21e1cca8318b209ab
BLAKE2b-256 05b5199af53626c7ed54885aa2197be86011ced077bafab0a516f4ec03e49344

See more details on using hashes here.

Provenance

The following attestation bundles were made for dml_plotting-0.1.6-py3-none-any.whl:

Publisher: publish.yml on coreygb1/2604_aipw

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