MMMIDataWrapper#

class pymc_marketing.data.idata.mmm_wrapper.MMMIDataWrapper(idata, schema=None, validate_on_init=True)[source]#

Codified wrapper around InferenceData for MMM models.

Provides validated access to data and common transformations.

Parameters:
idataaz.InferenceData

InferenceData object from fitted MMM model

schemaMMMIdataSchema, optional

Schema to validate against. If None, validation skipped.

validate_on_initbool, default True

Whether to validate idata structure on initialization

Examples

>>> wrapper = MMMIDataWrapper(mmm.idata)
>>>
>>> # Access observed data
>>> observed = wrapper.get_target()
>>>
>>> # Get contributions in original scale
>>> contributions = wrapper.get_contributions(original_scale=True)

Methods

MMMIDataWrapper.__init__(idata[, schema, ...])

MMMIDataWrapper.aggregate_dims(dim, values, ...)

Aggregate multiple dimension values into one.

MMMIDataWrapper.aggregate_time(period[, method])

Aggregate data over time periods.

MMMIDataWrapper.compute_posterior_summary(var)

Compute summary statistics for a variable.

MMMIDataWrapper.filter_dates([start_date, ...])

Filter to date range, returning new wrapper.

MMMIDataWrapper.filter_dims(**dim_filters)

Filter by custom dimensions, returning new wrapper.

MMMIDataWrapper.get_channel_contributions([...])

Get channel contribution posterior samples.

MMMIDataWrapper.get_channel_scale()

Get channel scaling factor used during model fitting.

MMMIDataWrapper.get_channel_spend()

Get channel spend data with consistent access pattern.

MMMIDataWrapper.get_contributions([...])

Get all contribution variables in a single dataset.

MMMIDataWrapper.get_roas([original_scale])

Compute ROAS (Return on Ad Spend) for each channel.

MMMIDataWrapper.get_target([original_scale])

Get observed target data with consistent access pattern.

MMMIDataWrapper.get_target_scale()

Get target scaling factor used during model fitting.

MMMIDataWrapper.to_original_scale(var)

Transform variable from scaled to original scale.

MMMIDataWrapper.to_scaled(var)

Transform variable from original to scaled space.

MMMIDataWrapper.validate()

Validate idata structure against schema.

MMMIDataWrapper.validate_or_raise()

Validate idata structure, raising detailed exception if invalid.

Attributes

channels

Get channel coordinate.

custom_dims

Get all custom dimension names.

dates

Get date coordinate.