Skip to main content

pathmc

pathmc logo

CI Docs Status: beta License: Apache 2.0 Python Ruff pre-commit

Structural causal models with Bayesian estimation and interventional simulation via a concise DSL.

What is pathmc?

pathmc is a Python package for Bayesian path analysis and structural causal modeling. You write your causal assumptions as a small set of structural equations in a lavaan-inspired formula language, and pathmc compiles them into a generative PyMC model in which every variable is wired through its structural parents in the DAG.

The result is a single model object that keeps the directed acyclic graph (DAG) at the center of the workflow. From that one object you can estimate effects with full posterior uncertainty, inspect the implied graph, check whether a causal effect is identifiable from your assumptions, falsify the graph against the data, run do()-operator interventions, and stress-test conclusions for unmeasured confounding, all without rewriting the model for each task.

pathmc is a good fit when you want the interpretability of path / structural equation modeling, the rigor of explicit causal identification, and the uncertainty quantification of full Bayesian inference, all in one place.

Installation

pip install pathmc

pathmc requires Python ≥ 3.12 and PyMC ≥ 6.0.

Quickstart

Pass a pandas DataFrame with columns matching the variables in your structural equations:

import pandas as pd
import pathmc
from pathmc.paths import data_dir

df = pd.read_csv(data_dir / "mediation.csv")
#           X         M         Y
# 0 -1.315113 -1.534242 -0.926176
# 1  0.490564  0.187741  1.742414
# 2 -1.077202 -0.691821 -0.233461
# 3  0.077516  0.156411  1.285188
# 4  1.600833  0.232611  1.379142
# ...

spec = """
M ~ a*X
Y ~ b*M + c*X
indirect := a*b
"""

m = pathmc.model(spec, data=df)
m.fit(draws=1000, chains=2)

m.effects_summary()             # labeled coefficients + defined parameters
m.ate("Y", "X", values=(0, 1))  # average treatment effect via the do-operator
m.adjustment_sets("X", "Y")     # what to condition on for identification
m.comparisons("Y", "X")         # same estimand, or ratio/lift via comparison=

adj = m.adjustment_model("X -> Y")  # DAG-derived backdoor outcome regression
adj.fit(draws=1000, chains=2)
adj.ate(values=(0, 1))

The DSL mirrors lavaan: ~ defines a regression of an outcome on its parents, label*var attaches a name to a coefficient, and := defines derived quantities (such as an indirect/mediated effect) that are tracked with full posterior uncertainty.

Capabilities

For concepts, tutorials, and the full API reference, see the documentation at pathmc.pymc-labs.com.

Capability What it lets you do
Model specification Write structural equations in a compact lavaan-style formula language, with labeled coefficients and derived quantities such as mediated effects.
Bayesian estimation Fit with full-posterior MCMC and get coefficient and effect summaries, including standardized effects, all with quantified uncertainty.
Causal identification Check whether an effect is identifiable from your DAG, find valid adjustment sets, and get warned about collider bias.
Regression adjustment Derive a backdoor adjustment set from the DAG, fit a single outcome equation via adjustment_model(), and estimate ATE/ATT/ATU/CATE by outcome-regression standardization.
Graph falsification Test the conditional independences your DAG implies against the data, including a whole-graph falsification test.
Interventional queries Ask "what if?" with the do-operator: average and conditional treatment effects and intervention probabilities.
Predictions, comparisons, and slopes Shared interpret layer on structural and adjustment models: response-scale grids, diff/ratio/lift contrasts, and local derivatives, with causal vs associational metadata.
Sensitivity analysis Stress-test causal conclusions against unmeasured confounding.
Transforms & response curves Apply nonlinear transforms such as adstock and saturation for marketing-mix and other media-response models.
Panel & longitudinal data Build lagged predictors and run interventions on time-series and panel structures.
Inspection & visualization Render the implied DAG, view the model equations, and inspect design matrices.
Simulation Generate synthetic data from a specification for testing, teaching, and method validation.

Documentation

Documentation, concepts, and worked examples are available at pathmc.pymc-labs.com. The user guide covers the Bayesian workflow, model specification, transforms, identification, estimation approaches (structural vs regression adjustment), predictions/comparisons/slopes, standardized effects, and panel data, alongside runnable examples from foundations through applied models and the interpret gallery.

Contributing

Development setup, testing, and pull request guidance live in CONTRIBUTING.md.

Citation

If you use pathmc in academic work, please cite the project using the metadata in the repository's CITATION.cff.

Thanks to our contributors

pathmc contributors

The contributor image is regenerated weekly by a GitHub Actions workflow (.github/workflows/contributors.yml) that opens a PR when the contributor list changes.

Metadata

Release files for pathmc 0.4.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 pathmc 0.4.0
File Size Uploaded
pathmc-0.4.0.tar.gz 19.5 MB Details

Built distribution (wheel)

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

Total release size: 19.7 MB

Release files / pathmc-0.4.0.tar.gz

Download URL pathmc-0.4.0.tar.gz
Size 19.5 MB
Tags Source
SHA-256 checksum
How to use checksums
17f3ddaef7e928cd046d2dc356464b936bfb995936b00b6984bdb7e667425c04
BLAKE2b-256 checksum
How to use checksums
4d1f1d2649eb468dfec06bd9a06921e7141b3a8ec7ade7b7c10b6c6ee11c2226
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 27, 2026.

Transparency log

Release files / pathmc-0.4.0-py3-none-any.whl

Download URL pathmc-0.4.0-py3-none-any.whl
Size 227.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1d14144aa24fbb31a7d727bc9c096f472c63625751e84dd80cee8a7a64c5e2fe
BLAKE2b-256 checksum
How to use checksums
83e1a82501dae7e5223c601f79d55ba1c979f118eb162196eea1fb444404a353
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 27, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

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