Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/DoktorMike/dammmdatagen
Marketing Mix Modeling Data Generator
https://github.com/DoktorMike/dammmdatagen
benchmark data data-generator marketing-mix-modeling
Last synced: 3 months ago
JSON representation
Marketing Mix Modeling Data Generator
- Host: GitHub
- URL: https://github.com/DoktorMike/dammmdatagen
- Owner: DoktorMike
- License: other
- Created: 2017-11-13T00:39:17.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-12-27T16:26:06.000Z (almost 3 years ago)
- Last Synced: 2024-05-13T00:11:12.351Z (6 months ago)
- Topics: benchmark, data, data-generator, marketing-mix-modeling
- Language: R
- Homepage: https://doktormike.github.io/dammmdatagen/
- Size: 10.9 MB
- Stars: 43
- Watchers: 4
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-marketing-machine-learning - dammmdatagen
README
---
output: github_document
---```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```The goal of dammmdatagen is to make it easy for marketing mix modeling professionals to get access to realistic data sets where the ground truth is known. This fascilitates our development and provides in the end more value for all stakeholders of MMM.
## Build status etc
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![R-CMD-check](https://github.com/DoktorMike/dammmdatagen/workflows/R-CMD-check/badge.svg)](https://github.com/DoktorMike/dammmdatagen/actions)
[![Codecov test coverage](https://codecov.io/gh/DoktorMike/dammmdatagen/branch/master/graph/badge.svg)](https://app.codecov.io/gh/DoktorMike/dammmdatagen?branch=master)## Installation
You can install dammmdatagen from github with:
```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("DoktorMike/dammmdatagen")
```## Quick start
This is a basic example which shows you how to generate a small 1 year data set.
```{r example, cache=TRUE}
# load useful libraries
library(dammmdatagen)# generate a basic data set
mydf <- generateCovariatesData()
head(mydf)
```Say that you would like to also generate a response variable to fit a model to. Then you could use the highlevel API function below.
```{r fullexample, cache=TRUE}
library(dammmdatagen)
library(ggplot2)
library(dplyr)
library(tidyr)
library(scales)
ret <- generateRetailData()
dates <- ret[["covariates"]][["Macro"]][["date"]]
qplot(dates, ret[["response"]]) + geom_line() + ylim(0, NA)
# entrytocolname <- function(x) a <- ret[["effects"]][[x]] %>% setNames(c(tolower(paste0(x, "_", names(.)))))
entrytocolname <- function(x) tibble::tibble(rowSums(ret[["effects"]][[x]])) %>% setNames(x)
Reduce(dplyr::bind_cols, lapply(names(ret[["effects"]]), entrytocolname)) %>%
dplyr::mutate(date = dates) %>%
tidyr::pivot_longer(-date, names_to = "variable", values_to = "value") %>%
ggplot2::ggplot(ggplot2::aes(x = date, y = value, fill = variable)) +
ggplot2::geom_bar(stat = "identity") + ggplot2::theme_minimal() +
ggplot2::ylab("Units sold") +
ggplot2::xlab("")
```We can do a lot more of course! In this small snippet we'll generate 1 month worth of competitor media spendings data and plot that out.
```{r competitorspendplot, fig.width=10, message=FALSE, warning=FALSE, paged.print=FALSE, cache=TRUE}
library(dammmdatagen)
library(ggplot2)
library(dplyr)
library(tidyr)
library(scales)generateCompetitorData(fromDate = Sys.Date() - 30, toDate = Sys.Date()) %>%
gather("competitor", "spend", -"date") %>%
ggplot(aes(y = spend, x = date, fill = competitor)) +
geom_bar(stat = "identity", position = position_stack()) +
theme_minimal() +
scale_y_continuous(labels = dollar_format(prefix = "kr. "))
```Just as we can generate competitor spending data we can also generate macroeconomical data. These types of indicators are typically slow moving over time with minor temporal differences.
```{r macroecondataplot, fig.width=10, message=FALSE, warning=FALSE, paged.print=FALSE, cache=TRUE}
generateMacroData(fromDate = Sys.Date() - 30, toDate = Sys.Date()) %>%
gather("indicator", "value", -"date") %>%
ggplot(aes(y = value, x = date, color = indicator)) +
geom_line(size = 1.5) +
theme_minimal()
```## Event type data
Event data are modeled as a poisson distribution with a low incidence.
```{r eventdata1, fig.width=10, message=FALSE, warning=FALSE, paged.print=FALSE, cache=TRUE}
generateEventData(Sys.Date() - 265, Sys.Date()) %>%
gather(type, value, -date) %>%
ggplot(aes(y = value, x = date, fill = type)) +
geom_bar(stat = "identity") +
theme_minimal()
```The incidence can of course be controlled. This is done via the freq parameter.
```{r eventdata2, fig.width=10, message=FALSE, warning=FALSE, paged.print=FALSE, cache=TRUE}
generateEventData(Sys.Date() - 265, Sys.Date(), freq = 0.1) %>%
gather(type, value, -date) %>%
ggplot(aes(y = value, x = date, fill = type)) +
geom_bar(stat = "identity") +
theme_minimal()
```## Media generation
Generating media is in general a bit more complicated as we need more information since in MMM models that's what we primarily care about. So we need three data.frames; the net, the impressions and the cpms. We also differentiate between offline and online media. This difference is rather artificial right now but it's to futureproof the package.
```{r onlineimpdata, fig.width=10, message=FALSE, warning=FALSE, paged.print=FALSE, cache=TRUE}
mydflist <- generateOnlineData(Sys.Date() - 30, Sys.Date())
mydflist[["impression"]] %>%
gather(type, impression, -date) %>%
ggplot(aes(y = impression, x = date, fill = type)) +
geom_bar(stat = "identity") +
theme_minimal()
```## Code of Conduct
Please note that the dammmdatagen project is released with a [Contributor Code of Conduct](https://doktormike.github.io/dammmdatagen/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.