summaryrefslogtreecommitdiffstats
path: root/R Scripts/analyze-cascades.R
blob: 463de18e2ea21a7e4d8c0d22e3db4eebe1ab7f96 (plain)
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
# library(igraph)
# setwd("~/Documents/Cascade Project/")
# 
# load('Results/dag_dat_all.RData')
# load('Results/weight-12-1-14.RData')
# load('Results/hyper-lcc.RData')

# dag = graph.edgelist(as.matrix(dag_dat[,1:2]))
# dag = set.edge.attribute(dag,'weight',value=weight)
# dag_dat = dag_dat[which(E(dag)$weight>=0.4),]
# dag = delete.edges(dag, which(E(dag)$weight<0.4))

table(clusters(dag)$csize)

clusters = clusters(dag)
membership = clusters$membership
csize = clusters$csize
order = rev(order(csize))

#use table not hist
plot(sizes,counts,log='xy',type='o',lwd=3,
     xlab='Size of Cascade', ylab='Number of Cascades', main='Distribution of Cascade Sizes')

i = 14
V = which(clusters(dag)$membership==order[i]) # get all nodes in cluster
cc = induced.subgraph(dag,V)
Vi = vic_ids[V]
Ei = intersect(which(dag_dat_vics$from[realized] %in% Vi),which(dag_dat_vics$to[realized] %in% Vi))
cc_dat = (dag_dat_vics[realized,])[Ei,]

### plot cascade ###
cols = rep('lightblue',vcount(cc))
seed = which(degree(cc,mode='in')==0)
cols[seed] = 'red'
plot(cc,vertex.size=10,edge.arrow.size=0.5,vertex.color=cols,vertex.label.cex=1,
     edge.width=E(cc)$weight*20/max(E(cc)$weight),layout=layout.reingold.tilford(cc,root=seed),
     vertex.label=V(hyp_lcc)$vic.day[Vi])
# vertex.label=as.Date(V(hyp_lcc)$vic.day[Vi], format ='%m/%d/%y'))
#      vertex.label=V(lcc)$vic_date[Vi])

### basic graph statistics
trl = mean(transitivity(cc,type='local',isolates='zero'))
apl = average.path.length(cc)
indeg = degree(cc,mode='in')
outdeg = degree(cc,mode='out')
ds = mean(cc_dat$dist)

### node demographic statistics
from = vic_ids[cc_dat$from]
to = vic_ids[cc_dat$to]
V(lcc)$sex[from] == V(lcc)$sex[to]
V(lcc)$sex[Vi]
V(lcc)$race[Vi]
as.numeric(V(lcc)$age[Vi])
V(lcc)$gang.member[Vi]
V(lcc)$gang.name[Vi]
V(lcc)$faction.name[Vi]