Brand Headline information

Name- Petco

In this assignment I have done SENTIMENT analysis of offical facebook page of Petco.

Profile Description

Petco is a leading specialty retailer that focuses on nurturing the powerful relationship between people and pets.They provide the products, services, advice and experiences that keep pets physically fit and emotionally happy.Petco facebook page has 2,920,064 likes at November 24, 2016

Analysis of most recent posts made by the brand- Counts of likes, comments, shares, and each type of reactions on these posts and profile name of People who liked the posts.

I used getPage to Extract list of posts from a public Facebook page. getPage(page , token, n = n): Extract list of posts from a public Facebook page

# Petco_page_large <- getPage(page = "Petco",token = my_oauth, n= 1000, reactions = T)
# head(Petco_page_large)
#write.csv(Petco_page_large, file="C:/Users/Amit/Desktop/MSDA/MSDA/DA6813/HW/Petco_page_large.csv", row.names= FALSE)
# Petco profile picture
Petco_page_large <- read.csv("C:/Users/Amit/Desktop/MSDA/MSDA/DA6813/HW/Petco_page_large.csv")

likes_freq <- table(Petco_page_large$likes_count,Petco_page_large$type)
l <- c('link','photo','status','video')
barplot(table(factor(Petco_page_large$type, levels = l)) , col = c('coral2', 'darkolivegreen4', 'darkturquoise', 'darkorchid1'), xlab = 'Type of Posts', ylab = 'Number Of Posts')

ggplot(Petco_page_large, aes(x = type, y = likes_count, fill = type )) +  geom_boxplot()  + scale_y_continuous(trans='log2')

par(c(1,4))
## NULL
                                                                                              plot(Petco_page_large$likes_count,Petco_page_large$shares_count, col="blue", main =" Likes count vs shares count")

# Coversion to log scale                                                                          
plot(Petco_page_large$likes_count,Petco_page_large$shares_count,  log = "xy", col="blue",main =" Likes count vs shares count on log scale")
## Warning in xy.coords(x, y, xlabel, ylabel, log): 14 y values <= 0 omitted
## from logarithmic plot

par(mar=c(1,1,1,1))
head(Petco_page_large, n=2)
##                              id likes_count     from_id from_name
## 1 78697430614_10157841828055615          19 78697430614     Petco
## 2 78697430614_10157837130260615          89 78697430614     Petco
##                                                                             message
## 1                                                        Cyber savings start today!
## 2 Need tips to find the right litter for your cat? We've got what you need to know.
##               created_time type                  link story comments_count
## 1 2016-11-27T16:00:12+0000 link http://bit.ly/2gjdfcO  <NA>              6
## 2 2016-11-26T16:00:11+0000 link http://bit.ly/2f0rkyz  <NA>              4
##   shares_count love_count haha_count wow_count sad_count angry_count
## 1            7          0          0         0         0           0
## 2            7          3          0         0         0           0
# Post with maximum likes count

Petco_page_large[which.max(Petco_page_large$likes_count), ]
##                                id likes_count     from_id from_name
## 978 78697430614_10155061670070615       52349 78697430614     Petco
##                                                                                                                                                     message
## 978 Fruit coma.\n\nImagine a blend of real fruit and veggies in your dog's dry food. Save now with this coupon: http://bit.ly/DogFoodSavings (Photo: Nixon)
##                 created_time  type
## 978 2015-01-04T16:01:26+0000 photo
##                                                                                                  link
## 978 https://www.facebook.com/Petco/photos/a.173370210614.235540.78697430614/10155061670035615/?type=3
##                                             story comments_count
## 978 Petco with Becky Hickey Plummer and 3 others.           1017
##     shares_count love_count haha_count wow_count sad_count angry_count
## 978         3285          0          0         0         0           0
# __Image in the post with maximum likes__
img1 <-  rasterGrob(as.raster(readPNG("C:/Users/Amit/Desktop/MSDA/MSDA/DA6813/HW/Petco_likes.png")), interpolate = FALSE)
#img1
grid.arrange(img1,ncol = 1)

# Total Counts of likes, comments, shares, and each type of reactions on these posts
Petco_count <- colSums(Petco_page_large[ ,c(2,10:16)], na.rm=T)
Petco_count
##    likes_count comments_count   shares_count     love_count     haha_count 
##        1915833          51094         267770          48007           5027 
##      wow_count      sad_count    angry_count 
##           3030          26487           9116
# Average Counts of likes, comments, shares, and each type of reactions on these posts
Petco_means <- colMeans(Petco_page_large[ ,c(2,10:16)], na.rm =T)
round(Petco_means)
##    likes_count comments_count   shares_count     love_count     haha_count 
##           1916             51            268             48              5 
##      wow_count      sad_count    angry_count 
##              3             26              9
par(mar=c(6,6,4,4))

