class: center, middle, inverse, title-slide # Advanced Network Analysis ## Ego ERGMs ### Olga Chyzh [www.olgachyzh.com] --- exclude: true --- ## Recommended Readings - Salter-Townshend, Michael and Brendan Thomas Murphy. 2015. Role analysis in networks using mixtures of exponential random graph models." *Journal of Computational and Graphical Statistics* 24(2): 520--538. - Box-Steffensmeier, Janet M., Benjamin W. Campbell, Dino P. Christenson, Zachary Navabi. (2018): Role analysis using the ego-ERGM: A Look at environmental interest group coalitions. *Social Networks* 52: 213--227. - Campbell, Benjamin W. (2018): Inferring Latent Roles in Longitudinal Networks. *Political Analysis* 26(3): 292--311. --- ## The Core Idea - Most current work on clustering nodes in a network focuses on community finding, based on the ratio of between to within linkage densities. - An Ego-ERGM is a statistical model-based method of clustering nodes based on the role they play in the network. - For example, identify the most central or high degree nodes, or nodes whose connections are distinct in some other way, i. e. discriminate on different patterns of connectivity. - Model the set of all ego-networks using ERGMs, then perform a model-based clustering of these ego-networks and, thus nodes within them. - Simultaneously estimate both the node clustering assignments and the ERGM parameters in the clusters. --- ## Ego-Networks Define ego-networks for each node in the network: 1. Select a node; this is referred to as the ego. 2. Include the alters (nodes connected to the ego). 3. Include the connections between the alters. Nodes performing differing local roles will have markedly different ego-networks and nodes performing similar roles will have similar ego-networks. <img src="images/roles_demo.png" width="700px" style="display: block; margin: auto;" /> --- ## Can You Identify Ego Networks? <img src="images/communities.png" width="300px" style="display: block; margin: auto;" /> --- ## Example: Lazega Lawyers <img src="images/table1.png" width="600px" style="display: block; margin: auto;" /> --- ##Replicate Example from the Article ```r library(network) library(sna) library(ergm) library(devtools) install_github("ochyzh/networkdata") library(networkdata) data(lazega) ``` --- ```r m1 <- ego_ergm(net = lazega, form = c("edges", "mutual", 'desp(.8, type="OSP")', 'desp(.8, type="ISP")'), core_size = 1, min_size = 5, roles = 3, forking = FALSE, ncpus = 1, directed = TRUE, edge_covariates = FALSE, seed = 12345, steps = 50, tol = 1e-06) saveRDS(m1,file="data/m1_ego.rds") ``` --- ```r m1<-readRDS("data/m1_ego.rds") m1$group.theta ``` ``` ## [,1] [,2] [,3] [,4] ## [1,] 1.740699 1.447842 -0.3398682 -0.1047873 ## [2,] -9.542963 1.514716 8.7070389 1.2591454 ## [3,] 1.358836 0.928196 -0.4409083 -0.4892306 ``` ```r m1$role_assignments ``` ``` ## Id Role ## 1 V1 1 ## 2 V2 3 ## 3 V3 3 ## 4 V4 1 ## 5 V5 1 ## 6 V6 3 ## 7 V7 1 ## 8 V8 1 ## 9 V9 1 ## 10 V10 3 ## 11 V11 1 ## 12 V12 1 ## 13 V13 1 ## 14 V14 3 ## 15 V15 1 ## 16 V16 3 ## 17 V17 1 ## 18 V18 3 ## 19 V19 1 ## 20 V20 1 ## 21 V21 1 ## 22 V22 3 ## 23 V23 3 ## 24 V24 3 ## 25 V25 1 ## 26 V26 3 ## 27 V27 1 ## 28 V28 3 ## 29 V29 3 ## 30 V30 3 ## 31 V31 3 ## 32 V32 3 ## 33 V33 3 ## 34 V34 1 ## 35 V35 3 ## 36 V36 1 ## 37 V37 1 ## 38 V38 3 ## 39 V39 2 ## 40 V40 3 ## 41 V41 1 ## 42 V42 3 ## 43 V43 3 ## 44 V44 3 ## 45 V45 3 ## 46 V46 3 ## 47 V47 3 ## 48 V48 3 ## 49 V49 3 ## 50 V50 3 ## 51 V51 1 ## 52 V52 3 ## 53 V53 3 ## 54 V54 3 ## 55 V55 3 ## 56 V56 1 ## 57 V57 3 ## 58 V59 3 ## 59 V60 3 ## 60 V61 3 ## 61 V62 3 ## 62 V63 3 ## 63 V64 3 ## 64 V65 3 ## 65 V66 3 ## 66 V67 3 ## 67 V68 3 ## 68 V69 3 ## 69 V70 3 ## 70 V71 3 ``` ```r nrow(m1$role_assignments) ``` ``` ## [1] 70 ``` --- ## Replicate the Table ```r length(v.attrs$Status[-58]) #It kicks out node 58 (degree=0?) ``` ``` ## [1] 70 ``` ```r table(v.attrs$Status[-58],m1$role_assignments[,2]) ``` ``` ## ## 1 2 3 ## 1 18 0 18 ## 2 4 1 29 ``` --- ## Plot ```r plot(lazega, displaylabels = FALSE, # size of nodes based on vector vertexSize vertex.cex = m1$role_assignments[,2], # color of nodes based on vertex attribute: group vertex.col = 'Status', edge.col="gray" ) ``` --- ## Plot <img src="14_ego_ergms_files/figure-html/unnamed-chunk-9-1.png" style="display: block; margin: auto;" /> --- ## Your Turn 1. Load the `sampson` dataset from the `sna` library. 2. How many different roles do you think are in these data? 3. Estimate an ego ERGM on `samplike` data. 4. Cross-tabulate the roles you identified with the `group` vertex attribute. Does it seem like the model is picking up differences based on groups? 5. Cross-tabulate the roles you identified with the `cloisterville` vertex attribute. Does it seem like the model is picking up differences based on whether monks attended Cloisterville? 6. Make a network graph, coloring nodes by role and using node size to show group belonging.