Pooled Marketing Mix Modelling using RStan.
This project was born out of a desire to reimagine traditional frequentist MMM in a hierarchical Bayesian framework. Much of the credit here goes to Richard McElreath and the fantastic Statistical Rethinking for introducing me to Bayesian statistics and associated philosophy.
Please note that this package is currently incomplete. I hope to complete/refine as and when I have time, but this is currently taking the back seat between work/study/moving house.
library(devtools)
install_github("https://github.com/nrhodes1451/bayesmmm")
library(tidyverse)
library(bayesmmm)
model_data <- bayesmmm::demo_dataset
Use the variable_grid()
function to create a data frame to contain the model specification
y <- "Sales"
variables <- c("Media",
"Seasonality",
"CCI",
"Competitor") %>% variable_grid
Run the model
model <- bayesmmm::bayesmodel(model_data,
y,
variables)
model$plots$fit
model$plots$coeffs$Seasonality
model$decomp %>% write_csv("decomp.csv")
variables <- c("Media",
"Seasonality",
"CCI",
"Competitor") %>% variable_grid
Set a variable's transformation to "media" within the variable_grid
in order to calculate media Adstocks/diminishing returns rates
variables$transformation[1] <- "media"
model <- bayesmmm::bayesmodel(model_data,
y,
variables)
model$plots$adstocks
model$plots$denominators
model %>% trace_plot("Media")
model$plots$decomp