MMM.add_lift_test_measurements#

MMM.add_lift_test_measurements(df_lift_test, dist=<class 'pymc.distributions.continuous.Gamma'>, name='lift_measurements')[source]#

Add lift tests to the model.

The model difference of a channel’s saturation curve is created from x and x + delta_x for each channel. This random variable is then conditioned using the empirical lift, delta_y, and sigma of the lift test with the specified distribution dist.

The pseudo-code for the lift test is as follows:

model_estimated_lift = (
    saturation_curve(x + delta_x)
    - saturation_curve(x)
)
empirical_lift = delta_y
dist(abs(model_estimated_lift), sigma=sigma, observed=abs(empirical_lift))

The model has to be built before adding the lift tests.

Parameters:
df_lift_testpd.DataFrame
DataFrame with lift test results with at least the following columns:
  • channel: channel name. Must be present in channel_columns.

  • x: x axis value of the lift test.

  • delta_x: change in x axis value of the lift test.

  • delta_y: change in y axis value of the lift test.

  • sigma: standard deviation of the lift test.

distpm.Distribution, optional

The distribution to use for the likelihood, by default pm.Gamma

namestr, optional

The name of the likelihood of the lift test contribution(s), by default “lift_measurements”. Name change required if calling this method multiple times.

Raises:
RuntimeError

If the model has not been built yet.

KeyError

If the ‘channel’ column is not present in df_lift_test.

Examples

Build the model first then add lift test measurements.

import pandas as pd
import numpy as np

from pymc_marketing.mmm import (
    GeometricAdstock,
    LogisticSaturation,
    MMM,
)

model = MMM(
    date_column="date_week",
    channel_columns=["x1", "x2"],
    adstock=GeometricAdstock(l_max=8),
    saturation=LogisticSaturation(),
    control_columns=[
        "event_1",
        "event_2",
    ],
    yearly_seasonality=2,
)

X: pd.DataFrame = ...
y: np.ndarray = ...

model.build_model(X, y)

df_lift_test = pd.DataFrame({
    "channel": ["x1", "x1"],
    "x": [1, 1],
    "delta_x": [0.1, 0.2],
    "delta_y": [0.1, 0.1],
    "sigma": [0.1, 0.1],
})

model.add_lift_test_measurements(df_lift_test)