aggregate_idata_time#
- pymc_marketing.data.idata.utils.aggregate_idata_time(idata, period, method='sum')[source]#
Aggregate DataTree over time periods.
- Parameters:
idata (
DataTree) – DataTree to aggregateperiod (
Literal['original','weekly','monthly','quarterly','yearly','all_time']) – Time period to aggregate to. Use “original” for no aggregation (returns unchanged), “all_time” to aggregate over the entire time dimension (removes the date dimension).method (
Literal['sum','mean']) – Aggregation method
- Return type:
xr.DataTree- Returns:
New DataTree with aggregated groups (or unchanged if period=”original”). Its root
attrsrecord the aggregation astime_aggregation=periodso that consumers of per-date quantities can tell the data apart from the original dates.
Notes
Each variable is reduced as it is, so a variable without a
datedim passes through unchanged. A time-invariant MMM intercept is such a variable although the model adds it in every period: summing MMM contributions with this function counts it once for the whole window. Useaggregate_time(), which broadcasts it overdatefirst.Examples
>>> original = aggregate_idata_time(idata, "original") # No aggregation >>> monthly = aggregate_idata_time(idata, "monthly", method="sum") >>> total = aggregate_idata_time(idata, "all_time", method="sum")