broadcast_over_date#

pymc_marketing.data.idata.utils.broadcast_over_date(variable, date)[source]#

Repeat a time-invariant variable on every date.

An MMM adds a time-invariant intercept to the linear predictor on every date but stores it without a date dim. Repeating it on the dates of the per-date variables lets it line up with them, so that summing over date counts it once per date like every other component.

Parameters:
variablexr.DataArray

Variable without a date dim, e.g. with dims (chain, draw, ...).

datexr.DataArray

The date coordinate to repeat variable on.

Returns:
xr.DataArray

variable with the date dim inserted after chain and draw (those present), before any other dim, the order the per-date variables of the same group use.

Examples

posterior = mmm.idata.posterior
intercept = broadcast_over_date(
    posterior["intercept_contribution"], posterior["date"]
)
intercept.dims  # ("chain", "draw", "date", ...)