Friday 8 January 2016

Marketing Mix Modeling

# Marketing Mix - Brands 
# Customer ratings for - perceptual adjectives and 4 brands.
# Within marketing analytics - perceptual adjectives to be linked to perceptual maps.

d <- read.csv("C:/Users/Rohit/Desktop/Marketing Mix - Brands/d.csv")
head(d)
##   cheap snappy effective luxurious artistic bold caring casual charming
## 1     9      7         2        10        7    5      9      1        3
## 2     4      2         2         8        5    4      9      7        2
## 3     5      6        10        10        1    8     10     10        8
## 4     8     10         5         5       10    2      9      2        1
## 5     9      5         3        10        3    8     10      5        3
## 6    10     10         4         9        9    3      5      1       10
##   contemporary creative daring elegant energetic exciting festive fresh
## 1            2       10      5       4        10       10       2    10
## 2            2        9      1       2         8        8       3     8
## 3           10        9      4       1         8        8       3     8
## 4            5        9      9       9         8        8       4     8
## 5            3        9      6       6         8        8       5     8
## 6            4       10      5       4        10       10       7    10
##   fun graceful hip brand.name
## 1  10        9  10          1
## 2   9        9   9          3
## 3   8        9   8          3
## 4  10        4  10          4
## 5   9        7   9          4
## 6   8        1   8          3
summary(d)
##      cheap            snappy         effective        luxurious     
##  Min.   : 1.000   Min.   : 1.000   Min.   : 1.000   Min.   : 1.000  
##  1st Qu.: 4.000   1st Qu.: 4.000   1st Qu.: 4.000   1st Qu.: 3.000  
##  Median : 8.000   Median : 8.000   Median : 6.000   Median : 6.000  
##  Mean   : 7.079   Mean   : 7.074   Mean   : 5.786   Mean   : 5.642  
##  3rd Qu.:10.000   3rd Qu.:10.000   3rd Qu.: 8.000   3rd Qu.: 8.000  
##  Max.   :10.000   Max.   :10.000   Max.   :10.000   Max.   :10.000  
##     artistic           bold            caring           casual     
##  Min.   : 1.000   Min.   : 1.000   Min.   : 1.000   Min.   : 1.00  
##  1st Qu.: 3.000   1st Qu.: 3.000   1st Qu.: 3.000   1st Qu.: 3.00  
##  Median : 6.000   Median : 5.000   Median : 6.000   Median : 6.00  
##  Mean   : 5.529   Mean   : 5.486   Mean   : 5.505   Mean   : 5.54  
##  3rd Qu.: 8.000   3rd Qu.: 8.000   3rd Qu.: 8.000   3rd Qu.: 8.00  
##  Max.   :10.000   Max.   :10.000   Max.   :10.000   Max.   :10.00  
##     charming       contemporary     creative          daring      
##  Min.   : 1.000   Min.   : 1.0   Min.   : 1.000   Min.   : 1.000  
##  1st Qu.: 3.000   1st Qu.: 3.0   1st Qu.: 4.000   1st Qu.: 3.000  
##  Median : 6.000   Median : 6.0   Median : 7.000   Median : 5.000  
##  Mean   : 5.637   Mean   : 5.8   Mean   : 6.085   Mean   : 5.473  
##  3rd Qu.: 8.000   3rd Qu.: 8.0   3rd Qu.: 9.000   3rd Qu.: 8.000  
##  Max.   :10.000   Max.   :10.0   Max.   :10.000   Max.   :10.000  
##     elegant         energetic         exciting         festive      
##  Min.   : 1.000   Min.   : 1.000   Min.   : 1.000   Min.   : 1.000  
##  1st Qu.: 3.000   1st Qu.: 4.000   1st Qu.: 4.000   1st Qu.: 3.000  
##  Median : 5.000   Median : 7.000   Median : 7.000   Median : 5.500  
##  Mean   : 5.502   Mean   : 6.082   Mean   : 6.072   Mean   : 5.478  
##  3rd Qu.: 8.000   3rd Qu.: 9.000   3rd Qu.: 9.000   3rd Qu.: 8.000  
##  Max.   :10.000   Max.   :10.000   Max.   :10.000   Max.   :10.000  
##      fresh             fun            graceful           hip        
##  Min.   : 1.000   Min.   : 1.000   Min.   : 1.000   Min.   : 1.000  
##  1st Qu.: 4.000   1st Qu.: 3.000   1st Qu.: 3.000   1st Qu.: 3.000  
##  Median : 7.000   Median : 6.000   Median : 5.000   Median : 6.000  
##  Mean   : 6.103   Mean   : 5.961   Mean   : 5.494   Mean   : 6.005  
##  3rd Qu.: 9.000   3rd Qu.: 9.000   3rd Qu.: 8.000   3rd Qu.: 9.000  
##  Max.   :10.000   Max.   :10.000   Max.   :10.000   Max.   :10.000  
##    brand.name   
##  Min.   :1.000  
##  1st Qu.:2.000  
##  Median :3.000  
##  Mean   :2.508  
##  3rd Qu.:4.000  
##  Max.   :4.000
# scaling the raw data  - creating a scaled matrix
dsc<-scale(d[,1:20])
# creating a Data Frame of same name - "dsc" from scaled matrix 
dsc<-as.data.frame(dsc)
summary(dsc)
##      cheap             snappy          effective          luxurious      
##  Min.   :-1.9334   Min.   :-1.9356   Min.   :-1.77078   Min.   :-1.5973  
##  1st Qu.:-0.9793   1st Qu.:-0.9797   1st Qu.:-0.66072   1st Qu.:-0.9092  
##  Median : 0.2929   Median : 0.2950   Median : 0.07933   Median : 0.1230  
##  Mean   : 0.0000   Mean   : 0.0000   Mean   : 0.00000   Mean   : 0.0000  
##  3rd Qu.: 0.9290   3rd Qu.: 0.9323   3rd Qu.: 0.81937   3rd Qu.: 0.8112  
##  Max.   : 0.9290   Max.   : 0.9323   Max.   : 1.55941   Max.   : 1.4993  
##     artistic            bold             caring            casual       
##  Min.   :-1.5710   Min.   :-1.5652   Min.   :-1.5577   Min.   :-1.5768  
##  1st Qu.:-0.8772   1st Qu.:-0.8674   1st Qu.:-0.8662   1st Qu.:-0.8821  
##  Median : 0.1634   Median :-0.1696   Median : 0.1711   Median : 0.1599  
##  Mean   : 0.0000   Mean   : 0.0000   Mean   : 0.0000   Mean   : 0.0000  
##  3rd Qu.: 0.8571   3rd Qu.: 0.8771   3rd Qu.: 0.8626   3rd Qu.: 0.8545  
##  Max.   : 1.5509   Max.   : 1.5749   Max.   : 1.5541   Max.   : 1.5492  
##     charming        contemporary         creative           daring       
##  Min.   :-1.5899   Min.   :-1.76217   Min.   :-1.7559   Min.   :-1.5594  
##  1st Qu.:-0.9042   1st Qu.:-1.02798   1st Qu.:-0.7200   1st Qu.:-0.8622  
##  Median : 0.1243   Median : 0.07331   Median : 0.3159   Median :-0.1649  
##  Mean   : 0.0000   Mean   : 0.00000   Mean   : 0.0000   Mean   : 0.0000  
##  3rd Qu.: 0.8100   3rd Qu.: 0.80750   3rd Qu.: 1.0065   3rd Qu.: 0.8811  
##  Max.   : 1.4957   Max.   : 1.54170   Max.   : 1.3518   Max.   : 1.5783  
##     elegant          energetic          exciting          festive         
##  Min.   :-1.5707   Min.   :-1.7515   Min.   :-1.7434   Min.   :-1.556096  
##  1st Qu.:-0.8729   1st Qu.:-0.7176   1st Qu.:-0.7122   1st Qu.:-0.861158  
##  Median :-0.1750   Median : 0.3162   Median : 0.3190   Median : 0.007514  
##  Mean   : 0.0000   Mean   : 0.0000   Mean   : 0.0000   Mean   : 0.000000  
##  3rd Qu.: 0.8717   3rd Qu.: 1.0055   3rd Qu.: 1.0064   3rd Qu.: 0.876186  
##  Max.   : 1.5695   Max.   : 1.3501   Max.   : 1.3502   Max.   : 1.571123  
##      fresh              fun              graceful           hip           
##  Min.   :-1.7679   Min.   :-1.66693   Min.   :-1.564   Min.   :-1.691154  
##  1st Qu.:-0.7286   1st Qu.:-0.99490   1st Qu.:-0.868   1st Qu.:-1.015407  
##  Median : 0.3107   Median : 0.01315   Median :-0.172   Median :-0.001785  
##  Mean   : 0.0000   Mean   : 0.00000   Mean   : 0.000   Mean   : 0.000000  
##  3rd Qu.: 1.0035   3rd Qu.: 1.02120   3rd Qu.: 0.872   3rd Qu.: 1.011836  
##  Max.   : 1.3499   Max.   : 1.35722   Max.   : 1.568   Max.   : 1.349710
# as seen in summary - "mean" for all - dimensions - is now "0.00" 

