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 pymc-labs.github.io/pathmc.

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 pymc-labs.github.io/pathmc. 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.0.tar.gz (10.1 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.0-py3-none-any.whl (92.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pathmc-0.1.0.tar.gz
  • Upload date:
  • Size: 10.1 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.0.tar.gz
Algorithm Hash digest
SHA256 e1058343145dc80de852f8ad42eff0f78d53cff3fe31e19605ad7de3de3aeb8a
MD5 5986108226eaff973c237907fa78811b
BLAKE2b-256 a89f2c012abe311cdd7e56370c86159a76901aadf7dd461e078fa7cbb8c64f3a

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pathmc-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 92.7 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61b661ba804f9398dcff1085d527d287da27691a91f094f7debf125090c689fa
MD5 ac614309a522e71ea2882dde6bcc4bb1
BLAKE2b-256 ccda1e95a4db0ac464da99b4dbf329b5652d74ad63ed8ce981f553d0ee025ad5

See more details on using hashes here.

Provenance

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

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