summaryrefslogtreecommitdiffstats
path: root/R Scripts/predict-victims-plots.R
diff options
context:
space:
mode:
authorBen Green <bgreen@g.harvard.edu>2015-09-17 23:37:30 -0400
committerBen Green <bgreen@g.harvard.edu>2015-09-17 23:37:32 -0400
commitc2eec4bb82cffe6ac454f4de62e828fe176c7e5c (patch)
tree4e4d601fb695f8a0d4e30defc35313b12b8c0a77 /R Scripts/predict-victims-plots.R
parentd943b78f633c5b783ce0311f3861f02502dca263 (diff)
downloadcriminal_cascades-c2eec4bb82cffe6ac454f4de62e828fe176c7e5c.tar.gz
some plotting stuff
Diffstat (limited to 'R Scripts/predict-victims-plots.R')
-rw-r--r--R Scripts/predict-victims-plots.R31
1 files changed, 17 insertions, 14 deletions
diff --git a/R Scripts/predict-victims-plots.R b/R Scripts/predict-victims-plots.R
index 3dfba60..179a60b 100644
--- a/R Scripts/predict-victims-plots.R
+++ b/R Scripts/predict-victims-plots.R
@@ -1,5 +1,11 @@
##### Plot results
-# load('Results/correct_rank_91415.RData')
+library(RColorBrewer)
+library(igraph)
+setwd('~/Documents/Violence Cascades/')
+load('Raw Data/lcc.RData')
+load('Results/correct_rank_91415.RData')
+
+#######
nvics = dim(correct_rank)[1]
correct_rank1 = correct_rank[,length(lambdas)] # demographics model
@@ -18,33 +24,30 @@ counts = matrix(c( sum(correct_rank1<(vcount(lcc)*popsizes[1])),
sum(correct_rank3<(vcount(lcc)*popsizes[2])),
sum(correct_rank3<(vcount(lcc)*popsizes[3]))),
nrow=3, byrow=T)
-barplot(counts,
+cols = brewer.pal(3,'Paired'); cols=cols[c(3,1,2)]
+barplot(counts, border=NA,
xlab="Size of High-Risk Population",
ylab="Victims Predicted",
names.arg=paste(as.character(popsizes*100),'%',sep=''),
ylim=c(0,max(counts)*1.1),axes=F,
- col=c(rgb(0,0,1,1/2),rgb(1,0,0,1/2),rgb(0,1,0,1/2)),
+ col=cols,
beside=TRUE)
axis(2, at=pretty(counts*100/nvics)*nvics/100, lab=paste0(pretty(counts*100/nvics), "%"), las=TRUE)
legend("topleft", inset=0.05,
c("Demographics Model", "Contagion Model", "Combined Model"),
- fill=c(rgb(0,0,1,1/2),rgb(1,0,0,1/2),rgb(0,1,0,1/2)))
+ fill=cols,border=NA,bty='n')
box(which='plot')
-
par(new=T)
-barplot(counts,
- ylim=c(0,max(counts)*1.1),
- col=c(rgb(0,0,1,0),rgb(1,0,0,0),rgb(0,1,0,0)),
- beside=TRUE,axes=F)
axis(side=4, at=pretty(counts), lab=pretty(counts))
mtext(side = 4, line = 3, "Number of Victims Predicted")
#### Precision-Recall Curve
-plot(ecdf(correct_rank1),col='red',lwd=2,main='')
-plot(ecdf(correct_rank2),col='darkblue',lwd=2,add=T)
-plot(ecdf(correct_rank3),col='darkgreen',lwd=2,add=T)
+plot(ecdf(correct_rank1),col=cols[1],lwd=2,main='',
+ xlab='Ranking',ylab='CDF',xlim=c(0,140000))
+plot(ecdf(correct_rank2),col=cols[2],lwd=2,add=T)
+plot(ecdf(correct_rank3),col=cols[3],lwd=2,add=T)
legend("bottomright", inset=0.05,
- c("Demographics Model", "Cascade Model", "Combined Model"),
- fill=c('red','darkblue','darkgreen'))
+ c("Demographics Model", "Contagion Model", "Combined Model"),
+ fill=cols,border=NA,bty='n')