Skip to main content

Bayesian path analysis and structural causal modeling in PyMC.

Project description

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 ≥ 5.22.

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

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.
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.
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 and estimation approaches, standardized effects, and panel data, alongside runnable examples from foundations through applied models.

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. The citation metadata will be updated before the final 0.1.0 release.

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.

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

pathmc-0.1.1.tar.gz (10.2 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.1.1-py3-none-any.whl (100.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pathmc-0.1.1.tar.gz
Algorithm Hash digest
SHA256 14f488b212766e02d46c65a7765bc3df51c876e9319810576cfa73ce8e08117e
MD5 c7252ad42040a8f7b6ef29ba4cc9f549
BLAKE2b-256 d9ca600ffbc475e6c3d2927007646a777eea1fcdf68400fe7ff410332a400d4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pathmc-0.1.1.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.1.1-py3-none-any.whl.

File metadata

  • Download URL: pathmc-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 100.0 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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4ba5dd30801c1919a00f60db11f816a5f919a50fb3d9a242ff13a5960c5b8217
MD5 744cca3f676f7230d8e4d819175a5dab
BLAKE2b-256 bab21fcc123705ad078975aa9ebfe8696461d22bca4e30de6e4f29f63b4f12d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pathmc-0.1.1-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.

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