Skip to main content
Version: 3.13

auto-mmm

R

### Automatic Media-Mix Model

#You will learn how to perform attribution with the automatic media-mix model (MMM) using the `auto_mmm` function from the `ChannelAttributionPro` package.
#The model leverages copula-based methods for improved accuracy and flexibility, allowing for better media attribution across marketing channels.

## Steps:
#- Import required libraries and the dataset
#- Define a dictionary linking dependent variables to marketing channels
#- Estimate the media-mix model using `auto_mmm` with appropriate parameters

### Import libraries"""

library(ChannelAttributionPro)
options(max.print=100)

### Set your token

token="yourtoken"

### Load data

# Load the dataset from the given URL
# This dataset should contain the timestamp, the target variable (revenue), and the dependent variables (marketing channels)
Data = read.csv("https://app.channelattribution.io/data/data_mmm.csv", sep = ",")
Data

# List to map the dependent variables (e.g., impressions, clicks, costs) to their respective channels
D_variables = list(
"revenue" = "target",
"direct_searches" = "direct_searches",
"facebook_impressions" = "facebook",
"facebook_cost" = "facebook",
"google_impressions" = "google",
"google_clicks" = "google",
"google_cost" = "google"
)
D_variables

# Call the auto_mmm function to estimate the automatic media mix model (MMM)
# The function parameters are explained below:
# - Data: The dataset containing the marketing data
# - D_variables: A dictionary linking dependent variables to their respective channels
# - max_p: Maximum lagged effects to consider for each dependent variable (default = 12)
# - nsim: Number of predictions to generate from copula distributions (default = 1000)
# - seed: Random seed for reproducibility (default = 1234567)
# - verbose: Whether to show additional information during the execution (default = True)
res = auto_mmm(
Data=Data, # The dataset containing timestamp, target, and dependent variables
D_variables=D_variables, # The dictionary associating dependent variables with channels
max_p=12, # Maximum lag for each dependent variable
nsim=1000, # Number of predictions from copula distributions
seed=1234567, # Random seed to ensure reproducibility
verbose=1 # Display detailed execution information
)

### Results
#After the model estimation is complete, the `res` object will contain the results, which can include various metrics such as the #contribution of each channel, predictions, etc.


# Example: Printing out the results summary (if available in the res object)
print(res)

#As you can see, attribution starts from a timestamp equal to max_p+1 because the algorithm uses the first max_p observations to estimate lagged effects. If you need attribution for the first max_p timestamps, you can run auto_mmm with max_p=0. But keep in mind that the resulting attribution could be imprecise.

res1 = auto_mmm(
Data,
D_variables,
max_p=0,
nsim=1000,
seed=1234567,
verbose=1
)

res1=res1[0:12,]

print(res1)