README.md

bayesmmm

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.

Update

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.

Installation

library(devtools)
install_github("https://github.com/nrhodes1451/bayesmmm")

Examples

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)

View model fit

model$plots$fit

View coefficient posterior distributions:

model$plots$coeffs$Seasonality

Get model decomposition calculated from MAP estimates

model$decomp %>% write_csv("decomp.csv")

Media transformations

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)

View media transformation posterior distributions:

model$plots$adstocks

model$plots$denominators

View trace plots for convergence

model %>% trace_plot("Media")

View model decomposition

model$plots$decomp



nrhodes1451/bayesmmm documentation built on Jan. 2, 2020, 2:16 a.m.