PyMC-Marketing MMM: Setting negative negative variables using priors?

I am using PyMC-Marketing to build an MMM in which i have a control and a channel variable that i want to set as negative.

Given the constrains of the distributions used, i seen to only be able to set positive positive values for the beta coefficients using the model_config.

I also tried converting these features to negative values, which return a ValueError

Any suggestions on how i can tackle this case using the package?

I also tried converting these features to negative values, which return a ValueError

This should work, can you share more details on the error message?

We are making the prior specification more flexible:


All i did was multiply the column of the negative channel by -1 and input it as a channel variable along all others.


Here is the error i get when trying to run

ValueError                                Traceback (most recent call last)
Cell In[34], line 4
      1 X = df_train.drop(kpi,axis=1)
      2 y = df_train[kpi]
----> 4, y=y, target_accept=0.95, chains=4, random_seed=42)

File /opt/conda/lib/python3.11/site-packages/pymc_marketing/, in, X, y, progressbar, predictor_names, random_seed, **kwargs)
    509     y = np.zeros(X.shape[0])
    510 y_df = pd.DataFrame({self.output_var: y})
--> 511 self.generate_and_preprocess_model_data(X, y_df.values.flatten())
    512 if self.X is None or self.y is None:
    513     raise ValueError("X and y must be set before calling build_model!")

File /opt/conda/lib/python3.11/site-packages/pymc_marketing/mmm/, in BaseDelayedSaturatedMMM.generate_and_preprocess_model_data(self, X, y)
    124 self.model_coords = coords
    125 if self.validate_data:
--> 126     self.validate("X", X_data)
    127     self.validate("y", y)
    128 self.preprocessed_data: Dict[str, Union[pd.DataFrame, pd.Series]] = {
    129     "X": self.preprocess("X", X_data),
    130     "y": self.preprocess("y", y),
    131 }

File /opt/conda/lib/python3.11/site-packages/pymc_marketing/mmm/, in BaseMMM.validate(self, target, data)
    126     validation_methods = self.validation_methods[1]
    128 for method in validation_methods:
--> 129     method(self, data)

File /opt/conda/lib/python3.11/site-packages/pymc_marketing/mmm/, in ValidateChannelColumns.validate_channel_columns(self, data)
     59     raise ValueError(
     60         f"channel_columns {self.channel_columns} contains duplicates"
     61     )
     62 if (data.filter(list(self.channel_columns)) < 0).any().any():
---> 63     raise ValueError(
     64         f"channel_columns {self.channel_columns} contains negative values"
     65     )

ValueError: channel_columns ['channel1','channel2','channel3','channel4','channel5'] contains negative values

The validate_channel_columns function seems to block negative values in the channel data.

Oh, that’s a shame. Do you mind opening an issue in GitHub - pymc-labs/pymc-marketing: Bayesian marketing toolbox in PyMC. Media Mix (MMM), customer lifetime value (CLV), buy-till-you-die (BTYD) models and more. ?