barplot(Petco_means, col= "orange", main=" Average Counts of likes, comments, shares, and each type of reactions on posts (n=1000)", xlab="Emotion",  
   ylab="Average Count", border="blue",  log = "y")

We get a data frame from get page. The most popular post from last 1000 post (starting from January 04, 2015) received almost 52,353 likes and 1,017 comments, and was shared over 3,286 times

In last 1000 posts, total likes count is 1,925,989, comment count is 51,124 and shares count is 268,473. Average like count per post is 1,926, comment count is 51 and shares count is 268. Analysis of 1,000 post reveals that median number of likes per post is around 450. As expected, the message which didn’t receive much response were status messages like stored will be closed, lost dog alert and Free delivery on your first order over $10!.

Key observations from graphs

  1. More than 90% posts have photo and links
  2. Likes count are high for post with photo followed by post with a link. It is interesting to note that even video have less likes count compared to photo and links. Post with only status have e lowest likes count as compared with post with links, status and video.
  3. Average love count is around 50, sad count is around 25, whereas average angry, haha and wow count is less than 10.
  4. Average likes count is 1916 mainly due to some posts that that very large number of likes. Median count of likes is around 500.
  5. As observed on log scale, there is a strong correlation between likes and counts.

For further analysis, I sorted the page (with recent post on top) and saved the file so that I don’t have to download the data every time I run the program.

The code below illustrates how to aggregate the metrics by month in order to compute the mean count of likes/comments/shares per post: for example, in ………. the average post received around …….. likes.

Petco2016_2015 <- read.csv("C:/Users/Amit/Desktop/MSDA/MSDA/DA6813/HW/Petco_page_large.csv")
head(Petco2016_2015)
##                              id likes_count     from_id from_name
## 1 78697430614_10157841828055615          19 78697430614     Petco
## 2 78697430614_10157837130260615          89 78697430614     Petco
## 3 78697430614_10157833283195615         161 78697430614     Petco
## 4 78697430614_10157832772335615         957 78697430614     Petco
## 5 78697430614_10157829002205615          94 78697430614     Petco
## 6 78697430614_10157828443135615         907 78697430614     Petco
##                                                                                                                                                                                                                      message
## 1                                                                                                                                                                                                 Cyber savings start today!
## 2                                                                                                                                          Need tips to find the right litter for your cat? We've got what you need to know.
## 3                                                                                                                                                                                   Going shopping? Need ideas? Here you go:
## 4 Stop by a Petco store near you & score a FREE gift with purchase! Plus save up to 50% on Holiday dog & cat toys, apparel, treats and scratchers. Happy shopping!\n\nBlack Friday Deals: http://bit.ly/PetcoBlackFriday2016
## 5                                                                                                                                                                          Ready. Set. Shop! Black Friday starts online NOW!
## 6                         If you<U+0092>ve ever bonded with a pet, you know that love changes everything. For that alone, we are so thankful. Happy Thanksgiving!\n\nWe'd love to see a photo of your pet. Share one with us below!
##               created_time  type
## 1 2016-11-27T16:00:12+0000  link
## 2 2016-11-26T16:00:11+0000  link
## 3 2016-11-25T18:00:17+0000  link
## 4 2016-11-25T16:00:18+0000 photo
## 5 2016-11-24T18:00:15+0000  link
## 6 2016-11-24T16:00:14+0000 photo
##                                                                                                link
## 1                                                                             http://bit.ly/2gjdfcO
## 2                                                                             http://bit.ly/2f0rkyz
## 3                                                                             http://bit.ly/2gDxPbE
## 4 https://www.facebook.com/Petco/photos/a.173370210614.235540.78697430614/10157832772335615/?type=3
## 5                                                                             http://bit.ly/2fZZnne
## 6 https://www.facebook.com/Petco/photos/a.173370210614.235540.78697430614/10157828443135615/?type=3
##   story comments_count shares_count love_count haha_count wow_count
## 1  <NA>              6            7          0          0         0
## 2  <NA>              4            7          3          0         0
## 3  <NA>              9           15         16          0         0
## 4  <NA>             63           54         92         59         0
## 5  <NA>             22           15          5          0         0
## 6  <NA>            551           40        154          0         0
##   sad_count angry_count
## 1         0           0
## 2         0           0
## 3         0           0
## 4         0           0
## 5         2           1
## 6         0           0
## convert Facebook date format to R date format
format.facebook.date <- function(datestring) {
    date <- as.POSIXct(datestring, format = "%Y-%m-%dT%H:%M:%S+0000", tz = "GMT")
}
## aggregate metric counts over month
aggregate.metric <- function(metric) {
    m <- aggregate(Petco2016_2015[[paste0(metric, "_count")]], list(month = Petco2016_2015$month), 
        mean)
    m$month <- as.Date(paste0(m$month, "-15"))
    m$metric <- metric
    return(m)
}
# create data frame with average metric counts per month
Petco2016_2015$datetime <- format.facebook.date(Petco2016_2015$created_time)
Petco2016_2015$month <- format(Petco2016_2015$datetime, "%Y-%m")
df.list <- lapply(c("likes", "comments", "shares"), aggregate.metric)
df <- do.call(rbind, df.list)
# visualize evolution in metric
library(ggplot2)
library(scales)

