Analyzing Facebook Networks using #rstats

Analyzing Facebook Networks using #rstats is given below. Note this can be replicated by anyone- and you can theoretically be able to create adjacency matrix (friend of friends) of all people who have given permission into your app- thus maybe a network analysis of people to some group (like R Facebook group https://www.facebook.com/groups/rusers/?fref=ts or even FOASStat https://www.facebook.com/groups/foastat/?fref=ts is possible

While traditional marketing and targeting focusses on variables like demographics and psychographics, social network analysis lets you tap into influential people within communities with the right offer and then let the free retweet, reshare as proxy free ads. The hypothesis being that people in similar network clusters have similar consumer behaviours (not just in similar demographic or psychographics). Also this should ideally be able to capture changing consumer behaviour faster for better targeting.

Sources-

1) Go to

2) Create a new app
https://developers.facebook.com/apps/241634542707615

Screenshot 2014-05-10 21.30.53

3) Change url in settings ( to http://localhost:1410 ). I wish we could do this in twitteR package and oAuth for TWitter but I have no clue . that. Also coming up post on Google Plus and LinkedIn (if I can)

https://developers.facebook.com/apps/241634542707615/settings/

Screenshot 2014-05-10 21.32.01

3) Copy the secret thingies from the dashboard. DO click the screenshots to enlarge (i.e to understand what I am trying to do here)

https://developers.facebook.com/apps/241634542707615/dashboard/

Screenshot 2014-05-10 21.25.00

4) Modify code below with the secret thingies above

install.packages("Rfacebook")
install.packages("httpuv")
library(Rfacebook)
library(httpuv)
#fbOAuth(app_id, app_secret, extended_permissions = TRUE)
fb_oauth=fbOAuth("241634542707615", "4f2e6273c08d1b56d1bf14626d9e19a6", extended_permissions = TRUE)
#fb_oauth <- fbOAuth(app_id="123456789", app_secret="1A2B3C4D")
save(fb_oauth, file="fb_oauth")
getwd()
dir()

Created by Pretty R at inside-R.org

5) Hey now we have a fb ouath object we can just load it up. we the following code can then be modified at will to get your analysis

library(Rfacebook)
library(httpuv)
library(RColorBrewer)
 
load("fb_oauth")
me <- getUsers("me", token=fb_oauth)
#getFQL(query, token)
my_friends <- getFriends(token=fb_oauth, simplify=F)
str(my_friends)
table(my_friends$relationship_status)
 
pie(table(my_friends$relationship_status),col=brewer.pal(5, "Set1"))
 
table(my_friends$location)
pie(table(my_friends$location),col=brewer.pal(20, "Greens"))
pie(table(my_friends$locale),col=brewer.pal(4, "Blues"))
pie(table(my_friends$gender),col=brewer.pal(3, "Oranges"))
 
load("fb_oauth")
 
mat <- getNetwork(token=fb_oauth, format="adj.matrix")
 
library(igraph)
 
network <- graph.adjacency(mat, mode="undirected")
getwd()
setwd("C:/Users/dell/Desktop")
 
pdf("network_plot.pdf")
 
plot(network ,vertex.size=5, 
     vertex.label=NA, 
     vertex.label.cex=0.45,
     edge.arrow.size=1,
     edge.curved=TRUE,)
 
dev.off()

Created by Pretty R at inside-R.org

6) Voila my FB graph

Rplot04

and analyzed for how are my homies

Rplot07

Europeans into open relationships more

Rplot05

Places my friends are

Rplot04

Languages they speak

and all with R

Note- this is what an adjancency matrix is- just a fancy word for turning your Fb friends into a 1-0 matrix based on their relationships. The more friends you have the more interesting this analysis

Now lets do likes analysis

I use this code and my own username (since I am the only one who has allowed the app permissions!)

likes=getLikes(user="byebyebyer",n=500,token=fb_oauth)

Boy I like a lot of websites huh- I wonder if I can cluster/ data reduce/association analysis  them (but that’s coming up  or is it?)

 

Screenshot 2014-05-23 01.31.42


 

Screenshot 2014-05-10 21.48.56

Hat tips-

 

 

Analyze Facebook with R

http://blog.revolutionanalytics.com/2013/11/how-to-analyze-you-facebook-friends-network-with-r.html

123

Unknown's avatar

Author: Ajay Ohri

http://about.me/ajayohri

22 thoughts on “Analyzing Facebook Networks using #rstats”

  1. Excellent blog right here! Also your web site rather
    a lot up very fast! What web host are you using? Can I
    get your affiliate hyperlink on your host? I want my web site loaded up as fast as
    yours lol

  2. Wonderful site you have here but I was curious about if you knew of any discussion boards that cover the same topics discussed
    in this article? I’d really love to be a part of community where I can get feedback from other experienced people that share the same interest.
    If you have any suggestions, please let me know.

    Thanks a lot!

  3. Appreciating the hard work you put into your blog and detailed information you present.
    It’s nice to come across a blog every once in a while that isn’t the same unwanted rehashed information. Fantastic read!
    I’ve saved your site and I’m including your RSS feeds to
    my Google account.

  4. I’m amazed, I have to admit. Rarely do I come across
    a blog that’s both equally educative and amusing, and without a doubt,
    you’ve hit the nail on the head. The issue is something that
    too few people are speaking intelligently about.

    I am very happy I stumbled across this during my search for something concerning
    this.

  5. Superb blog! Do you have any helpful hints for aspiring writers?

    I’m hoping to start my own blog soon but I’m a little lost on everything.
    Would you recommend starting with a free platform like WordPress
    or go for a paid option? There are so many choices out there that I’m completely confused ..
    Any ideas? Appreciate it!

  6. It’s difficult to find experienced people in this particular subject, but you sound like you
    know what you’re talking about! Thanks

  7. This piece of writing gives clear idea in support
    of the new users of blogging, that in fact how to do blogging and site-building.

  8. I’ve been exploring for a bit for any high quality articles or weblog posts on this sort of house .
    Exploring in Yahoo I eventually stumbled upon this web site.

    Studying this information So i am happy to convey that I
    have an incredibly excellent uncanny feeling
    I came upon exactly what I needed. I so much surely will make sure to don?t omit this
    site and provides it a glance on a constant basis.

  9. magnificent points altogether, you just received a
    emblem new reader. What may you recommend in regards to your submit that you made some days in the
    past? Any sure?

  10. Hi there,
    I am getting an error while using getFriends function. The error is as following :

    Only friends who use the application will be returned
    See ?getFriends for more details
    Error in getFriends(token = fb_oauth, simplify = F) :
    No friend information is available.

    could you please help to resolve this?

  11. I have a same ploblem like Mohammad Daoud.

    Only friends who use the application will be returned
    See ?getFriends for more details
    Error in getFriends(token = FB_OAUTH, simplify = F) :
    No friend information is available.

    how can i solve this error?
    does anyone have idea?

  12. my_friends <- getFriends(token=fb_oauth, simplify=F)
    Only friends who use the application will be returned
    See ?getFriends for more details
    Error in getFriends(token = fb_oauth, simplify = F) :
    No friend information is available.

  13. Just a perfect way to spend a lazy Sunday evening although GOT is coming up on HBO in an hour!! great post Ajay!

Leave a reply to Fabian Cancel reply