# Now we create a merged data frame "dsc1" - adding the "brand.name" variable to the 
# scaled data frame created earlier 
dsc1<-cbind(dsc,d$brand.name)
# change the - "d$brand.name" to just "brand.name"
names(dsc1) [21] <- "brand.name"

library(corrplot)

# varied permutations of the bi variable correlation plot....
# too many variables thus creating seperate Correlation Plots 
c1<-cor(dsc1[, 1:5])
c2<-cor(dsc1[, 6:10])
c3<-cor(dsc1[, 10:15])
c4<-cor(dsc1[, 16:20])

layout(matrix(c(1, 1, 2, 3), 2, 2, byrow = TRUE))
corrplot.mixed(c1,lower="number", upper="circle")
corrplot.mixed(c2,lower="number", upper="circle")
corrplot.mixed(c3,lower="number", upper="circle")
corrplot.mixed(c4,lower="number", upper="circle")

corrplot(c3,type="upper", method="number",order="AOE")
# "AOE" for the angular order of the eigenvectors
corrplot(c4,type="upper", method="shade",order="hclust")
# "hclust" for the hierarchical clustering order.
corrplot(c3,type="upper", method="shade",order="FPC")
# "FPC" for the first principal component order.
corrplot(c4,type="upper", method="ellipse",order="FPC")
# "FPC" for the first principal component order.
#  method="ellipse" 
corrplot(c4,type="upper", method="color",order="hclust")
# "FPC" for the first principal component order.
#  method="color" 
corrplot(c3,type="upper", method="shade",order="hclust")
# "FPC" for the first principal component order.
#  method="shade"  - not very different from "color"

