MMMSummaryFactory.adstock_curves#
- MMMSummaryFactory.adstock_curves(hdi_probs=None, output_format=None, data=None, amount=1.0, num_samples=None, random_state=None)[source]#
Create adstock curves summary DataFrame.
Delegates to MMM.sample_adstock_curve() to sample adstock weight curves from the posterior distribution, then computes summary statistics (mean, median, HDI).
Requires model to be provided (has adstock transformation).
- Parameters:
- hdi_probssequence of
float, optional HDI probability levels (default: uses factory default)
- output_format{“pandas”, “polars”}, optional
Output DataFrame format (default: uses factory default)
- data
MMMIDataWrapperorNone, optional Optional data wrapper to use for sampling curves. If None (default), uses self.data. This allows sampling curves from a different InferenceData, such as from a subset of samples or another model.
- amount
float, default 1.0 Amount to apply the adstock transformation to. This represents an impulse of spend at time 0, and the curve shows how this effect decays over subsequent time periods.
- num_samples
intorNone, optional Number of posterior samples to use for generating curves. By default None (use all posterior samples for accurate HDI). Using fewer samples speeds up computation and reduces memory usage while still capturing posterior uncertainty.
- random_state
int,np.random.Generator, orNone, optional Random state for reproducible subsampling. Can be an integer seed, a numpy Generator instance, or None for non-reproducible sampling. Only used when num_samples is not None and less than total available samples.
- hdi_probssequence of
- Returns:
pd.DataFrameorpl.DataFrameSummary DataFrame with columns:
time since exposure: Lag period (0 to l_max from the adstock transformation)
channel: Channel name
<custom_dims>: One column for each custom dimension (e.g., country)
mean: Mean adstock weight
median: Median adstock weight
abs_error_{prob}_lower: HDI lower bound for each prob
abs_error_{prob}_upper: HDI upper bound for each prob
See also
MMM.sample_adstock_curveUnderlying method for sampling curves
saturation_curvesFor saturation curves
Examples
>>> df = mmm.summary.adstock_curves() >>> df = mmm.summary.adstock_curves(amount=100.0) >>> df = mmm.summary.adstock_curves(hdi_probs=[0.80, 0.94]) >>> df = mmm.summary.adstock_curves(num_samples=500, random_state=42)