ggplot(df, aes(x = month, y = x, group = metric)) + geom_line(aes(color = metric))+ theme_bw() + theme(axis.title.x = element_blank()) + ggtitle(" Petco Facebook Page Performance") +scale_y_log10("Average count per post", breaks =c(10, 100,250,500, 1000,2000,4000))

ggsave(file="C:/Users/Amit/Desktop/MSDA/MSDA/DA6813/HW/Petco2016_2015.png",dpi=100)

write.csv(Petco2016_2015, file="C:/Users/Amit/Desktop/MSDA/MSDA/DA6813/HW/Petco2016_2015.csv", row.names= FALSE)
View(Petco2016_2015)

The most popular post in past 1000 post received almost 52,353 likes and 1017 comments, and was shared over 3286 times. We also observe that average number of likes were lower is 2016 as compared to 2015. This may be due to less post with very high likes in 2016 as compared to 2015. Also the trend indicates lower likes in second half of the year in both 2016 and 2015 # Trend analysis for the year 2016

First, I converted posts into a matrix so that it becomes easy to access the comments based on their position, and initialize the data frame allcomments as null. Traverse post by post and append all the comments of the posts to the data frame all comments. Using the for loop, I created a post number for each comment

#post_id<- head(page2016$id, n = 45)
#head(post_id, n=10)
#post_id<- as.matrix(post_id)
#allcomments<- data.frame(Doubles=double(),Ints=integer(),Factors=factor(),Logicals=logical(),Characters=character(),stringsAsFactors=FALSE)

#likes_names<- data.frame(Doubles=double(),Ints=integer(),Factors=factor(),Logicals=logical(),Characters=character(),stringsAsFactors= TRUE)

# Collecting all the commments from all the 45 posts
#for (i in 1:nrow(post_id)) 
# {
# Get upto 50 comments for each post
#post<- getPost(post_id[i,], token= my_oauth, n = 50,
#likes = TRUE, comments = TRUE)
#post
#write.csv(post, file="C:/Users/Amit/Desktop/MSDA/MSDA/DA6813/HW/post.csv", row.names= FALSE)
#post <- read.csv("C:/Users/Amit/Desktop/MSDA/MSDA/DA6813/HW/post.csv")
#comments<- post$comments
#names <- post$likes
#postnumber =i
#postcomments <- cbind(comments,postnumber)
# Append the comments to a single data frame
#allcomments<- rbind(allcomments, postcomments)
#likes_names <- rbind(likes_names, names)
# }

#View(allcomments)
#View(likes_names)

#write.csv(allcomments, file="C:/Users/Amit/Desktop/MSDA/MSDA/DA6813/HW/allcomments.csv", row.names= FALSE)
#write.csv(allcomments, file="C:/Users/Amit/Desktop/MSDA/MSDA/DA6813/HW/likes_names.csv", row.names= FALSE)

I extracted 45 posts from post matrix. Likes_names is a dataframe with 2224 observation of 2 variable. Similarly, comments is a data. Frame with 980 observations of 8 variables. I have added one variable of post number. This variable is required to do post wise analysis of comments.

Identify the users that comment the most often

