æ©æ¢°å¦ç¿æç¿ã: ã½ã¼ã·ã£ã«ã°ã©ãã®åæ
ãå ¥é æ©æ¢°å¦ç¿ãæç¿ãã11æ¥ç®ãã11ç« ã½ã¼ã·ã£ã«ã°ã©ãã®åæãã§ãã
Twitterã®ã½ã¼ã·ã£ã«ã°ã©ãã®å¯è¦åãããããã°ã©ããããã¹ã¹ã¡ã®åéãæ¨è¦ããã·ã¹ãã ãä½ãã¾ãã
# åæºå > setwd("11-SNA/")
ãã¼ã«ã«ã³ãã¥ããã£æ§é ã®å¯è¦å
æåã®ä¾ã§ã¯ãã¦ã¼ã¶ã¼ johnmyleswhite
ã®ãã©ãã¯ã¼ããã©ã®ãããªã³ãã¥ããã£æ§é ãæã£ã¦ããããåæãã¾ãã
ã¦ã¼ã¶ã¼ johnmyleswhite
ã¨ãã®ã¦ã¼ã¶ã¼ãç´æ¥ãã©ãã¼ãã¦ããã¦ã¼ã¶ã¼ã®ã°ã©ã(ã¦ã¼ã¶ã¼ãä¸å¿ã¨ããã¨ã´ãããã¯ã¼ã¯ã¨å¼ã³ã¾ã)ãèªã¿è¾¼ã¿ã
åãã©ãã¯ã¼éã®è·é¢ãç®åºãããããã¨ã« hclust
ã§é層çã¯ã©ã¹ã¿ãªã³ã°ãè¡ãã¾ãã
# ã°ã©ããã¼ã¿ã®èªã¿è¾¼ã¿ > user <- 'johnmyleswhite' > user.ego <- read.graph("data/johnmyleswhite/johnmyleswhite_ego.graphml", format='graphml') # ãã¼ãéã®è·é¢ãç®åº > user.sp <- shortest.paths(user.ego) # é層çã¯ã©ã¹ã¿ãªã³ã°ã§ããã©ãã¯ã¼ã®ã³ãã¥ããã£æ§é ãç®åº > user.hc <- hclust(dist(user.sp)) # å¯è¦å > png(paste('../images/', user, '_dendrogram.png', sep=''), width=1680, height=1050) > plot(user.hc) > dev.off()
ã°ã©ãããããã£ããã¨2ã¤ã®å¤§ããªã³ãã¥ããã£ãããããã®ä¸ã«ããã«å°ããªãµãã³ãã¥ããã£ãããæ§æã«ãªã£ã¦ãããã¨ãããããã¨ã
ã°ã©ããã¼ã¿ãããã¹ã¹ã¡ã®åéãæ¨è¦ãã
ãåéã®åéãã¯åéã«ãªã確çãé«ããã®ä»®å®ã®ãã¨ãã°ã©ããã¼ã¿ãããã¹ã¹ã¡ã®åéãæ¨è¦ãã¦ã¿ã¾ãã
ã¾ãã¯ãã°ã©ããã¼ã¿ã®èªã¿è¾¼ã¿ã
# ãã¹ã¹ã¡ãã©ãã¯ã¼ãæ¨è¦ãã対象ã¨ããã¦ã¼ã¶ã¼å > user <- "drewconway" # ã°ã©ããã¼ã¿ã®èªã¿è¾¼ã¿ > user.graph <- suppressWarnings(read.graph(paste("data/", user, "/", user, "_net.graphml", sep = ""), format = "graphml"))
ã°ã©ãããããåéã®åéããåéåè£ã¨ãã¦åãåºãã¾ãã ãå¤ãã®åéãåéã¨ãã¦ããåè£ã¯é©æ§ãé«ããã¨ã¿ãªãã¦é ä½ã¥ããã¦ãã½ã¼ãã
# "drewconway" ããã©ãã¼ãã¦ããã¦ã¼ã¶ã¼(=åé)ã®ä¸è¦§ãåãåºã > friends <- V(user.graph)$name[neighbors(user.graph, user, mode = "out") + 1] [1] "311nyc" "aaronkoblin" "abumuqawama" "acroll" "adamlaiacano" [6] "aeromax" # ã°ã©ãã®ã¨ãã¸ã®ä¸è¦§ãåãåºã > user.el <- get.edgelist(user.graph) > head(user.el) [,1] [,2] [1,] "drewconway" "311nyc" [2,] "drewconway" "aaronkoblin" [3,] "drewconway" "abumuqawama" [4,] "drewconway" "acroll" [5,] "drewconway" "adamlaiacano" [6,] "drewconway" "aeromax" # åéã®åéã2çªç®ã®è¦ç´ (ã¿ã¼ã²ãã)ã«å«ã¾ããè¡ãåãåºãã # ãã ãããã§ã«ãã©ãã¼æ¸ã¿(=åé)ã«ãªã£ã¦ããã¦ã¼ã¶ã¼ã¯é¤ã > non.friends <- sapply(1:nrow(user.el), function(i) { ifelse(any(user.el[i,] == user | !user.el[i,1] %in% friends) | user.el[i,2] %in% friends, FALSE, TRUE) }) > non.friends.el <- user.el[which(non.friends == TRUE),] > head(non.friends.el) [,1] [,2] [1,] "000988" "1000timesyes" [2,] "000988" "10ch" [3,] "000988" "1mrankhan" [4,] "000988" "1ndus" [5,] "000988" "500startups" [6,] "000988" "_hoffman" # åéåè£ãã¨ã®åéã®æ°ãéè¨ > friends.count <- table(non.friends.el[,2]) > head(friends.count) ___emma __damonwang__ __dave __davidflanagan __iriss 1 1 2 3 1 __neha 1 # ãã¼ã¿ãã¬ã¼ã ã«å¤æ > friends.followers <- data.frame(list(Twitter.Users = names(friends.count), Friends.Following=as.numeric(friends.count)), stringsAsFactors = FALSE) > head(friends.followers) Twitter.Users Friends.Following 1 ___emma 1 2 __damonwang__ 1 3 __dave 2 4 __davidflanagan 3 5 __iriss 1 6 __neha 1 # åéåè£ã¨ãã¦ã®æé©åº¦ã示ãææ¨ã¨ãã¦ãååéåè£ããã©ãã¼ãã¦ããåéæ¯çãè¨ç®ãã¦ä½¿ãã # å¤ãã®åéãåéã¨ãã¦ããåè£ã¯é©æ§ãé«ãã¨ã¿ãªãã > friends.followers$Friends.Norm <- friends.followers$Friends.Following / length(friends) > head(friends.followers) Twitter.Users Friends.Following Friends.Norm 1 ___emma 1 0.003816794 2 __damonwang__ 1 0.003816794 3 __dave 2 0.007633588 4 __davidflanagan 3 0.011450382 5 __iriss 1 0.003816794 6 __neha 1 0.003816794 # ãå§ã度ã®ææ¨ã§ã½ã¼ã > friends.followers <- friends.followers[with(friends.followers, order(-Friends.Norm)),]
ãã¼ã¿ãã§ããã®ã§ããå§ã度é ã«ä¸ä½6人ã表示ãã¦ã¿ã¾ãã
# ä¸ä½6人ãåå¾ã > head(friends.followers) Twitter.Users Friends.Following Friends.Norm 13388 cshirky 80 0.3053435 21403 fredwilson 58 0.2213740 6950 bigdata 57 0.2175573 14062 dangerroom 57 0.2175573 55153 shitmydadsays 55 0.2099237 2025 al3x 54 0.2061069