aggregate_idata_dims#

pymc_marketing.data.idata.utils.aggregate_idata_dims(idata, dim, values, new_label, method='sum')[source]#

Aggregate multiple dimension values into one.

Parameters:
idataaz.InferenceData

InferenceData object to aggregate

dimstr

Dimension to aggregate (e.g., “channel”, “country”)

valueslist of str

Values to aggregate

new_labelstr

Label for aggregated value

method{“sum”, “mean”}, default “sum”

Aggregation method

Returns:
az.InferenceData

New InferenceData with aggregated dimension values

Raises:
ValueError

If the dimension doesn’t exist in any group, or if new_label conflicts with existing coordinate values that aren’t being aggregated

Examples

>>> # Combine social channels into one
>>> combined = aggregate_idata_dims(
...     idata,
...     dim="channel",
...     values=["Facebook", "Instagram", "TikTok"],
...     new_label="Social",
...     method="sum",
... )