Media Mix Modeling in R

While attribution measurements are widely used in the digital marketing field, Media Mix Modeling (MMM) still plays an important role in evaluating marketing effectiveness across multiple channels at a higher level. Here is an example of how to do MMM in R with a free dataset from Kaggle.

Data Preparation

library(tidyverse)

# Import data
media.raw <- read_csv("mediamix.csv")

# Tidy data
media <- media.raw %>%
      mutate(TV = tv_sponsorships + tv_cricket + tv_RON) %>%
      mutate(Digital = rowSums(.[9:13])) %>%
      select(TV, radio, Magazines, OOH, Digital, sales) %>%
      rename(Radio = radio, Sales = sales)

# Examining data
View(media)

Three TV-related channels are combined as TV variable. Similarly, the Digital variable is computed from channels such as Social, Display, Search, etc. The final data structure is shown as follows. This article is to examine the relationship between the dependent variable of Sales and the independent variables of TV, Radio, Magazines, OOH, and Digital. The numbers represent the media cost across channels.

Continue reading

Mediation Analysis in SPSS and R

Background

In the past few months I have been working on my Master’s Thesis and I just completed the data analysis part, leaving the discussion and conclusion parts. For some reason, this data analysis is conducted in SPSS and I’m always wondering if I could repeat it in R. The topic of my Master’s Thesis is “The influence of IT Capability on New Product Development Performance”. Specifically, my research question is “To what extent does IT Capability relate to NPD Performance and to what extent does NPD Process mediate the relationship?”.

The data was collected with a questionnaire that is designed based on a thorough literature review. After data cleaning, construct validity tests with Exploratory Factor Analysis and construct reliability tests, the latent constructs are computed and the enhanced operational model is presented below:

Figure 1. Operational Conceptual Model
Continue reading

Market Basket Analysis in R

Introduction

Hundreds and thousands of transactions occur every day in a supermarket, while a customer would buy multiple products in each transaction. For example, it may look like this in the database: {Transaction1: Product1, Product3, Product4, Product8, Product9}. In a larget data set of transactions, purchase patterns, i.e. some products are always bought together, can be examined based on product association analysis, also called Market Basket Analysis.

Key Concepts of Market Basket Analysis

The basics of market basket analysis
The basics of market basket analysis, source: UofT

Basically, there are four key concepts of Market Basket Analysis:

  • Rule: a rule expresses the incidence across transactions of one set of items as a condition of another set of items, i.e. X => Y;
  • Support: the support for a set of items is the proportion of all transactions that contain the set;
  • Confidence: the support for the co-occurrence of all items in a rule, conditional on the support for the left-hand set alone;
  • Lift: the support of a set conditional on the joint support of each element;
Continue reading

R Basic Takeaways

While learning R, I was always thinking to make some notes and some of the concepts really took me more time than what I expected. That is why I am planning to make a Cheat Sheet for R so that I can always come back to check the key points instead of searching online every time. Therefore, I will first make a summary, in this post, of the key points from the books I read and update it when necessary. Hopefully, I can make an R Cheat Sheet based on this in the end.

Asking for help

Asking for help in R

Inspecting Data

Continue reading

Transportation and Assignment problems with R

In the previous post “Linear Programming with R” we examined the approach to solve general linear programming problems with “Rglpk” and “lpSolve” packages. Today, let’s explore “lpSolve” package in depth with two specific problems of linear programming: transportation and assignment.

1. Transportation problem

Transportation problem, Frederick & Mark (2014, p.95)

Usage:

lp.transport(cost.mat, direction="min", row.signs, row.rhs, col.signs,
               col.rhs, presolve=0, compute.sens=0, integers = 1:(nc*nr))
Continue reading