Skip to main content

pathmc

pathmc logo

CI Docs 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.

Overview talk

An overview of pathmc: Bayesian structural causal modeling in PyMC

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.6.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.6.0
File Size Uploaded Provenance Actions
pathmc-0.6.0.tar.gz 21.3 MB With provenance Details for pathmc-0.6.0.tar.gz

Built distribution (wheel)

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

Total release size: 21.6 MB

Release files / pathmc-0.6.0.tar.gz

Download URL pathmc-0.6.0.tar.gz
Size 21.3 MB
Tags Source
SHA-256 checksum
How to use checksums
d108a0d024e5308baa2bafc0b4d7ed9483a1136cf9ded14cb68d6c2c31874940
BLAKE2b-256 checksum
How to use checksums
029c7be7985276aae1c75750fc80223b5fbecdc62dcf6f10827d501809ac57ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 11, 2026.

Transparency log

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

Download URL pathmc-0.6.0-py3-none-any.whl
Size 346.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
783219888526ae89149440bdc1e679c9ac03589a4a6b4c7fae195eedb9e50ee4
BLAKE2b-256 checksum
How to use checksums
9d250c29142f55ef6bd108814f3d7ec8e81abb890db3342396410100190b098e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 11, 2026.

Transparency log

Security for pathmc 0.6.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pathmc-0.6.0.tar.gz

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 Nov 11, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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