This is the exploration analysis before creating the linear regression model. In this exploration, I plotted various relationships among different variables and got some insights.

Before Exploration

setwd("~/Documents/marketing mix model/marketing mix model")
mmm_raw <- read.csv("mmm_raw.csv", header = TRUE) #import the raw data
mmm_raw$Period <- as.Date(mmm_raw$Period, '%m/%d/%Y') #transform the period into date type for later analysis
summary(is.na(mmm_raw)) #check if there is missing value in raw dataset
##    Period          Month            CCI          National.TV.GRPs
##  Mode :logical   Mode :logical   Mode :logical   Mode :logical   
##  FALSE:208       FALSE:208       FALSE:208       FALSE:208       
##  Magazine.GRPs   Paid.Search      Display        Facebook.Impressions
##  Mode :logical   Mode :logical   Mode :logical   Mode :logical       
##  FALSE:208       FALSE:208       FALSE:208       FALSE:208           
##    Wechat        Sales.Event     Black.Friday     July.4th      
##  Mode :logical   Mode :logical   Mode :logical   Mode :logical  
##  FALSE:208       FALSE:208       FALSE:208       FALSE:208      
##  Comp.Media.Spend   Sales         DisplayAlwaysOnImpression
##  Mode :logical    Mode :logical   Mode :logical            
##  FALSE:208        FALSE:208       FALSE:208                
##  DisplayBrandingImpression DisplayWebsiteImpression DisplayHolidayImpression
##  Mode :logical             Mode :logical            Mode :logical           
##  FALSE:208                 FALSE:208                FALSE:208               
##  SearchBrandingclicks SearchAlwasyOnclicks SearchWebsiteclicks
##  Mode :logical        Mode :logical        Mode :logical      
##  FALSE:208            FALSE:208            FALSE:208          
##  FacebookBrandingImpressions FacebookHolidayImpressions
##  Mode :logical               Mode :logical             
##  FALSE:208                   FALSE:208                 
##  FacebookOtherImpressions
##  Mode :logical           
##  FALSE:208

Insights: the two periods when the sales spike appears should be created later as two new independent variables for the model

Compare Trend Lines Between Different Variables & Sales, and Get Some Insights

Plot sales trend line along time series

plot(mmm_raw$Period, mmm_raw$Sales,
     type = 'l', xlab = 'period', ylab = 'sales',
     main = 'trend line: sales')

Add trend lines of other variables into the sales trend line, and compare these trend lines to get some insights

Trend lines of sales and sales.event

plot(mmm_raw$Period, mmm_raw$Sales,
     type = 'l', xlab = 'period', ylab = 'sales',
     main = 'Trend line: sales') #sales trend line
par(new = TRUE)
plot(mmm_raw$Period, mmm_raw$Sales.Event,
     type = 'l', col = 'red', 
     xlab = '', ylab = '', axes = FALSE) #sales.event trend line

Insights: two dummy variables should be separated from sales event

Trend lines of sales and CCI

plot(mmm_raw$Period, mmm_raw$Sales,
     type = 'l', xlab = 'period', ylab = 'sales',
     main = 'Trend line: sales') #sales trend line
par(new = TRUE)
plot(mmm_raw$Period, mmm_raw$CCI,
     type = 'l', col = 'red', 
     xlab = '', ylab = '', axes = FALSE) #CCI trend line

Trend lines of sales and Comp.Media.Spend

plot(mmm_raw$Period, mmm_raw$Sales,
     type = 'l', xlab = 'period', ylab = 'sales',
     main = 'Trend line: sales') #sales trend line
par(new = TRUE)
plot(mmm_raw$Period, mmm_raw$Comp.Media.Spend,
     type = 'l', col = 'red', 
     xlab = '', ylab = '', axes = FALSE) #Comp.Media.Spend trend line

Trend lines of sales and National.TV.GRPs

plot(mmm_raw$Period, mmm_raw$Sales,
     type = 'l', xlab = 'period', ylab = 'sales',
     main = 'Trend line: sales') #sales trend line
par(new = TRUE)
plot(mmm_raw$Period, mmm_raw$National.TV.GRPs,
     type = 'l', col = 'red', 
     xlab = '', ylab = '', axes = FALSE) #National.TV.GRPs trend line

Trend lines of sales and Magazine.GRPs

plot(mmm_raw$Period, mmm_raw$Sales,
     type = 'l', xlab = 'period', ylab = 'sales',
     main = 'trend line: sales') #sales trend line
par(new = TRUE)
plot(mmm_raw$Period, mmm_raw$Magazine.GRPs,
     type = 'l', col = 'red', 
     xlab = '', ylab = '', axes = FALSE) #Magazine.GRPs trend line

Trend lines of sales and Paid.Search

plot(mmm_raw$Period, mmm_raw$Sales,
     type = 'l', xlab = 'period', ylab = 'sales',
     main = 'trend line: sales') #sales trend line
par(new = TRUE)
plot(mmm_raw$Period, mmm_raw$Paid.Search,
     type = 'l', col = 'red', 
     xlab = '', ylab = '', axes = FALSE) #Paid.Search trend line

