-
Notifications
You must be signed in to change notification settings - Fork 0
/
SNA.Rmd
671 lines (537 loc) · 19.7 KB
/
SNA.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
---
title: "Gender Representation in Romance Movies using Network Analysis"
author: Ryan and Dina
output: rmarkdown::github_document
---
```{r}
#Clear
rm(list = ls())
```
```{r setup, include=FALSE , results="hide"}
#Packages
library(tidyverse)
library(igraph)
```
# 0 Load Node and Edge list (Check Alignment of Node and Edge List)
```{r echo=FALSE, message=FALSE , results="hide"}
no_films <- 11
all_nodes <- list.files(path = "node", pattern = '.csv$', full.names = T, include.dirs = T) %>%
map(read_csv)
all_edges <- list.files(path = "edge", pattern = '.csv$', full.names = T, include.dirs = T) %>%
map(read_csv)
#check extraction
list.files(path = "node", pattern = '.csv$', full.names = T, include.dirs = T)
list.files(path = "edge", pattern = '.csv$', full.names = T, include.dirs = T)
n <- c(1:no_films)
year <- c(2009,1977,2011,2004,2016,1987,1996,1999,2012,2014,1997)
movie <- c("500 Days of Summer",
"Annie Hall",
"Crazy, Stupid, Love",
"Eternal Sunshine of the Spotless Mind",
"La La Land",
"Princess Bride",
"Romeo & Juliet",
"Runaway Bride",
"Silver Linings Playbook",
"Theory of Everything",
"Titanic")
all = data.frame(n,year,movie)
all$nodes <- 0
all$edges <- 0
```
Nest Node and Edge List in dataframe
```{r message=FALSE, warning=FALSE}
for (i in 1:no_films){
all[i,]$edges <- nest(all_edges[[i]])
nod <- all_nodes[[i]]
nod <- nod %>%
select(nid,entity,freq,scene_count,gender) %>%
mutate(main = if_else(scene_count > 2, TRUE, FALSE))
all[i,]$nodes <- nest(nod)
}
all = all %>% arrange(year)
```
Check Dataframe
```{r}
print (all %>% select(n,year,movie))
```
# 1 Data Exploration: Raw Network Statistics
Stats Table
```{r}
compare_df <- all %>%
select(n, year, movie) %>%
mutate(modularity = 0,
den = 0,
trn = 0,
apl = 0,
dia = 0)
#Network Statistics
for (x in 1:no_films){
node_list = data.frame(all[x,]$nodes)
edge_list = data.frame(all[x,]$edges)
nodelist <- node_list
edgelist <- edge_list %>% select(node_i, node_j)
colnames(edgelist) = c('from','to')
edgelist
#Create igraph graph
g <- graph_from_edgelist(as.matrix(edgelist), directed = FALSE)
g <- simplify(g,remove.loops = TRUE, remove.multiple = TRUE)
#Check Modularity
com <- edge.betweenness.community(g, directed = F)
compare_df[x,]$modularity <- round(max(com$modularity),3)
#density
compare_df[x,]$den <- mean(degree(g))/(vcount(g)-1)
#transitivity (probability that the adjacent vertices of a vertex are connected)
compare_df[x,]$trn <- transitivity(g, 'global')
#Average Path Length (length of all the shortest paths from or to the vertices in the network)
compare_df[x,]$apl <- mean_distance(g, unconnected = TRUE)
#Diameter
compare_df[x,]$dia <- diameter(g, weights = NA)
}
compare_df
```
Comparing with Year
+ Lower Transitivity over the Years
```{r}
par(mfrow = c(2,3))
plot(compare_df$year, compare_df$modularity, main = "modularity")
plot(compare_df$year, compare_df$den, main = "density")
plot(compare_df$year, compare_df$trn, main = "trn")
plot(compare_df$year, compare_df$apl, main = "apl")
plot(compare_df$year, compare_df$dia, main = "dia")
```
# 2 Data Cleaning: Filtering Nodes
## 2a/ Initial Plots (undirected, self loops, WEIGHTED)
+ Problems with lack of labels, networks also very messy and unnecessary convulated
+ Black nodes, seem to be unimportant, thought we were able to remove it
```{r fig.width = 15, fig.asp = .62, warning=FALSE}
for (x in 1:no_films){
node_list <- data.frame(all[x,]$nodes)
edge_list <- data.frame(all[x,]$edges)
nodelist <- node_list
edgelist <- edge_list %>% select(node_i, node_j)
colnames(edgelist) <- c('from','to')
#Create igraph graph
el <- as.matrix(get.adjacency(graph.data.frame(edgelist)))
g <- graph_from_adjacency_matrix(el, weighted = T, mode = "undirected",diag = F)
#Order Vertices
order <- match(V(g)$name, nodelist$nid)
nodelist <- nodelist[order,]
#Centrality
btw <- betweenness(g)#betweenness
cls <- closeness(g)#closeness
k <- degree(g, mode = 'all')#degree
evc <- eigen_centrality(g, directed = T)$vector#eigenvector
pgr <- page_rank(g)$vector#pagerank
#Color by Gender
gen <- nodelist$gender
col_gen <- rep('black',length(gen))
col_gen[gen == 'F'] <- 'pink'
col_gen[gen == 'M'] <- 'skyblue'
#plot based on degree centrality
plot (g,
layout = layout_with_fr,
edge.width = (E(g)$weight/2),
vertex.size = 1.5*nodelist$freq^0.5, #based on speaking
#vertex.size = 25*(btw/max(btw))^0.5, #based on btw
#vertex.size = 25*(evc)^0.5, #based on evc
vertex.color = col_gen,
vertex.label = nodelist$entity,
vertex.label.cex = 0.1*(nodelist$freq^0.5),
#edge.arrow.size = 0.2,
main = paste(all[x,]$n," - (", all[x,]$year, ") ",all[x,]$movie, sep = ""),
add = F)
nodelist$gender[is.na(nodelist$gender)] <- "O"
text(-1.2, 1.2, paste("Gender Assortativity =", assortativity_nominal(g, as.factor(nodelist$gender))))
}
```
## 2b/ Filtering "Un-important" People? by Frequency Count [Scene Count 2 and Below]
+ Learnt that "importance" is hard to define theoretically
+ Low scene count actors might have high betweeness (disconnected the node) - Tititanic and Eternal Sunshine
+ The utterance count/ scene count might not have a direct rls with importance (centrality) [Search further]
```{r fig.width = 15, fig.asp = .62, warning=FALSE}
for (x in 1:no_films){
node_list <- data.frame(all[x,]$nodes)
edge_list <- data.frame(all[x,]$edges)
nodelist <- node_list
edgelist <- edge_list %>% select(node_i, node_j)
colnames(edgelist) = c('from','to')
#Create igraph graph
el <- as.matrix(get.adjacency(graph.data.frame(edgelist)))
#g <- graph_from_edgelist(as.matrix(edgelist), directed = FALSE)
#g <- simplify(g,remove.loops = TRUE, remove.multiple = TRUE)
g = graph_from_adjacency_matrix(el, weighted = T, mode = "undirected",diag = F)
#Delete Vertex
#del_gen = nodelist[is.na(nodelist$gender),]$nid
#del = del_gen
del_main = nodelist[(nodelist$main==FALSE),]$nid
#del = c(del_gen,del_main)
del_o <- match(del_main, V(g)$name)
del_o <- del_o[!is.na(del_o)]
g = delete_vertices(g, del_o)
#Order Vertices
order <- match(V(g)$name, nodelist$nid)
nodelist = nodelist[order,]
#Centrality
btw <- betweenness(g)#betweenness
cls <- closeness(g)#closeness
k <- degree(g, mode = 'all')#degree
evc <- eigen_centrality(g, directed = T)$vector#eigenvector
pgr <- page_rank(g)$vector#pagerank
#Color by Gender
gen <- nodelist$gender
col_gen <- rep('black',length(gen))
col_gen[gen == 'F'] <- 'pink'
col_gen[gen == 'M'] <- 'skyblue'
#plot based on degree centrality
plot (g,
layout = layout_with_fr,
edge.width = (E(g)$weight/2),
vertex.size = 1.5*nodelist$freq^0.5, #based on speaking
#vertex.size = 25*(btw/max(btw))^0.5, #based on btw
#vertex.size = 25*(evc)^0.5, #based on evc
vertex.color = col_gen,
vertex.label = nodelist$entity,
vertex.label.cex = 0.1*(nodelist$freq^0.5),
#edge.arrow.size = 0.2,
main = paste(all[x,]$n," - (", all[x,]$year, ") ",all[x,]$movie, sep = ""),
add = F)
nodelist$gender[is.na(nodelist$gender)] <- "O"
text(-1.2, 1.2, paste("Gender Assortativity =", assortativity_nominal(g, as.factor(nodelist$gender))))
}
```
## 2c/ Final Plotting by Gender
```{r fig.width = 15, fig.asp = .62, warning=FALSE}
#x=1
compare_df$asst = 0
for (x in 1:no_films){
#Call nodes and edges
node_list = data.frame(all[x,]$nodes)
edge_list = data.frame(all[x,]$edges)
nodelist <- node_list
edgelist <- edge_list %>% select(node_i, node_j)
colnames(edgelist) = c('from','to')
#Create igraph graph (undirected/unweighted)
g <- graph_from_edgelist(as.matrix(edgelist), directed = FALSE)
g <- simplify(g,remove.loops = TRUE, remove.multiple = TRUE)
#Delete Vertex (by gender)
del_gen <- nodelist[is.na(nodelist$gender),]$nid
del <- del_gen
del_o <- match(del, V(g)$name)
del_o <- del_o[!is.na(del_o)]
g <- delete_vertices(g, del_o)
#Order Vertices
order <- match(V(g)$name, nodelist$nid)
nodelist <- nodelist[order,]
#Centrality
btw <- betweenness(g)#betweenness
cls <- closeness(g)#closeness
k <- degree(g, mode = 'all')#degree
evc <- eigen_centrality(g, directed = T)$vector#eigenvector
pgr <- page_rank(g)$vector#pagerank
#Color by Gender
gen <- nodelist$gender
col_gen <- rep('black',length(gen))
col_gen[gen == 'F'] <- 'pink'
col_gen[gen == 'M'] <- 'skyblue'
#plot based on degree centrality
plot (g,
layout = layout_with_fr,
#edge.width = (E(g)$weight/2),
vertex.size = (nodelist$freq^0.5)+3, #based on speaking
#vertex.size = 25*(btw/max(btw))^0.5, #based on btw
#vertex.size = 25*(evc)^0.5, #based on evc
vertex.color = col_gen,
vertex.label = nodelist$entity,
vertex.label.cex = 0.1*(nodelist$freq^0.5),
#edge.arrow.size = 0.2,
main = paste(all[x,]$n," - (", all[x,]$year, ") ",all[x,]$movie, sep = ""),
add = F)
nodelist$gender[is.na(nodelist$gender)] <- "O"
text(-1.2, 1.2, paste("Gender Assortativity =", assortativity_nominal(g, as.factor(nodelist$gender))))
#plot(x = cent_df$freq, y = cent_df$btw, col = as.factor(cent_df$gender) )
compare_df[x,]$asst = assortativity_nominal(g, as.factor(nodelist$gender))
}
```
# 3 ASSORTATIVE MIXING [Macro]
## 3a/ Gender Assortative over Time?
+ Seems like "Gender dynamics" are more POLARIZED
+ Gender differences seems to play greater roles
```{r}
#par(mfrow = c(2,1))
plot(x=compare_df$year,
y=compare_df$asst,
main = "Gender Assortativity",
ylim = c(-0.15,0.15),
xlab = "Year",
ylab = "Asst")
abline(h = 0, lwd = 2, col = 'red')
plot(x=compare_df$year,
y=abs(compare_df$asst),
col= as.factor(compare_df$asst>0),
main = "Gender Assortativity (Absolute)",
xlab = "Year",
ylab = "abs(Asst)")
abline(lm(abs(compare_df$asst)~compare_df$year), col="green") # regression line (y~x)
#compare_df
```
## 3b/ Plotting by Communities
+ Communities tend to be decided by subplot
```{r fig.width = 15, fig.asp = .62, warning=FALSE}
#x=2
for (x in 1:no_films){
node_list = data.frame(all[x,]$nodes)
edge_list = data.frame(all[x,]$edges)
nodelist <- node_list
edgelist <- edge_list %>% select(node_i, node_j)
colnames(edgelist) = c('from','to')
#Create igraph graph
g <- graph_from_edgelist(as.matrix(edgelist), directed = FALSE)
g <- simplify(g,remove.loops = TRUE, remove.multiple = TRUE)
del = nodelist[is.na(nodelist$gender),]$nid
del_o <- match(del, V(g)$name)
del_o <- del_o[!is.na(del_o)]
delete_vertices(g, del_o)
order <- match(V(g)$name, nodelist$nid)
nodelist = nodelist[order,]
#Community Structure
com <- edge.betweenness.community(g, directed = F)
com_no = max(com$membership)
C <- split(nodelist, com$membership)
library(colorRamps)
names(C) <- primary.colors(com_no, steps = 2, no.white = TRUE)
#plot based on degree centrality
plot (g,
layout = layout_with_fr,
#edge.width = (E(g)$weight/2),
vertex.size = (nodelist$freq^0.5)+3,
vertex.color = com$membership + 1,
vertex.label = nodelist$entity,
#vertex.label.cex = 0.07*(nodelist$freq^0.5),
#edge.arrow.size = 0.2,
main = paste(all[x,]$n," - (", all[x,]$year, ") ",all[x,]$movie, sep = ""),
add = F)
text(-1.2, 1.2, paste("Modularity, Q =", round(max(com$modularity),3)))
}
```
# 4 CENTRALITY [Micro]
How does good representation look like?
## 4a/ Understanding Main Characters
```{r fig.width = 15, fig.asp = .62, warning=FALSE}
#x=1
for (x in 1:no_films){
#Call nodes and edges
node_list = data.frame(all[x,]$nodes)
edge_list = data.frame(all[x,]$edges)
nodelist <- node_list
edgelist <- edge_list %>% select(node_i, node_j)
colnames(edgelist) = c('from','to')
#Create igraph graph (undirected/unweighted)
g <- graph_from_edgelist(as.matrix(edgelist), directed = FALSE)
g <- simplify(g,remove.loops = TRUE, remove.multiple = TRUE)
#Delete Vertex (by gender)
del_gen <- nodelist[is.na(nodelist$gender),]$nid
del <- del_gen
del_o <- match(del, V(g)$name)
del_o <- del_o[!is.na(del_o)]
g <- delete_vertices(g, del_o)
#Order Vertices
order <- match(V(g)$name, nodelist$nid)
nodelist <- nodelist[order,]
#Centrality
btw <- betweenness(g)#betweenness
cls <- closeness(g)#closeness
k <- degree(g, mode = 'all')#degree
evc <- eigen_centrality(g, directed = T)$vector#eigenvector
pgr <- page_rank(g)$vector#pagerank
#Color by Gender
gen <- nodelist$gender
col_gen <- rep('black',length(gen))
col_gen[gen == 'F'] <- 'pink'
col_gen[gen == 'M'] <- 'skyblue'
#plot based on degree centrality
par(mfrow = c(1, 1))
plot (g,
layout = layout_with_fr,
#edge.width = (E(g)$weight/2),
vertex.size = 1.5*nodelist$freq^0.5, #based on speaking
#vertex.size = 25*(btw/max(btw))^0.5, #based on btw
#vertex.size = 25*(evc)^0.5, #based on evc
vertex.color = col_gen,
vertex.label = nodelist$entity,
vertex.label.cex = 0.1*(nodelist$freq^0.5),
#edge.arrow.size = 0.2,
main = paste(all[x,]$n," - (", all[x,]$year, ") ",all[x,]$movie, sep = ""),
add = F)
text(-1.2, 1.2, paste("Gender Assortativity =", assortativity_nominal(g, as.factor(nodelist$gender))))
#}
#which(nodelist$entity == "ANNIE")
#charA_i = which(nodelist$freq == max(nodelist$freq)) # Highest
#charB_i = which(nodelist$freq == max( nodelist$freq[nodelist$freq!=max(nodelist$freq)])) # Second Highest
#Male Protag
Mlist <- nodelist[nodelist$gender == "M",]
charA_nid <- Mlist$nid[which(Mlist$freq == max(Mlist$freq))]
#Femal Protag
Flist <- nodelist[nodelist$gender == "F",]
charB_nid <- Flist$nid[which(Flist$freq == max(Flist$freq))]
charA = which(nodelist$nid == charA_nid)
charB = which(nodelist$nid == charB_nid)
#charB
#charA = nodelist[nodelist$gender == "M",]
#nodelist[nodelist$gender == "F",]
charA_name = paste(nodelist$entity[charA], " (", nodelist$gender[charA] , ")", sep = "") #guy protag
charB_name = paste(nodelist$entity[charB], " (", nodelist$gender[charB] , ")", sep = "") #girl protag
# INDIVIDUAL NODE LEVEL
deg <- degree(g, mode = 'all')
btw <- betweenness(g)
eig <- eigen_centrality(g)$vector
BTW <- NULL
EIG <- NULL
done <- 0
#charA <- 5
#charB <- 24
sample_size <- 5000
while (done < sample_size)
{
r <- sample_degseq(deg, method = 'vl')
V(r)$name <- V(g)$name
BTW <- rbind(BTW, betweenness(r))
EIG <- rbind(EIG, eigen_centrality(r)$vector)
done <- done + 1
}
BTW <- as.data.frame(BTW)
EIG <- as.data.frame(EIG)
par(mfrow = c(2, 2))
# specific individual (e.g., Jace, ID = 23)
den <- density(BTW[,charA])
pval <- mean(BTW[,charA] > btw[charA])
plot(den, main = paste ('Betweenness - ', charA_name, sep = ""))
abline(v = median(BTW[,charA]), lwd = 2)
abline(v = btw[charA], col = 'red', lwd = 2)
text(btw[charA], max(den$y) * 6/7, paste("TOP", round(pval * 100, 1), "%"), pos = 4, col = 'red')
den <- density(BTW[,charB])
pval <- mean(BTW[,charB] > btw[charB])
plot(den, main = paste ('Betweenness - ', charB_name, sep = ""))
abline(v = median(BTW[,charB]), lwd = 2)
abline(v = btw[charB], col = 'blue', lwd = 2)
text(btw[charB], max(den$y) * 6/7, paste("TOP", round(pval * 100, 1), "%"), pos = 4, col = 'blue')
den <- density(EIG[,charA])
pval <- mean(EIG[,charA] > eig[charA])
plot(den, main = paste ('Eigenvector - ', charA_name, sep = ""))
abline(v = median(EIG[,charA]), lwd = 2)
abline(v = eig[charA], col = 'red', lwd = 2)
text(eig[charA], max(den$y) * 6/7, paste("TOP", round(pval * 100, 1), "%"), pos = 4, col = 'red')
den <- density(EIG[,charB])
pval <- mean(EIG[,charB] > eig[charB])
plot(den, main = paste ('Eigenvector - ', charB_name, sep = ""))
abline(v = median(EIG[,charB]), lwd = 2)
abline(v = eig[charB], col = 'blue', lwd = 2)
text(eig[charB], max(den$y) * 6/7, paste("TOP", round(pval * 100, 1), "%"), pos = 4, col = 'blue')
}
```
## 4b/ Understanding Overall Roles of Characters
```{r fig.asp=.9, fig.width=15, warning=FALSE}
for (x in 1:no_films){
#Call nodes and edges
node_list = data.frame(all[x,]$nodes)
edge_list = data.frame(all[x,]$edges)
nodelist <- node_list
edgelist <- edge_list %>% select(node_i, node_j)
colnames(edgelist) = c('from','to')
#Create igraph graph (undirected/unweighted)
g <- graph_from_edgelist(as.matrix(edgelist), directed = FALSE)
g <- simplify(g,remove.loops = TRUE, remove.multiple = TRUE)
#Delete Vertex (by gender)
del_gen <- nodelist[is.na(nodelist$gender),]$nid
del <- del_gen
del_o <- match(del, V(g)$name)
del_o <- del_o[!is.na(del_o)]
g <- delete_vertices(g, del_o)
#Order Vertices
order <- match(V(g)$name, nodelist$nid)
nodelist <- nodelist[order,]
#Color by Gender
gen <- nodelist$gender
col_gen <- rep('black',length(gen))
col_gen[gen == 'F'] <- 'pink'
col_gen[gen == 'M'] <- 'skyblue'
#plot based on degree centrality
par(mfrow = c(1, 1))
plot (g,
layout = layout_with_fr,
#edge.width = (E(g)$weight/2),
vertex.size = 1.5*nodelist$freq^0.5, #based on speaking
#vertex.size = 25*(btw/max(btw))^0.5, #based on btw
#vertex.size = 25*(evc)^0.5, #based on evc
vertex.color = col_gen,
vertex.label = nodelist$entity,
vertex.label.cex = 0.1*(nodelist$freq^0.5),
#edge.arrow.size = 0.2,
main = paste(all[x,]$n," - (", all[x,]$year, ") ",all[x,]$movie, sep = ""),
add = F)
text(-1.2, 1.2, paste("Gender Assortativity =", assortativity_nominal(g, as.factor(nodelist$gender))))
#}
# INDIVIDUAL NODE LEVEL
deg <- degree(g, mode = 'all')
btw <- betweenness(g)
eig <- eigen_centrality(g)$vector
BTW <- NULL
EIG <- NULL
done <- 0
sample_size <- 5000
while (done < sample_size)
{
r <- sample_degseq(deg, method = 'vl')
V(r)$name <- V(g)$name
BTW <- rbind(BTW, betweenness(r))
EIG <- rbind(EIG, eigen_centrality(r)$vector)
done <- done + 1
}
BTW <- as.data.frame(BTW)
EIG <- as.data.frame(EIG)
# ------------------------------------- #
peig <- NULL
pbtw <- NULL
n <- vcount(g)
for (i in 1:n)
{
peig <- c(peig, mean(EIG[,i] >= eig[i]))
pbtw <- c(pbtw, mean(BTW[,i] >= btw[i]))
}
nodelist$deg <- deg
nodelist$eig <- eig
nodelist$btw <- btw
nodelist$peig <- peig
nodelist$pbtw <- pbtw
nodelist$col <- 'white'
nodelist$col[nodelist$pbtw < .025] <- 'pink'
nodelist$col[nodelist$pbtw > .975] <- 'skyblue'
nodelist$gcol <- 'red'
nodelist$gcol[nodelist$gender == 'M'] <- 'blue'
#---------------------------
par(mfrow = c(3, 2))
#---------------------------
plot(-1, -1, xlim = c(0, max(nodelist$deg)), ylim = c(1, 0), main = 'Betweenness',
ylab = 'p_value', xlab = 'degree')
text(nodelist$deg, nodelist$pbtw, nodelist$gender, col = nodelist$gcol)
abline(h = c(.025, .5, .975), lty = 2)
plot(-1, -1, xlim = c(0, max(nodelist$deg)), ylim = c(1, 0), main = 'Eigenvector',
ylab = 'p_value', xlab = 'degree')
text(nodelist$deg, nodelist$peig, nodelist$gender, col = nodelist$gcol)
abline(h = c(.025, .5, .975), lty = 2)
#---------------------------
plot(-1, -1, xlim = c(0, max(nodelist$scene_count)), ylim = c(1, 0), main = 'Betweenness',
ylab = 'p_value', xlab = 'freq')
text(nodelist$scene_count, nodelist$pbtw, nodelist$gender, col = nodelist$gcol)
abline(h = c(.025, .5, .975), lty = 2)
plot(-1, -1, xlim = c(0, max(nodelist$scene_count)), ylim = c(1, 0), main = 'Eigenvector',
ylab = 'p_value', xlab = 'freq')
text(nodelist$scene_count, nodelist$peig, nodelist$gender, col = nodelist$gcol)
abline(h = c(.025, .5, .975), lty = 2)
#---------------------------
boxplot(pbtw ~ gender, data = nodelist, ylim = c(1, 0), main = 'Betweenness')
abline(h = .5, lty = 2)
boxplot(peig ~ gender, data = nodelist, ylim = c(1, 0), main = 'Eigenvector')
abline(h = .5, lty = 2)
}
```