Data is about PDA 2001
# Cluster Analysis for segmentation: MKTG 580/MKTG 880
# R code by Bharatendra Rai
# Modifed by Suh
# Example Data from MEXL: Decisionpro.biz
## package you need to install "cluster"
# install.packages("cluster")
# library(cluster)
##
#install.packages("cluster")
library(cluster)
## Warning: package 'cluster' was built under R version 4.2.3
#getwd() #identify the current working directory once you open RStudio
#setwd("~/MKTG580-880/Module3") # change the working directory to the folder where the data is saved
#getwd() #confirm the current working directory
segdata <- read.csv("pda2001_original.csv")
str(segdata)
## 'data.frame': 160 obs. of 33 variables:
## $ id : int 1 2 3 4 5 6 7 8 9 10 ...
## $ innovator : int 4 5 3 3 4 5 5 3 6 2 ...
## $ usemessage : int 1 4 5 1 1 3 5 1 5 2 ...
## $ usecell : int 5 7 5 6 6 5 5 5 5 7 ...
## $ usepim : int 7 5 6 7 7 7 6 5 7 5 ...
## $ infpassive : int 4 6 3 5 7 3 6 6 3 4 ...
## $ infactive : int 6 5 4 7 5 7 4 5 7 5 ...
## $ remoteaccess: int 3 6 7 3 5 4 3 4 1 5 ...
## $ shareinf : int 1 5 6 4 5 6 3 3 3 4 ...
## $ monitor : int 4 4 4 4 2 5 4 4 2 6 ...
## $ email : int 5 7 4 4 7 6 6 7 6 4 ...
## $ web : int 5 3 4 7 5 7 5 4 4 6 ...
## $ mmedia : int 6 6 6 5 5 6 7 7 6 5 ...
## $ ergonomic : int 4 1 3 5 4 3 4 1 3 3 ...
## $ monthly : int 15 15 35 15 25 40 20 15 15 25 ...
## $ price : int 280 310 370 390 410 250 310 230 240 290 ...
## $ age : int 48 43 48 28 54 62 53 48 46 59 ...
## $ education : int 3 3 2 3 3 2 3 2 3 2 ...
## $ income : int 47 89 24 52 84 46 71 39 87 21 ...
## $ construction: int 0 0 0 0 0 0 0 0 0 0 ...
## $ emergency : int 0 0 0 0 0 0 0 0 0 0 ...
## $ sales : int 0 0 0 1 0 1 1 1 0 0 ...
## $ service : int 0 1 0 0 0 0 0 0 0 1 ...
## $ professional: int 0 0 0 0 0 0 0 0 1 0 ...
## $ computers : int 0 0 1 0 1 0 0 0 0 0 ...
## $ pda : int 1 0 1 1 1 0 0 0 0 1 ...
## $ cell : int 1 1 1 1 1 1 0 1 1 1 ...
## $ pc : int 1 1 1 1 1 1 1 1 1 1 ...
## $ away : int 3 3 6 7 2 4 6 3 4 6 ...
## $ businessweek: int 0 1 0 0 1 0 0 0 0 0 ...
## $ pcmagazine : int 0 0 0 0 0 0 0 0 0 0 ...
## $ fieldstream : int 0 0 0 0 0 0 0 0 0 0 ...
## $ mgourmet : int 0 0 0 0 0 0 0 0 0 0 ...
head(segdata)
## id innovator usemessage usecell usepim infpassive infactive remoteaccess
## 1 1 4 1 5 7 4 6 3
## 2 2 5 4 7 5 6 5 6
## 3 3 3 5 5 6 3 4 7
## 4 4 3 1 6 7 5 7 3
## 5 5 4 1 6 7 7 5 5
## 6 6 5 3 5 7 3 7 4
## shareinf monitor email web mmedia ergonomic monthly price age education
## 1 1 4 5 5 6 4 15 280 48 3
## 2 5 4 7 3 6 1 15 310 43 3
## 3 6 4 4 4 6 3 35 370 48 2
## 4 4 4 4 7 5 5 15 390 28 3
## 5 5 2 7 5 5 4 25 410 54 3
## 6 6 5 6 7 6 3 40 250 62 2
## income construction emergency sales service professional computers pda cell
## 1 47 0 0 0 0 0 0 1 1
## 2 89 0 0 0 1 0 0 0 1
## 3 24 0 0 0 0 0 1 1 1
## 4 52 0 0 1 0 0 0 1 1
## 5 84 0 0 0 0 0 1 1 1
## 6 46 0 0 1 0 0 0 0 1
## pc away businessweek pcmagazine fieldstream mgourmet
## 1 1 3 0 0 0 0
## 2 1 3 1 0 0 0
## 3 1 6 0 0 0 0
## 4 1 7 0 0 0 0
## 5 1 2 1 0 0 0
## 6 1 4 0 0 0 0
names(segdata)
## [1] "id" "innovator" "usemessage" "usecell" "usepim"
## [6] "infpassive" "infactive" "remoteaccess" "shareinf" "monitor"
## [11] "email" "web" "mmedia" "ergonomic" "monthly"
## [16] "price" "age" "education" "income" "construction"
## [21] "emergency" "sales" "service" "professional" "computers"
## [26] "pda" "cell" "pc" "away" "businessweek"
## [31] "pcmagazine" "fieldstream" "mgourmet"
# column (variable) selection for cluster analysis
segdata1 <- segdata[, 1:16]
names(segdata1)
## [1] "id" "innovator" "usemessage" "usecell" "usepim"
## [6] "infpassive" "infactive" "remoteaccess" "shareinf" "monitor"
## [11] "email" "web" "mmedia" "ergonomic" "monthly"
## [16] "price"
# Normalize
z = segdata1[, -1] # remove ID variable which is not numeric
head(z)
## innovator usemessage usecell usepim infpassive infactive remoteaccess
## 1 4 1 5 7 4 6 3
## 2 5 4 7 5 6 5 6
## 3 3 5 5 6 3 4 7
## 4 3 1 6 7 5 7 3
## 5 4 1 6 7 7 5 5
## 6 5 3 5 7 3 7 4
## shareinf monitor email web mmedia ergonomic monthly price
## 1 1 4 5 5 6 4 15 280
## 2 5 4 7 3 6 1 15 310
## 3 6 4 4 4 6 3 35 370
## 4 4 4 4 7 5 5 15 390
## 5 5 2 7 5 5 4 25 410
## 6 6 5 6 7 6 3 40 250
means = apply(z,2,mean)
means
## innovator usemessage usecell usepim infpassive infactive
## 3.47500 4.20625 5.55625 4.00625 4.45000 4.50000
## remoteaccess shareinf monitor email web mmedia
## 3.98750 3.71250 4.79375 4.72500 4.47500 4.01250
## ergonomic monthly price
## 4.63125 28.75000 332.25000
sds = apply(z,2,sd)
sds
## innovator usemessage usecell usepim infpassive infactive
## 1.605611 1.690137 1.180272 2.035833 1.624498 1.590063
## remoteaccess shareinf monitor email web mmedia
## 1.859829 1.634485 1.496734 1.818666 1.999843 1.974643
## ergonomic monthly price
## 1.592521 9.696657 113.231271
nor = scale(z,center=means,scale=sds) # mean 0 and sd 1
##calculate distance matrix (default is Euclidean distance)
distance = dist(nor)
#distance2 = dist(segdata1[,-1])
#distance
#distance2
# Hierarchical clustering using default complete linkage
segdata.hclust = hclust(distance)
plot(segdata.hclust)
plot(segdata.hclust,labels=segdata$ID,main='Default from hclust')
plot(segdata.hclust,hang=-1)
Based on eyeball checking, I think there are 4 distinct clusters.
# Cluster membership
member = cutree(segdata.hclust,4)
member
## [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1
## [38] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3 3 1
## [75] 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 1 2 1 2 2
## [112] 2 2 1 2 1 2 2 2 1 1 2 2 2 2 2 2 1 2 1 2 1 1 1 1 2 1 2 2 2 1 2 2 2 4 4 4 4
## [149] 4 4 4 4 4 4 4 4 4 4 4 4
table(member)
## member
## 1 2 3 4
## 71 27 46 16
segdata2 <- cbind(segdata, member) #adding member variable into the original segdata
write.csv(segdata2,'pda2001_with_member.csv')
Cluster 1 has 71 respondents (biggest one)
#Characterizing clusters
aggregate(nor,list(member),mean)
## Group.1 innovator usemessage usecell usepim infpassive infactive
## 1 1 0.2217136 -0.3053652 0.1134407 0.73027010 0.1998451 0.3321685
## 2 2 1.0881976 -0.2096860 0.5014929 -0.03945514 -0.3910040 -0.7104305
## 3 3 -0.7020217 0.8040573 -0.1029147 -0.94275599 -0.4375934 -0.4785152
## 4 4 -0.8018753 -0.6027616 -1.0537823 -0.46356953 1.0310878 1.1005850
## remoteaccess shareinf monitor email web mmedia
## 1 -0.2583344 -0.16017020 -0.1727353 0.5848970 0.5371901 0.5357539
## 2 -0.9690758 -0.41325739 -0.5798119 0.5381436 0.6884801 0.7064100
## 3 0.7197367 -0.02360802 0.5590070 -0.8648239 -0.7049467 -0.8760528
## 4 0.7124313 1.47600018 0.1378000 -1.0172289 -1.5188694 -1.0508230
## ergonomic monthly price
## 1 -0.2195009 -0.2560052 -0.2611818
## 2 0.9525135 0.3580845 0.7880463
## 3 -0.4100348 -0.4091504 -0.5382405
## 4 0.5455186 1.7080629 1.3766073
aggregate(segdata1[,-c(1,1)],list(member),mean)
## Group.1 innovator usemessage usecell usepim infpassive infactive
## 1 1 3.830986 3.690141 5.690141 5.492958 4.774648 5.028169
## 2 2 5.222222 3.851852 6.148148 3.925926 3.814815 3.370370
## 3 3 2.347826 5.565217 5.434783 2.086957 3.739130 3.739130
## 4 4 2.187500 3.187500 4.312500 3.062500 6.125000 6.250000
## remoteaccess shareinf monitor email web mmedia ergonomic monthly
## 1 3.507042 3.450704 4.535211 5.788732 5.549296 5.070423 4.281690 26.26761
## 2 2.185185 3.037037 3.925926 5.703704 5.851852 5.407407 6.148148 32.22222
## 3 5.326087 3.673913 5.630435 3.152174 3.065217 2.282609 3.978261 24.78261
## 4 5.312500 6.125000 5.000000 2.875000 1.437500 1.937500 5.500000 45.31250
## price
## 1 302.6761
## 2 421.4815
## 3 271.3043
## 4 488.1250
mean2 = apply(segdata1, 2, mean)
mean2
## id innovator usemessage usecell usepim infpassive
## 80.50000 3.47500 4.20625 5.55625 4.00625 4.45000
## infactive remoteaccess shareinf monitor email web
## 4.50000 3.98750 3.71250 4.79375 4.72500 4.47500
## mmedia ergonomic monthly price
## 4.01250 4.63125 28.75000 332.25000
aggregate(segdata2[,-c(1,1)],list(member),mean)
## Group.1 innovator usemessage usecell usepim infpassive infactive
## 1 1 3.830986 3.690141 5.690141 5.492958 4.774648 5.028169
## 2 2 5.222222 3.851852 6.148148 3.925926 3.814815 3.370370
## 3 3 2.347826 5.565217 5.434783 2.086957 3.739130 3.739130
## 4 4 2.187500 3.187500 4.312500 3.062500 6.125000 6.250000
## remoteaccess shareinf monitor email web mmedia ergonomic monthly
## 1 3.507042 3.450704 4.535211 5.788732 5.549296 5.070423 4.281690 26.26761
## 2 2.185185 3.037037 3.925926 5.703704 5.851852 5.407407 6.148148 32.22222
## 3 5.326087 3.673913 5.630435 3.152174 3.065217 2.282609 3.978261 24.78261
## 4 5.312500 6.125000 5.000000 2.875000 1.437500 1.937500 5.500000 45.31250
## price age education income construction emergency sales
## 1 302.6761 42.16901 2.591549 68.53521 0.05633803 0.01408451 0.4647887
## 2 421.4815 39.03704 3.222222 85.59259 0.03703704 0.03703704 0.1481481
## 3 271.3043 36.47826 2.152174 58.41304 0.06521739 0.02173913 0.2173913
## 4 488.1250 42.18750 1.937500 52.43750 0.31250000 0.18750000 0.0625000
## service professional computers pda cell pc away
## 1 0.1267606 0.1126761 0.2112676 0.5070423 0.9014085 1.0000 4.112676
## 2 0.0000000 0.3703704 0.4074074 0.8888889 0.8888889 1.0000 2.481481
## 3 0.3913043 0.1739130 0.1304348 0.1521739 0.9130435 1.0000 4.956522
## 4 0.1250000 0.0000000 0.3125000 0.1875000 0.6250000 0.8125 5.375000
## businessweek pcmagazine fieldstream mgourmet member
## 1 0.3098592 0.1971831 0.05633803 0.01408451 1
## 2 0.5185185 0.2962963 0.00000000 0.07407407 2
## 3 0.1739130 0.2826087 0.23913043 0.00000000 3
## 4 0.0000000 0.2500000 0.31250000 0.00000000 4
# Scree Plot
wss <- (nrow(nor)-1)*sum(apply(nor,2,var))
for (i in 2:20) wss[i] <- sum(kmeans(nor, centers=i)$withinss)
plot(1:20, wss, type="b", xlab="Number of Clusters", ylab="Within groups sum of squares")
Based on screen plot, 4 (or 3, or 5) cluster solution seems reasonable
I would say, there are 32 distinct segmentations throughout the market #### Assignment Question 2 Within the cluster diagram, there are 4 big clusters that connect them all. #### Assignment Question 3 Through different codes, it gives all the information you need. #### Assignment Question 4 There is a lot of information to take in, so condensing it would be helpful.