summaryrefslogtreecommitdiffstats
path: root/R Scripts/data-exploration.R
blob: 404ce9e558f9548512838232e1c17ca12d1bc5ee (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
library(igraph)
setwd("Documents/Cascade Project/Raw Data/")
load('chi-19mar2015.RData')

d = remove.edge.attribute(person,'weight')
lcc = induced.subgraph(d,which(clusters(d)$membership==which.max(clusters(d)$csize)))

##### Small-World Analysis
trl = mean(transitivity(lcc,type='local',isolates='zero'))
apl = average.path.length(lcc)
cat('Local Transitivity =', trl);cat('\nAverage Path Length =', apl)

nsim = 5
ER_sim = data.frame(trl=rep(0,nsim),apl=0)
for(i in 1:nsim){
  print(i)
  erg = erdos.renyi.game(n=vcount(lcc),p.or.m=ecount(lcc),type='gnm')
  erg = induced.subgraph(erg,which(clusters(erg)$membership==which.max(clusters(erg)$csize)))
  ER_sim[i,1] = mean(transitivity(erg,type='local',isolates='zero'))
  ER_sim[i,2] = average.path.length(erg)
}

S = data.frame(C_dat = trl,
               L_dat = apl,
               C_ER=mean(ER_sim$trl),
               L_ER=mean(ER_sim$apl),
               S_ER=mean((trl/ER_sim$trl)/(apl/ER_sim$apl)))
S

##### Degree Distribution
plot(degree.distribution(lcc)*vcount(lcc),log='xy',type='l',col='red',lwd=2,
      xlab='Degree', ylab='Number of Vertices', main='Degree Distribution')


##### Victims
vic_ids = which(V(lcc)$vic==TRUE)
non_vic_ids = which(V(lcc)$vic==FALSE)
hist(as.numeric(V(lcc)$vic_date[vic_ids]),100,col='lightblue',
     xlab='Day of Study Period',main='Infections During the Study Period')