pymc-marketing
pymc-marketing copied to clipboard
Negative delta x causes sampling error
Default implementation uses Gamma distribution which doesn't work well with delta x (and delta y) being negative.
Absolute value of the difference and delta_y could fix. Location of change: https://github.com/pymc-labs/pymc-marketing/blob/78964f0708179da63080a7d5c0398433616f774c/pymc_marketing/mmm/lift_test.py#L278-L287
Reproducible example:
import numpy as np
import pandas as pd
from pymc_marketing.mmm import DelayedSaturatedMMM
data_url = "https://raw.githubusercontent.com/pymc-labs/pymc-marketing/main/data/mmm_example.csv"
data = pd.read_csv(data_url, parse_dates=["date_week"])
mmm = DelayedSaturatedMMM(
date_column="date_week",
channel_columns=["x1", "x2"],
control_columns=[
"event_1",
"event_2",
"t",
],
adstock_max_lag=8,
yearly_seasonality=2,
)
# Set features and target
X = data.drop("y", axis=1)
y = data["y"]
mmm.build_model(X, y)
# Delta x is negative
df_lift_test = pd.DataFrame({
"channel": ["x1"],
"x": [1],
"delta_x": [-0.1],
"delta_y": [-0.1],
"sigma": [0.05],
})
mmm.add_lift_test_measurements(df_lift_test)
mmm.fit(X, y)