Trend lines of sales and Display

plot(mmm_raw$Period, mmm_raw$Sales,
     type = 'l', xlab = 'period', ylab = 'sales',
     main = 'trend line: sales') #sales trend line
par(new = TRUE)
plot(mmm_raw$Period, mmm_raw$Display,
     type = 'l', col = 'red', 
     xlab = '', ylab = '', axes = FALSE) #Display trend line

Trend lines of sales and Facebook.Impressions

plot(mmm_raw$Period, mmm_raw$Sales,
     type = 'l', xlab = 'period', ylab = 'sales',
     main = 'trend line: sales') #sales trend line
par(new = TRUE)
plot(mmm_raw$Period, mmm_raw$Facebook.Impressions,
     type = 'l', col = 'red', 
     xlab = '', ylab = '', axes = FALSE) #Facebook.Impressions trend line

Trend lines of sales and Wechat

plot(mmm_raw$Period, mmm_raw$Sales,
     type = 'l', xlab = 'period', ylab = 'sales',
     main = 'trend line: sales') #sales trend line
par(new = TRUE)
plot(mmm_raw$Period, mmm_raw$Wechat,
     type = 'l', col = 'red', 
     xlab = '', ylab = '', axes = FALSE) #Wechat trend line

Compare Scatterplot of Sales and Various Independent Variables, and Get Some Insights

scatter.smooth(mmm_raw$Sales.Event, mmm_raw$Sales,
               xlab = 'Sales Event', ylab = 'Sales',
               main = 'Scatterplot: Sales ~ Sales Event') #if you don't want scientific notation to show up in the plot, just try "options(scipen=5)" before running this command line
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, : at
## -0.005
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## radius 2.5e-05
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, : all
## data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## pseudoinverse used at -0.005
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## neighborhood radius 0.005
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## reciprocal condition number 1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## There are other near singularities as well. 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## zero-width neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, : at
## -0.005
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## radius 2.5e-05
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, : all
## data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## pseudoinverse used at -0.005
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## neighborhood radius 0.005
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## reciprocal condition number 1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## There are other near singularities as well. 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## zero-width neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, : at
## -0.005
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## radius 2.5e-05
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, : all
## data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## pseudoinverse used at -0.005
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## neighborhood radius 0.005
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## reciprocal condition number 1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## There are other near singularities as well. 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## zero-width neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, : at
## -0.005
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## radius 2.5e-05
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, : all
## data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## pseudoinverse used at -0.005
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## neighborhood radius 0.005
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## reciprocal condition number 1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## There are other near singularities as well. 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## zero-width neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, : at
## -0.005
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## radius 2.5e-05
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, : all
## data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## pseudoinverse used at -0.005
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## neighborhood radius 0.005
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## reciprocal condition number 1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## There are other near singularities as well. 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = FALSE, :
## zero-width neighborhood. make span bigger

scatter.smooth(mmm_raw$CCI, mmm_raw$Sales,
               xlab = 'CCI', ylab = 'Sales',
               main = 'Scatterplot: Sales ~ CCI')

scatter.smooth(mmm_raw$Comp.Media.Spend, mmm_raw$Sales,
               xlab = 'Competitor Media Spend', ylab = 'Sales',
               main = 'Scatterplot: Sales ~ Competitor Meida Spend')

scatter.smooth(mmm_raw$National.TV.GRPs, mmm_raw$Sales,
               xlab = 'National TV GRP', ylab = 'Sales',
               main = 'Scatterplot: Sales ~ National TV GRP')

scatter.smooth(mmm_raw$Magazine.GRPs, mmm_raw$Sales,
               xlab = 'Magazine GRP', ylab = 'Sales',
               main = 'Scatterplot: Sales ~ Magazine GRP')

scatter.smooth(mmm_raw$Paid.Search, mmm_raw$Sales,
               xlab = 'Paid Search', ylab = 'Sales',
               main = 'Scatterplot: Sales ~ Paid Search')

scatter.smooth(mmm_raw$Display, mmm_raw$Sales,
               xlab = 'Display', ylab = 'Sales',
               main = 'Scatterplot: Sales ~ Display')

scatter.smooth(mmm_raw$Facebook.Impressions, mmm_raw$Sales,
               xlab = 'FB Impressions', ylab = 'Sales',
               main = 'Scatterplot: Sales ~ FB Impressions')

scatter.smooth(mmm_raw$National.TV.GRPs, mmm_raw$Sales,
               xlab = 'National TV GRP', ylab = 'Sales',
               main = 'Scatterplot: Sales ~ National TV GRP')

scatter.smooth(mmm_raw$Wechat, mmm_raw$Sales,
               xlab = 'Wechat', ylab = 'Sales',
               main = 'Scatterplot: Sales ~ Wechat')

Correlation Matrix

library(corrplot)
## corrplot 0.84 loaded
correlation_matrix <- cor(mmm_raw[3:14])
corrplot(correlation_matrix,
         type = 'upper', tl.srt=45, 
         tl.col = 'black', tl.cex = 0.8,
         addCoef.col = 'black')