allcomments <- read.csv("C:/Users/Amit/Desktop/MSDA/MSDA/DA6813/HW/allcomments.csv")
head(allcomments)
##        from_id                 from_name
## 1 1.190644e+15      Christy Boren-Huizar
## 2 1.020237e+16          Jennifer Cartier
## 3 1.010341e+16             Chelsea Dolan
## 4 1.021127e+16            Karina Burgess
## 5 1.015553e+16          Brandon Esparsen
## 6 1.020952e+16 Jackie Mosqueda-Contreras
##                                                                                                                                                                                                       message
## 1                                                                                                                                                              Will the stores honor the cyber Monday prices?
## 2                                                                                                                                                                  When are you doing pets with santa clause?
## 3                          Aloha!  Trying to get ahold of grooming Dept.  When I call store number 334-1012 it gives a weird message about line not In service? Is there another number I can try? Thank you!
## 4 I was trying to buy a cat tower and thinking prices would be better on cyber Monday but it is actually the same, now I found it in another site $20 cheaper from the "sale" price you are advertising today
## 5                                                  I've looked at the prices and they're the same exact price for aquatics . Not one single deal. You can't just say 40-60 %off like your site normally does.
## 6                                                                                                                                                                                          Victoria Contreras
##               created_time likes_count comments_count
## 1 2016-11-27T16:51:49+0000           1              3
## 2 2016-11-27T16:35:04+0000           0              2
## 3 2016-11-27T19:29:37+0000           0              1
## 4 2016-11-27T17:48:33+0000           0              0
## 5 2016-11-27T17:27:26+0000           1              0
## 6 2016-11-27T17:48:59+0000           0              0
##                                    id postnumber
## 1 10157841828055615_10157842097655615          1
## 2 10157841828055615_10157841986445615          1
## 3 10157841828055615_10157842630635615          1
## 4 10157841828055615_10157842327405615          1
## 5 10157841828055615_10157842256910615          1
## 6 10157841828055615_10157842329000615          1
likes_names <- read.csv("C:/Users/Amit/Desktop/MSDA/MSDA/DA6813/HW/likes_names.csv")
head(likes_names)
##        from_id                 from_name
## 1 1.190644e+15      Christy Boren-Huizar
## 2 1.020237e+16          Jennifer Cartier
## 3 1.010341e+16             Chelsea Dolan
## 4 1.021127e+16            Karina Burgess
## 5 1.015553e+16          Brandon Esparsen
## 6 1.020952e+16 Jackie Mosqueda-Contreras
##                                                                                                                                                                                                       message
## 1                                                                                                                                                              Will the stores honor the cyber Monday prices?
## 2                                                                                                                                                                  When are you doing pets with santa clause?
## 3                          Aloha!  Trying to get ahold of grooming Dept.  When I call store number 334-1012 it gives a weird message about line not In service? Is there another number I can try? Thank you!
## 4 I was trying to buy a cat tower and thinking prices would be better on cyber Monday but it is actually the same, now I found it in another site $20 cheaper from the "sale" price you are advertising today
## 5                                                  I've looked at the prices and they're the same exact price for aquatics . Not one single deal. You can't just say 40-60 %off like your site normally does.
## 6                                                                                                                                                                                          Victoria Contreras
##               created_time likes_count comments_count
## 1 2016-11-27T16:51:49+0000           1              3
## 2 2016-11-27T16:35:04+0000           0              2
## 3 2016-11-27T19:29:37+0000           0              1
## 4 2016-11-27T17:48:33+0000           0              0
## 5 2016-11-27T17:27:26+0000           1              0
## 6 2016-11-27T17:48:59+0000           0              0
##                                    id postnumber
## 1 10157841828055615_10157842097655615          1
## 2 10157841828055615_10157841986445615          1
## 3 10157841828055615_10157842630635615          1
## 4 10157841828055615_10157842327405615          1
## 5 10157841828055615_10157842256910615          1
## 6 10157841828055615_10157842329000615          1
library(sqldf)
commenters <- sqldf("select from_name, COUNT(from_name) as Frequency from allcomments group by from_name")
write.csv(commenters, file="C:/Users/Amit/Desktop/MSDA/MSDA/DA6813/HW/commenters.csv", row.names= FALSE)
commenters <- read.csv("C:/Users/Amit/Desktop/MSDA/MSDA/DA6813/HW/commenters.csv")
# head(commenters)

topcommenters <- sqldf("select from_name, frequency from commenters group by from_name order by frequency desc ")

write.csv(topcommenters, file="C:/Users/Amit/Desktop/MSDA/MSDA/DA6813/HW/topcommenters.csv", row.names= FALSE)
commenters <- read.csv("C:/Users/Amit/Desktop/MSDA/MSDA/DA6813/HW/topcommenters.csv")

