Pymc marketing sample_posterior_predictive (Bug)

Version: 0.16.0

When using mmm.sample_posterior_predictive setting original_scale=True will only affect ‘y’ variable like so

if original_scale:
    if hasattr(self, "target_scale"):
        # Use the new computed scale factor approach
        if self.output_var in posterior_predictive_samples:
            posterior_predictive_samples[self.output_var] = (
                posterior_predictive_samples[self.output_var]
                * self.target_scale
            )

where self.output_var is

    @property
    def output_var(self) -> Literal["y"]:
        """Define target variable for the model.

        Returns
        -------
        str
            The target variable for the model.
        """
        return "y"

That means posterior_predictive_samples['channel_contribution']is never affected by the scale parameter. This has downstream affects with other functions such as plot_budget_allocation where by default original_scale=True and channel calculation is calculated with

channel_contribution = (samples["channel_contribution"].mean(dim=["date", "sample"]).to_numpy())

if not original_scale:
    channel_contribution /= self.get_target_transformer()["scaler"].scale_

However if passing values from posterior_predictive_samples samples[“channel_contribution”] is never scaled to begin with so original_scale will not have the desired effect.

For example if someone is following the end to end notebook with the latest pymc marketing version they will not arrive at correct values as the workflow is using these functions in tandem.

Functions used:

sample response distribution link

plot budget allocation link

sample posterior predictive link