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 pathmc

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.

Download files

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

Source Distribution

pathmc-0.3.0.tar.gz (18.9 MB view details)

Uploaded Source

Built Distribution

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

pathmc-0.3.0-py3-none-any.whl (185.6 kB view details)

Uploaded Python 3

File details

Details for the file pathmc-0.3.0.tar.gz.

File metadata

  • Download URL: pathmc-0.3.0.tar.gz
  • Upload date:
  • Size: 18.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pathmc-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f0594e42dfd229a703ba7077d211a3e01fb12a0fde996ab3866b8b4bda014cec
MD5 11b7088e524847f59ead42533e6cf286
BLAKE2b-256 74d52379748d1ac1e1c9e236e0b3d1b485712d51ced4caf8d10c007f7a24ad09

See more details on using hashes here.

Provenance

The following attestation bundles were made for pathmc-0.3.0.tar.gz:

Publisher: release.yml on pymc-labs/pathmc

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

File details

Details for the file pathmc-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pathmc-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 185.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pathmc-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e15c002b1e56a21e39e890a6bdc9aae9a3f7b857ebc4a26ba016719dd5a4f60
MD5 511d0a4d0c5ba34a65164f2514d53f8c
BLAKE2b-256 9eeaa9c6fbf67c38c41fdaf873806ebedd23d69a9ed4364f4674508ac87e78a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pathmc-0.3.0-py3-none-any.whl:

Publisher: release.yml on pymc-labs/pathmc

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

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 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