extract_response_distribution#

pymc_marketing.pytensor_utils.extract_response_distribution(pymc_model, idata, response_variable, frozen_deterministics=None)[source]#

Extract the response distribution graph, conditioned on posterior parameters.

Overloads:
  • pymc_model (Model), idata (xr.DataTree), response_variable (str | Variable), frozen_deterministics (list[str] | None) → Variable

  • pymc_model (Model), idata (xr.DataTree), response_variable (Sequence[str | Variable]), frozen_deterministics (list[str] | None) → list[Variable]

Parameters:
pymc_modelModel

The PyMC model to extract the response distribution from.

idataxr.DataTree

The inference data containing posterior samples.

response_variablestr, Variable, or sequence of either

The response variable to extract, by name or as the graph node itself. A node is accepted because not every interesting quantity is a named variable of the model: an MMM’s linear predictor is only registered as a Deterministic under a log link, and is an anonymous intermediate otherwise. A sequence extracts several variables in a single pass, so any subgraph they share is conditioned, rewritten and vectorized once and stays shared in the result – which is what makes it cheap to evaluate, say, channel_contribution alongside a mediated effect that reads the same spend data.

frozen_deterministicslist of str, optional

Names of Deterministic variables to freeze at their posterior values instead of recomputing from the graph. Some models (e.g, those containing HSGP) need this to to obtain a valid conditional posterior graph.

Returns:
pt.TensorVariable or list of pt.TensorVariable

The response distribution graph. A list – matching response_variable element-wise – when a sequence was passed, a single variable otherwise.

Examples

extract_response_distribution(model, idata, "channel_contribution") returns a graph that computes "channel_contribution" as a function of both the newly introduced budgets and the posterior of model parameters.