{"word_count": 356, "character_count": 3579}
In order to practice with network data with R, we have been playing with the Padgett (1994) Florentine's wedding dataset (discussed in the lecture). The dataset is available from&#62; library(network)&#62; data(flo)&#62; nflo=network(flo,directed=FALSE)  &#62; plot(nflo, displaylabels = TRUE,+      boxed.labels =+        FALSE)The next step was to move from the network package to igraph. Since we have the adjacency matrix, we can use it&#62; library(igraph)&#62; iflo=graph_from_adjacency_matrix(flo,+      mode = "undirected")&#62; plot(iflo)The good thing is that a lot of functions are available, for instance we can get shortest paths, between two specific nodes. And we can give appropriate colors to the nodes that we'll cross&#62; AP=all_shortest_paths(iflo,+                    from="Peruzzi",+                    to="Ginori")&#62; L=AP$res[[1]]&#62; V(iflo)$color="yellow"&#62; V(iflo)$color[L[2:4]]="light blue"&#62; V(iflo)$color[L[c(1,5)]]="blue"&#62; plot(iflo)We can also visualize edges, but I found it slightly more complicated (to extract edges from the output)&#62; liens=c(paste(as.character(L)[1:4],+             "--",+             as.character(L)[2:5],sep=""),+         paste(as.character(L)[2:5],+               "--",+               as.character(L)[1:4],sep=""))&#62; df=as.data.frame(ends(iflo,E(iflo)))&#62; names(df)=c("src","target")&#62; lstn=sort(unique(c(as.character(df[,1]),as.character(df[,2]),"Pucci")))&#62; Eliens=paste(as.numeric(factor(df[,1],levels=lstn)),"--",+              as.numeric(factor(df[,2],levels=lstn)),sep="")&#62; EU=unlist(lapply(Eliens,function(x) x%in%liens))&#62; E(iflo)$color=c("grey","black")[1+EU]&#62; plot(iflo)But it works. It is also possible to use some D3js visualization&#62; library( networkD3 )&#62; simpleNetwork (df)Then the next question was to add a vertice to the network. The most simple way to do it is probability through the adjacency matrix&#62; flo2=flo&#62; flo2["Pucci","Bischeri"]=1&#62; flo2["Bischeri","Pucci"]=1&#62; nflo2=network(flo2,directed=FALSE) &#62; plot(nflo2, displaylabels = TRUE,+      boxed.labels =+        FALSE)Then, we've been playing with centrality measures.&#62; plot(iflo,vertex.size=betweenness(iflo))The goal was to see how related they were. Here, for all of them, "Medici" is the central node. But what about the others?&#62; B=betweenness(iflo)&#62; C=closeness(iflo)&#62; D=degree(iflo)&#62; E=eigen_centrality(iflo)$vector&#62; base=data.frame(betw=B,close=C,deg=D,eig=E)&#62; cor(base)betw     close       deg       eigbetw  1.0000000 0.5763487 0.8333763 0.6737162close 0.5763487 1.0000000 0.7572778 0.7989789deg   0.8333763 0.7572778 1.0000000 0.9404647eig   0.6737162 0.7989789 0.9404647 1.0000000Those measures are quite correlated. It is also possible to use a hierarchical graph to visualize how close those centrality measures can be&#62; H=hclust(dist(t(base)),+          method="ward")&#62; plot(H)Instead of looking at values of centrality measures, it is possible to looks are ranks&#62; rbase=base&#62; for(i in 1:4) rbase[,i]=rank(base[,i])&#62; H=hclust(dist(t(rbase)),+          method="ward")&#62; plot(H)Here the eigenvector measure is very close to the degree of vertices.Finally, it is possible to seek clusters (in the context of coalition here, in case a war should start between those families)&#62; kc &#60;- fastgreedy.community ( iflo )Here we have 3 classes (+1 for the node that is disconnected from the other families)&#62; V(iflo)$color=c("yellow","orange",+       "light blue")[membership ( kc )]&#62; plot(iflo)&#62; plot(kc,iflo)