BuildModelFromDAG.build#

BuildModelFromDAG.build()[source]#

Construct and return the PyMC model implied by the DAG and data.

The method creates a pm.Data container for every node to align the observed data with the declared dims. For each edge A -> B, a slope prior is instantiated from model_config['slope'] and used in the mean of node B’s likelihood, which is instantiated from model_config['likelihood'].

Returns:
pymc.Model

A fully specified model with slopes and likelihoods for all nodes.

Examples

Build a model and sample from it:

builder = BuildModelFromDAG(
    dag="A->B", df=df, target="B", dims=("date",), coords={"date": dates}
)
model = builder.build()
with model:
    idata = pm.sample(100, tune=100, chains=2, cores=2)

Multi-dimensional dims (e.g. date and country):

dims = ("date", "country")
coords = {"date": dates, "country": ["Venezuela", "Colombia"]}
builder = BuildModelFromDAG(
    dag="A->B, B->Y", df=df, target="Y", dims=dims, coords=coords
)
model = builder.build()