Structural causal models with Bayesian estimation and interventional simulation via a concise DSL.
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.
pip install pathmcpathmc requires Python ≥ 3.12 and PyMC ≥ 5.22.
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 identificationThe 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.
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, 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.
Development setup, testing, and pull request guidance live in CONTRIBUTING.md.
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.
The contributor image is regenerated weekly by a GitHub Actions workflow (.github/workflows/contributors.yml) that opens a PR when the contributor list changes.