Brand Marketing on Facebook using Statistical Analysis | by Rohit Lokwani | Towards Data Science

Tips and tricks to promote brands and gain insights from data
Suppose, some day you think of starting a company. In this age and time, one of the most important things is the reach of your company. If the company is formed on certain products which are used by people in day-to-day life, then it is likely that you already have a lot of competitors in the market. Now, what matters is to beat the heat of the competition. So, the places where your company becomes accessible to people is not only the advertisement hoardings these days. It’s the social media where people keep scrolling through their news feed around three times a day. On average, an American spends 705 hours on social media every year. The chances of failing are negligible, and even if you do fail, you have nothing to lose.
So, let’s assume your company is officially participating in brand marketing on Social Media. You’ve set up a Facebook or Instagram page as the brand that is supposed to be marketed is a cosmetic brand ( Not a big fan of cosmetics but the dataset used is that of a cosmetic brand). You respond to customer questions, follow fans, post important news, and thank your advocates for their support. Beyond that, are you taking enough actions to monitor and analyze the results of your work? If you’re engaging in social media, then you should certainly measure those activities. Is there any better way of knowing it? It’s easier done than said, sounds ironical, huh ?
Social media metrics are data and statistics that give you insights into your social media marketing performance. Some of these metrics are explained in the blog below.
To suffice the purpose of this blog, we’ll segment the metrics into four different categories:
Awareness: These metrics illuminate your current and potential audience.
Engagement: These metrics show how audiences are interacting with your content.
Conversion: These metrics demonstrate the effectiveness of your social engagement.
Consumer: These metrics reflect how active customers think and feel about your brand.
I’ll be covering all the categories in general without going into the specific details for each. So, following are some of the metrics that you need to know to get a better understanding of the whole thing:
Reach: The total number of distinct people or the users the post has reached.
Impressions: The number of times a post was seen by the users. A post reached to n number of people can be seen by them m times individually. So, the total impressions become m*n. The number of times a post is displayed in your news feed, irrespective of the post being clicked. People may see multiple impressions of the same post. For example, someone might see a Page update in News Feed once, and then a second time if their friend shares it.
Total number of page likes: Likes show your audience size on Facebook. Over time, that number should be growing. If you’re stuck with around the same number of likes for months, it means one of two things:  1) You’re losing the same number of Likes as you’re gaining. 2) New people aren’t following you
Engagement: It means the number of times the users have performed an action on the post. Engagement is one of the most important Facebook metrics you can track. Subjectively, engagement is a sign that people actually like the content you’re sharing. But another reason engagement is so valuable is it may give your posts more exposure to your audience. This includes liking, commenting, sharing and people who’ve viewed your video or clicked on your links and photos. And it also includes people who’ve clicked on a commenter’s name, liked a comment, clicked on your Page name and even gave negative feedback by reporting your post.
Consumptions: This metric is similar to Engagement but Consumption does not necessarily produce a story.Consumptions = Link Clicks + Photo Views + Video Plays + Other Clicks (some of which do generate stories)
Total interactions: As we know, the main motive is to increase the number of people viewing the post and to increase the number of interactions (like, comment, share) with the post so that a story is created and it automatically appears to the viewer’s friends in their News Feed. The total interactions are calculated from the actions performed by Lifetime Post Engaged Users (Story is created) and Lifetime Post Consumers (Story not created). Do note these metrics, these will be used later.Total interactions= Likes + Comments + Shares
Type of Posts: There are four types of post on Facebook: Video, Photo, Status, Links. A general human tendency is to look at images, read and share them. Statuses are generally longer and people are reluctant to read it. So, the natural biasing is towards looking and reacting to Videos, Pictures followed by statuses.
Last year (2018), Facebook admitted that it prioritizes video in its algorithm, with extra emphasis on live video. If you can create video content, you have a much better chance of getting to the top of news feeds. So, you’ll see the later visualizations are a little biased towards Video Posts.
Paid Likes: Number of people who have Liked your Page as a result of a Facebook Ad campaign.
The Facebook page analytics provides data and statistics related to these metrics. So, what I have done is I have a dataset with the name Morto et al, which gave the metrics for advertisement of particular cosmetic anonymized brand on Facebook. The dataset has a total of 500 records which has 19 columns with such metric values defined. Now, coming back to next part of this blog is getting started with R programming.
R is a statistical programming language. R possesses an extensive catalog of statistical and graphical methods. It includes machine learning algorithms, linear regression, time series, statistical inferences. There are various packages in R which make it easy to get the tasks in the data science domain done easily. For detailed information theoretically on R, visit https://en.wikipedia.org/wiki/R_(programming_language) and https://www.tutorialspoint.com/r/index.htm to get help for syntax of R programming language.Going to the project wherein I plotted various data visualizations which will help any layman to make decisions as to what actually helps in bringing the advertisement close to the end user.Note: The following observations and data analysis was done by intuition and then some changes were done to get the best results out of it.
Chiefly, The total page likes depend on following Facebook Post metrics:Total ReachTotal ImpressionsType of Post (Photo, Status, Video, Link)WeekdayHour of the day
Chiefly, The total page likes depend on following Facebook Post metrics:Total ReachTotal ImpressionsType of Post (Photo, Status, Video, Link)WeekdayHour of the day
With the help of multiple regression analysis, we get the coefficients for all the above metrics which will help us determine the importance of each metric, which helps in increasing our page likes.
Why Multiple Regression? Multiple regression is an extension of linear regression into relationship between more than two variables. In simple linear relation we have one predictor and one response variable, but in multiple regression we have more than one predictor variable and one response variable.
We create the regression model using the lm() function in R. The model determines the value of the coefficients using the input data. Next we can predict the value of the response variable for a given set of predictor variables using these coefficients.
data<-read.csv("Morto_Et_Al.csv")input<-read.csv(file = "facebook.csv", sep = ",")[ ,c('PTL','LPTReach','LPTImpressions','Type','Weekday','Hour')]model<-lm(PTL~LPTReach+LPTImpressions+Type+Weekday+Hour,data=input)a <- coef(model)[1]XLPTReach <- coef(model)[2]XLPTImpressions <- coef(model)[3]XTypePhoto <- coef(model)[4]XTypeStatus <- coef(model)[5]XTypeVideo <- coef(model)[6]XWeekday <- coef(model)[7]Xhour <- coef(model)[8]
2. Prediction analysis:Here, using the coefficients obtained by multiple regression analysis are used to generate an equation wherein putting the values for the variables the equation predicts the number of likes depending on the type of post.
x1 <- readline("What is the total reach?")x1 <- as.numeric(x1)x2 <- readline("What is the value for total impressions?")x2 <- as.numeric(x2)x6 <- readline("What is weekday?")x6 <- as.numeric(x6)x7 <- readline("Which is the hour of the day?")x7 <- as.numeric(x7)x<-c("Photo","Status","Video")type<-readline("What is the type of post?")if("Photo" %in% type) {Y = a + XLPTReach*x1+XLPTImpressions*x2+XTypePhoto*2.5+XWeekday*x6+Xhour*x7Z = a + XLPTReach*x1+XLPTImpressions*x2+XTypePhoto*3+XWeekday*x6+Xhour*x7} else if ("Status" %in% x) {Y = a + XLPTReach*x1+XLPTImpressions*x2+XTypeStatus*1.4+XWeekday*x6+Xhour*x7Z = a + XLPTReach*x1+XLPTImpressions*x2+XTypeStatus*2+XWeekday*x6+Xhour*x7} else if ("Video" %in% x) {Y = a + XLPTReach*x1+XLPTImpressions*x2+XTypeVideo*4+XWeekday*x6+Xhour*x7Z = a + XLPTReach*x1+XLPTImpressions*x2+XTypeVideo*5+XWeekday*x6+Xhour*x7}
3. Post weekday v/s total reach, Post weekday v/s Total Impressions:Here, I have plotted a line graph to show the relation, how a post weekday affects the total reach and impressions. Results show a post posted on weekday 3 gives the best results for reach, and the same post has the maximum number of impressions the following day. Makes sense, doesn’t it?
day1<- subset(data,Weekday==1)mean1R <- mean(day1$LPTReach)mean1I <- mean(day1$LPTImpressions)day2<- subset(data,Weekday==2)mean2R <- mean(day2$LPTReach)mean2I <- mean(day2$LPTImpressions)day3<- subset(data,Weekday==3)mean3R <- mean(day3$LPTReach)mean3I <- mean(day3$LPTImpressions)day4<- subset(data,Weekday==4)mean4R <- mean(day4$LPTReach)mean4I <- mean(day4$LPTImpressions)day5<- subset(data,Weekday==5)mean5R <- mean(day5$LPTReach)mean5I <- mean(day5$LPTImpressions)day6<- subset(data,Weekday==6)mean6R <- mean(day6$LPTReach)mean6I <- mean(day6$LPTImpressions)day7<- subset(data,Weekday==7)mean7R <- mean(day7$LPTReach)mean7I <- mean(day7$LPTImpressions)v<-c(mean1R,mean2R,mean3R,mean4R,mean5R,mean6R,mean7R)t<-c(mean1I,mean2I,mean3I,mean4I,mean5I,mean6I,mean7I)png(file = “Weekday_TotalReach.png”)plot(v,type = “o”,col = “red”, xlab = “Weekday”, ylab = “Total Reach”,main = “Chart for analysis of total reach”)dev.off()png(file = “Weekday_TotalImpressions.png”)plot(t,type = “o”,col = “blue”, xlab = “Weekday”, ylab = “Total Impressions”,main = “Chart for analysis of total impressions”)dev.off()
4. Type of post v/s Total reach, Type of Post v/s Total ImpressionsHere, a bar chart is used to show the relation between the post type and reach, impressions. It helps in comparing the impact made by each of the post types. The results show that a “video” could be a better option for promoting your brand over other post types.
photodf <- subset(data,Type=="Photo")meanPR <- mean(photodf$LPTReach)meanPI <- mean(photodf$LPTImpressions)#meanPLikesP <- mean(photodf$PTL)statusdf <- subset(data,Type=="Status")meanSR <- mean(statusdf$LPTReach)meanSI <- mean(statusdf$LPTImpressions)#meanPLikesS <- mean(statusdf$PTL)videodf <- subset(data,Type=="Video")meanVR <- mean(videodf$LPTReach)meanVI <- mean(videodf$LPTImpressions)#meanPLikesV <- mean(videodf$PTL)linkdf <- subset(data,Type=="Link")meanLR <- mean(linkdf$LPTReach)meanLI <- mean(linkdf$LPTImpressions)#meanPLikesL <- mean(linkdf$PTL)ValueR <- c(meanPR,meanSR,meanVR,meanLR)ValueI <- c(meanPI,meanSI,meanVI,meanLI)Post <- c("Photo","Status","Video","Link")png(file = "barchart_reach&postType.png")barplot(ValueR,names.arg = Post,xlab = "Post Type",ylab = "Total Reach",col = "blue", main = "Total Reach v/s Post Type",border = "red")dev.off()png(file = "barchart_Impressions&postType.png")barplot(ValueI,names.arg = Post,xlab = "Post Type",ylab = "Total Impressions",col = "red", main = "Total Impressions v/s Post Type",border = "blue")dev.off()
5. Total Interactions v/s Total reach, Total Interactions v/s Total ImpressionsUsing linear regression, a graph is plotted that shows the dependency of total interactions on total reach, impressions which in turn would actually allow many viewers to visit the page.
ReachInt<-data$LPTReachImpressionInt<-data$LPTImpressionsLikesInt<-data$PTLTotalInt<-data$Total.Interactionsrelation <- lm(TotalInt~ReachInt)png(file = "linearregression(ReachvsInteractions.png")plot(ReachInt,TotalInt,col = "blue",main = "Reach v/s Interactions",cex = 1.3,pch = 16,ylab = "Total Interactions",xlab = "Total Reach")dev.off()relation <- lm(TotalInt~ImpressionInt)png(file = "linearregression(ImpressionsvsInteractions.png")plot(ImpressionInt,TotalInt,col = "red",main = "Impressions v/s Interactions",cex = 1.3,pch = 16,ylab = "Total Interactions",xlab = "Total Impressions")dev.off()relation <- lm(LikesInt~TotalInt)png(file = "linearregression(LikesvsInteractions.png")plot(TotalInt,LikesInt,col = "violet",main = "Likes v/s Interactions",cex = 1.3,pch = 16,xlab = "Total Interactions",ylab = "Total Page Likes")dev.off()
6. Paid post v/s Total Reach:When you pay Facebook to promote a post, the total reach of the post is increased. So, in order to determine if a post is paid, we use a decision tree which shows that if the total reach > 10470, the post is a paid post. So, as per the current dataset if you have to make the post reach to around 10,000 people, you need to pay for it and Facebook ends up promoting it.
data1<-read.csv(“facebook.csv”)library(party)png(file = “Paid(FullData).png”)output.tree <- ctree(Paid[1:100] ~ ReachInt[1:100] +                          ReachInt[1:100],data = data1)plot(output.tree)dev.off()
7. How many users who have engaged with the post have already liked the page? I plotted the pie chart to show the distribution. The results show 70% people who engage with the post are the ones who have already liked the page. Now, this statistic helps to spread the post amongst their friends and also provokes them to like the post or maybe the page.
LPEuser1<-data$LPEuserLEngaged1<-data$LEngageddivi.result <- (LPEuser1/LEngaged1)*100LPEuser1mean<-mean(divi.result)LEngaged1mean=100-LPEuser1meanx<-c(LPEuser1mean,LEngaged1mean)piepercent<- round(100*x/sum(x), 1)png(file = “Engaged_users.png”)pie(x,labels=piepercent, main = “Engaged users %”, col = rainbow(length(x)))legend(“topright”, c(“Users already liked the page”,”Others”), cex = 0.8,fill = rainbow(length(x)))dev.off()
8. Engaged Users, Consumptions as a ratio of Impressions:Till now, we have been focusing on the parameters which directly affect the total page likes. Now, the factors which indirectly affect the total page likes i.e. Engaged users, Consumers, Consumptions are taken into consideration. Here, the statistics are plotted on a pie chart, which help in determining the percentage of consumers, engaged users from the total reach and also the consumptions, engaged users from the total impressions for every type of post.
This helps in showing whether a particular post type is suitable for increasing the number of interactions and promoting the post.
LPConsumptions<-photodf$LPConsumptionsLPTimpressions<-photodf$LPTImpressionsLEngaged2<-photodf$LEngageddivi.result<-(LPConsumptions/LPTimpressions)*100divi.result2<-(LEngaged2/LPTimpressions)*100LEngaged2mean<-mean(divi.result)LPConsumptionsmean<-mean(divi.result2)others<-100-(LEngaged2mean + LPConsumptionsmean)x<-c(LEngaged2mean,LPConsumptionsmean,others)piepercent<- round(100*x/sum(x), 1)png(file = "Impressions_Engaged_Consumptions(photo).png")pie(x,labels=piepercent, main = "Engaged Users,Consumptions from total impressions(photo)%", col = rainbow(length(x)))legend("topright", c("Engaged users%","Lifetime Post Consumptions%","Others%"), cex = 0.8,fill = rainbow(length(x)))dev.off()LPConsumptions<-statusdf$LPConsumptionsLPTimpressions<-statusdf$LPTImpressionsLEngaged2<-statusdf$LEngageddivi.result<-(LPConsumptions/LPTimpressions)*100divi.result2<-(LEngaged2/LPTimpressions)*100LEngaged2mean<-mean(divi.result)LPConsumptionsmean<-mean(divi.result2)others<-100-(LEngaged2mean + LPConsumptionsmean)x<-c(LEngaged2mean,LPConsumptionsmean,others)piepercent<- round(100*x/sum(x), 1)png(file = "Impressions_Engaged_Consumptions(status).png")pie(x,labels=piepercent, main = "Engaged Users,Consumptions from total impressions(status)%", col = rainbow(length(x)))legend("topright", c("Engaged users%","Lifetime Post Consumptions%","Others%"), cex = 0.8,fill = rainbow(length(x)))dev.off()LPConsumptions<-videodf$LPConsumptionsLPTimpressions<-videodf$LPTImpressionsLEngaged2<-videodf$LEngageddivi.result<-(LPConsumptions/LPTimpressions)*100divi.result2<-(LEngaged2/LPTimpressions)*100LEngaged2mean<-mean(divi.result)LPConsumptionsmean<-mean(divi.result2)others<-100-(LEngaged2mean + LPConsumptionsmean)x<-c(LEngaged2mean,LPConsumptionsmean,others)piepercent<- round(100*x/sum(x), 1)png(file = "Impressions_Engaged_Consumptions(video).png")pie(x,labels=piepercent, main = "Engaged Users,Consumptions from total impressions(video)%", col = rainbow(length(x)))legend("topright", c("Engaged users%","Lifetime Post Consumptions%","Others%"), cex = 0.8,fill = rainbow(length(x)))dev.off()LPConsumptions<-linkdf$LPConsumptionsLPTimpressions<-linkdf$LPTImpressionsLEngaged2<-linkdf$LEngageddivi.result<-(LPConsumptions/LPTimpressions)*100divi.result2<-(LEngaged2/LPTimpressions)*100LEngaged2mean<-mean(divi.result)LPConsumptionsmean<-mean(divi.result2)others<-100-(LEngaged2mean + LPConsumptionsmean)x<-c(LEngaged2mean,LPConsumptionsmean,others)piepercent<- round(100*x/sum(x), 1)png(file = "Impressions_Engaged_Consumptions(link).png")pie(x,labels=piepercent, main = "Engaged Users,Consumptions from total impressions(link)%", col = rainbow(length(x)))legend("topright", c("Engaged users%","Lifetime Post Consumptions%","Others%"), cex = 0.8,fill = rainbow(length(x)))dev.off()
Thus, above was the statistical data analysis done in R as an amateur to get a Hands-On Experience on a real-world dataset. So, next time you start marketing your brand, do it on Facebook and see it spread like wildfire. Also, do keep check on the metrics, they will help you grade your marketing skills😊