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_model
Model The PyMC model to extract the response distribution from.
- idata
xr.DataTree The inference data containing posterior samples.
- response_variable
str,Variable, or sequence ofeither 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
Deterministicunder 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_contributionalongside a mediated effect that reads the same spend data.- frozen_deterministics
listofstr, 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.
- pymc_model
- Returns:
pt.TensorVariableorlistofpt.TensorVariableThe response distribution graph. A list – matching
response_variableelement-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.