sum_contributions_over_time#

pymc_marketing.data.idata.utils.sum_contributions_over_time(contributions, period)[source]#

Sum per-date contributions over the dates of each period.

Every variable of contributions is a component the model adds to the linear predictor on every date. A component without a date dim, such as a time-invariant intercept, is repeated on every date of contributions first (see broadcast_over_date()), so that it is counted once per observed date within each period, exactly like the per-date components. The aggregation runs per variable, so each keeps its (chain, draw, date, ...) dim order.

Decompose first, then call this: under a nonlinear inverse link the decomposition of the summed linear predictor is not the sum of the per-date decompositions.

Parameters:
  • contributions (Dataset) – One data variable per component, on the original dates.

  • period (Literal['original', 'weekly', 'monthly', 'quarterly', 'yearly', 'all_time']) – Time period to sum over. "original" returns contributions unchanged, "all_time" removes the date dim; otherwise date holds the last calendar day of each period. A period shorter than the spacing of the dates (e.g. "weekly" on monthly data) leaves empty periods, which are NaN.

Return type:

xr.Dataset

Returns:

The contributions of each period.