head(topcommenters, n=10)
##          from_name Frequency
## 1       Betty Puhr        13
## 2   Virginia Green        10
## 3       Marla Hill         9
## 4     Cerrie Bader         6
## 5    Deanna Shanks         5
## 6      Sumy Guzman         5
## 7    Connie Milton         4
## 8   Heather Napper         4
## 9      Lilly Karak         4
## 10 Michelle Mathis         4
# Consolidating the like for each user.
influentialusers<- sqldf("select from_name, sum(likes_count) as
totlikes from allcomments group by from_name")

influentialusers$totlikes<- as.numeric(influentialusers$totlikes)
top<- influentialusers[order(- influentialusers$totlikes),]
head(top, n=10)
##              from_name totlikes
## 56        Angie Benner       44
## 751      T.j. Mangrich       39
## 170 Christina Eversole       30
## 156    Chasen Brookman       28
## 597      Michelle Ryan       28
## 802       Vicki Wilson       28
## 208      Darrell Estus       26
## 727 Sherry-Richie Word       26
## 413       Karen Juarez       21
## 183        Cindy Tyler       19

The above code gives top commenters and most influential person (based on total number of likes for his/her comments). We observe that in last 45 post top three commenters are Betty, Virginia and Marla. It is interesting to observe that none of the first top commenters are in top ten influential people. (based on number of likes).
Getting to know the top commenters and most influential person is a very useful task, that is very helpful for executing marketing campaigns and making them successful. Based on the sentiment analysis below, we observe that some top commenters have positive sentiment and some don’t.

Sentiment analysis

Word Cloud

library(stringr)
library(tm)
allcomments$message <- sapply(allcomments$message,function(row) iconv(row, "latin1", "ASCII", sub=""))
#head(allcomments$message)
#str(allcomments$message)
#clean the corpus
myCorpus <- Corpus(VectorSource(allcomments$message),readerControl=list(language="en"))
# convert to lower case
myCorpus <- tm_map(myCorpus, content_transformer(tolower))
# remove punctuation
myCorpus <- tm_map(myCorpus, removePunctuation) 
# remove numbers
myCorpus <- tm_map(myCorpus, removeNumbers)
# remove stopwords from corpus
stop_words1 <- stopwords("SMART")
stop_words2<-stopwords("en")
stop_words <-c(stop_words1, stop_words2)
myCorpus <- tm_map(myCorpus, removeWords, stop_words)
# Strip white spaces
myCorpus <- tm_map(myCorpus, stripWhitespace)
#plain text 
myCorpus<-tm_map(myCorpus, PlainTextDocument)
#Do stem
myCorpus<-tm_map(myCorpus,stemDocument)
# remove words
# myCorpus <- tm_map(myCorpus, removeWords, c("Petco"))
par(mfrow=c(1,1))
# Get a wordcloud
wordcloud(myCorpus, scale=c(5,0.5), sin.freq=3, max.words=Inf,
          random.order=FALSE, rot.per=0.35,
          use.r.layout=FALSE, colors=brewer.pal(8,"Dark2"))

Word cloud captures the expected words such as Petco, dog, cat and some positive word such as Love, good, happi, cute and lol etc and many neutral words such as sale, food, home, veteran, today etc.

Post-wise sentiment analysis

This is a technique for evaluating the overall positivity, negativity, or neutrality of a body of text. Positive words receive positive integers as a score, whereas negative words are represented by negative integers. The overall score for a body of text is the average of those numbers. To explore further I did the sentiment analysis using sentiment and syuzet package I used sqldf to group by post and then find out correlation between Facebook reactions and post wise comments.

The above code gives the sentiment of each 45 post (875 comments). The mean sentiment score is 0.12 (i.e slightly above zero). In top 45 posts, we can also see that 11 posts (i.e. post number 5,8,11,12,13,16,18,23,29,40 and 45) have negative sentiment.

Analysis of top three post with high sentiment score

Post 37 which is “This iconic scene from Lady and the Tramp is just too cute! Congrats to @rocket_the_dachshund, our 2nd place winner! They win $3,000!” has highest sentiment score. Post 36 which is Beware of the big bad wolf! Congrats to @run.love.dog, the 4th place winner of our Halloween Contest. They win a $500 prize! has second highest sentiment score.

Post 33 which is Thank you to all who entered our Halloween Contest on Instagram this year! We had over 1,700 photos to enjoy. Check out these amazing entries. This post has third highest sentiment score. Post with interesting pictures and with words like congrats, woe, prize have high positive reactions and sentiment score.

Based on the above analysis, we can conclude that sentiment score does partly correlate with the sentiment that we observe in the reactions on the posts. For example, post 8 which has highest negative sentiment has very less like, shares and love count but has no angry or sad count. Similarly, post 33 with sentiment score of 0.29 and have only 44 love count and 319 likes count as compared to post 36 with sentiment score of 0.33 and has 2034 love count and 319 likes count.

Though the correlation between reactions (love, haha, wow, sad) and post sentiment is positive, it is not very strong in magnitude. However, as mean sentiment score was positive, correlation between Angry count and Post sentiment is negative. (-0.42)

Though the correlation between reactions (love, haha, wow, sad) and post sentiment is positive, it is not very strong in magnitude. However, as mean sentiment score was positive, correlation between Angry count and Post sentiment is negative. (-0.42)

Sentiment analysis using syuzhet package

I used Syuzhet package for analysis. Syuzet supports the use of different Sentiment Analysis lexicons. The NRC method, for example, evaluates a body of text and returns positive values for eight different emotions (anger, anticipation, disgust, fear, joy, sadness, surprise, and trust), and two sentiments (negative and positive). I computed these scores with the get_nrc_sentiment () function.

#library(syuzhet)
#get_nrc_sentiment
Petco_post_sentiment<-cbind(allcomments, get_nrc_sentiment(iconv(allcomments$message, to= "ASCII")))
#View(Petco_post_sentiment)

Petco_post_sentiment <- sqldf("select anger, anticipation, fear,joy,sadness,surprise,trust,positive,negative from Petco_post_sentiment group by postnumber")
#round(Petco_post_sentiment,3)

Petco_post45 <-head(page2016,n=45)

Petco_post_reactions<- Petco_post45[ ,c(2,11:16)]
Petco_post_reactions
##    likes_count shares_count love_count haha_count wow_count sad_count
## 1           19            7          0          0         0         0
## 2           89            7          3          0         0         0
## 3          161           15         16          0         0         0
## 4          957           54         92         59         0         0
## 5           94           15          5          0         0         2
## 6          907           40        154          0         0         0
## 7           67            6          1          1         0         0
## 8           93            8          6          0         0         0
## 9          112           13          3          0         1         0
## 10         379           15         68          0         0         3
## 11         292           41         19          1         0         0
## 12         507          106         45          0         4         0
## 13         666           54         48          1         1         0
## 14         116           22          7          0         0         0
## 15        1259          141        179         42         1         0
## 16          72            8          3          0         0         0
## 17        2141          502        236        268         3         1
## 18         551          112        116          0         0         8
## 19         464           31         41         11         0         0
## 20       13425         1441       1892          6        27        14
## 21          97           10          4          0         1         0
## 22        1541          181        151          0         0         4
## 23         168           32         15          0         3         1
## 24         751           45         66         18         1         0
## 25         545          108         67          0         1         1
## 26         625           95         85          0         7         0
## 27        1144           48         99         11         0         0
## 28         262           43         26          0         0         9
## 29         754           53        100         47         3         0
## 30         173           36         26          0         1         0
## 31         102           18          9          0         1         0
## 32         717           73         88         11         1         0
## 33         319           23         44          3         1         0
## 34         565           38         54         28         3         0
## 35         421           11         29         11         3         0
## 36        2034          132        428         69         8         0
## 37         867           57        105         45         5         0
## 38         713           59        111         14         4         0
## 39         908           20        102         38         1         0
## 40         603           50         43         55         4         0
## 41         844          101         79         69         3         1
## 42         950           21        113          2         2         0
## 43         388           36         36         17         3         0
## 44        2314           84        294         13         1         0
## 45         135           26          5          0         0         1
##    angry_count
## 1            0
## 2            0
## 3            0
## 4            0
## 5            1
## 6            0
## 7            0
## 8            0
## 9            1
## 10           0
## 11           2
## 12           1
## 13           0
## 14           0
## 15           0
## 16           2
## 17           1
## 18           1
## 19           0
## 20           0
## 21           0
## 22           1
## 23           1
## 24           0
## 25           0
## 26           0
## 27           0
## 28           0
## 29           0
## 30           0
## 31           0
## 32           0
## 33           0
## 34           0
## 35           0
## 36           0
## 37           0
## 38           0
## 39           0
## 40           0
## 41           0
## 42           0
## 43           0
## 44           0
## 45           0
par(mfrow=c(1,1))
Petco_reactions_sentiment<- cbind(Petco_post_reactions,Petco_post_sentiment)
View(Petco_reactions_sentiment)
Posts_corr_syuzet <- cor(Petco_reactions_sentiment)
round(Posts_corr_syuzet,2)
##              likes_count shares_count love_count haha_count wow_count
## likes_count         1.00         0.96       0.99       0.12      0.90
## shares_count        0.96         1.00       0.95       0.26      0.88
## love_count          0.99         0.95       1.00       0.10      0.91
## haha_count          0.12         0.26       0.10       1.00      0.11
## wow_count           0.90         0.88       0.91       0.11      1.00
## sad_count           0.69         0.71       0.69      -0.08      0.57
## angry_count        -0.09         0.01      -0.10       0.06     -0.12
## anger              -0.08        -0.07      -0.08      -0.09     -0.10
## anticipation       -0.07        -0.06      -0.07      -0.10     -0.08
## fear               -0.07        -0.07      -0.06      -0.09     -0.11
## joy                -0.07        -0.05      -0.06      -0.08     -0.07
## sadness            -0.07        -0.06      -0.07      -0.08     -0.09
## surprise           -0.06        -0.04      -0.06      -0.08     -0.03
## trust              -0.07        -0.06      -0.06      -0.10     -0.08
## positive           -0.08        -0.07      -0.08      -0.10     -0.09
## negative           -0.12        -0.10      -0.12      -0.13     -0.14
##              sad_count angry_count anger anticipation  fear   joy sadness
## likes_count       0.69       -0.09 -0.08        -0.07 -0.07 -0.07   -0.07
## shares_count      0.71        0.01 -0.07        -0.06 -0.07 -0.05   -0.06
## love_count        0.69       -0.10 -0.08        -0.07 -0.06 -0.06   -0.07
## haha_count       -0.08        0.06 -0.09        -0.10 -0.09 -0.08   -0.08
## wow_count         0.57       -0.12 -0.10        -0.08 -0.11 -0.07   -0.09
## sad_count         1.00        0.08 -0.03        -0.08 -0.08 -0.07   -0.04
## angry_count       0.08        1.00  0.03        -0.06  0.04 -0.09   -0.03
## anger            -0.03        0.03  1.00         0.86  0.84  0.88    0.96
## anticipation     -0.08       -0.06  0.86         1.00  0.95  0.97    0.95
## fear             -0.08        0.04  0.84         0.95  1.00  0.95    0.92
## joy              -0.07       -0.09  0.88         0.97  0.95  1.00    0.97
## sadness          -0.04       -0.03  0.96         0.95  0.92  0.97    1.00
## surprise         -0.07       -0.09  0.86         0.96  0.91  0.98    0.95
## trust            -0.09       -0.11  0.86         0.98  0.94  0.98    0.95
## positive         -0.09       -0.11  0.89         0.98  0.93  0.99    0.97
## negative         -0.09        0.04  0.88         0.88  0.86  0.91    0.93
##              surprise trust positive negative
## likes_count     -0.06 -0.07    -0.08    -0.12
## shares_count    -0.04 -0.06    -0.07    -0.10
## love_count      -0.06 -0.06    -0.08    -0.12
## haha_count      -0.08 -0.10    -0.10    -0.13
## wow_count       -0.03 -0.08    -0.09    -0.14
## sad_count       -0.07 -0.09    -0.09    -0.09
## angry_count     -0.09 -0.11    -0.11     0.04
## anger            0.86  0.86     0.89     0.88
## anticipation     0.96  0.98     0.98     0.88
## fear             0.91  0.94     0.93     0.86
## joy              0.98  0.98     0.99     0.91
## sadness          0.95  0.95     0.97     0.93
## surprise         1.00  0.97     0.96     0.89
## trust            0.97  1.00     0.98     0.88
## positive         0.96  0.98     1.00     0.91
## negative         0.89  0.88     0.91     1.00
corrplot(Posts_corr_syuzet,method="number")

We get the correlation between Facebook reactions and eight different emotions (anger, anticipation, disgust, fear, joy, sadness, surprise, and trust), and two sentiments (negative and positive) of syuzet package.

# Before NormaliZation 
get_dct_petco <- get_sentences(allcomments$message)
s_v_sentiment <- get_sentiment(get_dct_petco)
plot(s_v_sentiment, type="l", main=" Plot Trajectory", xlab = " Time", ylab= "Emotional Valence(+ve or -Ve)",col= "orange")

#get_dct_transform**
get_dct_transform_petco<-get_dct_transform(allcomments$likes_count, low_pass_size = 5, x_reverse_len = 100, scale_vals = FALSE, scale_range = FALSE)
get_dct_transform_petco
##   [1] 32.53972 32.40758 32.14524 31.75656 31.24728 30.62487 29.89850
##   [8] 29.07885 28.17796 27.20907 26.18639 25.12493 24.04021 22.94812
##  [15] 21.86461 20.80547 19.78612 18.82137 17.92519 17.11050 16.38901
##  [22] 15.77103 15.26531 14.87894 14.61723 14.48362 14.47969 14.60509
##  [29] 14.85755 15.23295 15.72539 16.32723 17.02926 17.82084 18.69002
##  [36] 19.62376 20.60811 21.62843 22.66958 23.71619 24.75285 25.76433
##  [43] 26.73582 27.65317 28.50302 29.27306 29.95215 30.53052 30.99985
##  [50] 31.35343 31.58619 31.69482 31.67772 31.53510 31.26886 30.88262
##  [57] 30.38161 29.77256 29.06360 28.26414 27.38467 26.43659 25.43208
##  [64] 24.38384 23.30492 22.20852 21.10778 20.01558 18.94435 17.90588
##  [71] 16.91118 15.97027 15.09209 14.28438 13.55353 12.90459 12.34116
##  [78] 11.86535 11.47786 11.17790 10.96333 10.83065 10.77516 10.79100
##  [85] 10.87135 11.00853 11.19414 11.41928 11.67469 11.95093 12.23857
##  [92] 12.52836 12.81140 13.07930 13.32439 13.53976 13.71948 13.85867
##  [99] 13.95358 14.00168
ft_values <- get_transformed_values(get_dct_transform_petco, low_pass_size = 3, x_reverse_len = 100,padding_factor = 2,scale_vals = TRUE,scale_range = FALSE)

plot(ft_values, type ="l", main =" Portrait using Transformed Values", xlab = "Narrative Time",ylab = "Emotional Valence", col = "orange")

We can also see from emotional Valence (plot trajectory) that average sentiment is only marginally positive

Based on syuzet package observations, i found a very weak and correlation between facebook reactions and syuzet package emotions. For example correlation between Angry count and anger is - 0.03 because many comments are not related with posts and are general feeback

Recommendation based on the analysis of Petco’s Facebook page:

Based on syuzet package observations, i found a very weak and correlation between Facebook reactions and syuzet package emotions. For example, correlation between Angry count and anger is - 0.03 Reason is that many comments are not related with posts and are general feedback:

Recommendation based on the analysis of Petco’s Facebook page:

  1. Identifying sentiment for last two years- Average number of likes have decreased in last two years and hence it is critical to know movement of average sentiment in last two years. Based on sentiment analysis of recent 45 posts, we observed that 25% post (11 posts (i.e post number 5,8,11,12,13,16,18,23,29,40 and 45) out of 45) have negative sentiment. Since, Sentiment score does partly correlate with the sentiment that we observe in the reactions on the posts. Petco should devise a strategy to reduce this negative sentiment number.

  2. Selection of type of post- As Post with interesting pictures and links have high positive reactions and high sentiment score as compared to post with status and videos, Petco should have expert person to recommend which pictures and link should be posted

  3. Focus of quality of post content-We observe that one interesting post with picture may attract lot of eyeballs and can change the sentiment of comments of that post. As we saw in 2015, Post dated January 04, 2015 had more than 50,000 likes (as compared to median likes of 500). It may be noted that Post with interesting pictures and with words like congrats, woe, prize have high positive reactions and sentiment score.

  4. Quick customer query/dispute resolution- We observe that first negative comment may trigger series of negative comment. For Example, In post 14 one negative comment also trigger other negative comments of the same post. This post 14 is on Travel smoothly, safely and comfortably with your dog this holiday season. It has no sad or angry Facebook reactions yet score high in sadness and surprise count,because many comments are not related with posts and are general feedback. All these comments were on same post within a period of 4 days, so a quick customer response by Petco may have reduced further comments.

  5. Private message box on Facebook page for customer complaints. This will help customers not being misguided by a disgruntled customer. For example, Facebook comments may be analyzed to figure out which stores need more improvement in quality. For example, customers have complained about Bensalem, PA Store, Lake Street in Peoria, Illinois and one store in Nj. Customer feedback should be viewed as an opportunity for change. As a rule, the expression of empathy to the customer should come right after the apology. Also, it may be kept in mind that not all customers can be pleased. Some people are just complainers and nothing will change that. But everything we can correct about this situation will help with future events. Keep improving in areas over which you have control.

  6. Leverage Social Media and have Focused Strategy for online marketing- Petco Facebook page has more than 2,920,064 likes. Petco should leverage this for all social media campaigns. It may be noted that Petco twitter page has 179,000 followers and has 8,986 likes. We also observe that average number of likes were lower is 2016 as compared to 2015. This may be due to less post with very high likes in 2016 as compared to 2015. Also, the trend indicates lower likes in second half of the year in both 2016 and 2015. We may do a granular analysis to know if this has an impact on company’s topline and bottom-line.