DelayedSaturatedMMM.add_lift_test_measurements#

DelayedSaturatedMMM.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 sudo code for the lift test is as follows:

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

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

Parameters:
  • df_lift_test (pd.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.

  • dist (pm.Distribution, optional) – The distribution to use for the likelihood, by default pm.Gamma

  • name (str, 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.

Return type:

None

Examples

Build the model first then add lift test measurements.

model = DelayedSaturatedMMM(
    date_column="date_week",
    channel_columns=["x1", "x2"],
    control_columns=[
        "event_1",
        "event_2",
    ],
    adstock_max_lag=8,
    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)