Last time, I talked about the media variable transformariton. Ten sets of tranformation data of lag, decay and alpha was already set up. So the next step was to put all the variables we chose put into model and test them one by one until we got the final model that we think was the best one (the transformed dataset was named mmm_transformed).
Create dummy variables
In exploration analysis phase, I found the seasonality pattern of the data. There were two spikes per year occuring on July 4th and Black Friday. So before building model, I created the two dummy variables first.
mmm_transformed[, "black_friday"] = 0
mmm_transformed[which(mmm_transformed$Period == "2014-11-24"), "black_friday"] = 1
mmm_transformed[which(mmm_transformed$Period == "2015-11-30"), "Black_Friday"] = 1
mmm_transformed[which(mmm_transformed$Period == "2016-11-28"), "Black_Friday"] = 1
mmm_transformed[which(mmm_transformed$Period == "2017-11-27"), "Black_Friday"] = 1
mmm_transformed[, "july4th"] = 0
mmm_transformed[which(mmm_transformed$Period == "2014-07-07"), "july4th"] = 1
mmm_transformed[which(mmm_transformed$Period == "2015-07-06"), "july4th"] = 1
mmm_transformed[which(mmm_transformed$Period == "2016-07-04"), "july4th"] = 1
mmm_transformed[which(mmm_transformed$Period == "2017-07-03"), "july4th"] = 1
Variable selection
In this process, I put candidated variables into the model one by one, and selected those for final model according to several principles:
- P value is as small as possible (significance level is 0.05).
- T value is as big as possible (at least > 1).
- VIF < 6.
- Adjusted R-squared is as big as possible.
These principles were used collectively.
Through the selection process, I got my final model:final_model <- lm(Sales ~ black_friday + july4th + CCI + sales_event + comp_media_spend + national_tv2 + paid_search1 + wechat1 + magazine1 + display1 + facebook2, data = mmm_transformed)The summary of the final model is:

The R-squared is very close to 1.
And the MAPE:MAPE(y_pred = model$fitted.values, y_true = MMM$Sales)The calculated MAPE is 0.008.
So maybe it’s a good model.