###
# Whats the average or the "mean" rating for each brand 
# for all given - 20 - perceptual adjectives ? 
###

avg.ratings <- aggregate(.~ brand.name , data=dsc1 , mean)
View(avg.ratings)
library(gplots)
## 
## Attaching package: 'gplots'
## 
## The following object is masked from 'package:stats':
## 
##     lowess
library("RColorBrewer", lib.loc="~/R/win-library/3.1")
heatmap.2(as.matrix(c3),col=brewer.pal(9, "GnBu"),
          xlab=" Perceptual Adjectives ", ylab= "Coded Brand Names",trace="none", key=T, dend="none",main="\n\n\n Heat Map \n\n Perceptual Adj. Avg Ratings")
heatmap.2(as.matrix(c4),col=brewer.pal(7,"Greens"),
          xlab=" Perceptual Adjectives ", ylab= "Coded Brand Names",trace="none", key=T, dend="none",main="\n\n\n Heat Map \n\n Perceptual Adj. Avg Ratings")
# 
heatmap.2(as.matrix(c4),col=brewer.pal(9,"BrBG"),
          xlab=" Perceptual Adjectives ", ylab= "Coded Brand Names",trace="none", key=T, dend="none",main="\n\n\n Heat Map \n\n Perceptual Adj. Avg Ratings")
# 
heatmap.2(as.matrix(avg.ratings),col=brewer.pal(9,"BrBG"),
          xlab=" Perceptual Adjectives ", ylab= "Coded Brand Names",trace="none", key=T, dend="none",main="\n\n\n Heat Map \n\n Perceptual Adj. Avg Ratings")
#
# As the average ratings are mostly in the "0.000" range we need to 
# multiply with "1000" across to get a decent data viz with the HeatMap . 
getwd()
## [1] "C:/Users/Rohit/Documents/GitHub/USE_R/USE_R_Marketing-Mix-Modeling-RCode"
write.table(avg.ratings,"C:/Users/Rohit/Desktop/Marketing Mix - Brands/avg.csv",sep=",")
# Excel calc - external to R - now import avg1.csv 
avg1 <- read.csv("C:/Users/Rohit/Desktop/Marketing Mix - Brands/avg1.csv")
View(avg1)
#
heatmap.2(as.matrix(avg1),col=brewer.pal(9,"BrBG"),
          xlab=" Perceptual Adjectives ", ylab= "Coded Brand Names",trace="none", key=T, dend="none",main="\n\n\n Heat Map \n\n Perceptual Adj. Avg Ratings")
#
heatmap.2(as.matrix(avg1),col=brewer.pal(9, "GnBu"),
          xlab=" Perceptual Adjectives ", ylab= "Coded Brand Names",trace="none", key=T, dend="none",main="\n\n\n Heat Map \n\n Perceptual Adj. Avg Ratings")
#

No comments:

Post a Comment