summaryrefslogtreecommitdiffstats
path: root/R Scripts/data-exploration.R
diff options
context:
space:
mode:
Diffstat (limited to 'R Scripts/data-exploration.R')
-rwxr-xr-xR Scripts/data-exploration.R40
1 files changed, 40 insertions, 0 deletions
diff --git a/R Scripts/data-exploration.R b/R Scripts/data-exploration.R
new file mode 100755
index 0000000..404ce9e
--- /dev/null
+++ b/R Scripts/data-exploration.R
@@ -0,0 +1,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')
+