summaryrefslogtreecommitdiffstats
path: root/R Scripts/predict-victims-plots.R
blob: dee3cdc1939d7d27b04278594b011892f7785de2 (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
##### Plot results
# load('Results/correct_rank_91415.RData')

nvics = dim(correct_rank)[1]
correct_rank1 = correct_rank[,length(lambdas)] # demographics model
correct_rank2 = correct_rank[,1] # cascade model
correct_rank3 = correct_rank[,which.min(colMeans(correct_rank))] # best combined model
popsizes = c(0.1,0.5,1.0)/100
vcount(lcc)*popsizes
counts = matrix(c( sum(correct_rank1<(vcount(lcc)*popsizes[1])),
                  sum(correct_rank1<(vcount(lcc)*popsizes[2])),
                  sum(correct_rank1<(vcount(lcc)*popsizes[3])),
                  sum(correct_rank2<(vcount(lcc)*popsizes[1])),
                  sum(correct_rank2<(vcount(lcc)*popsizes[2])),
                  sum(correct_rank2<(vcount(lcc)*popsizes[3])),
                  sum(correct_rank3<(vcount(lcc)*popsizes[1])),
                  sum(correct_rank3<(vcount(lcc)*popsizes[2])),
                  sum(correct_rank3<(vcount(lcc)*popsizes[3]))),
                nrow=3, byrow=T)
counts = counts*100/nvics
barplot(counts, 
        xlab="Size of High-Risk Population",
        ylab="Percent of Victims Predicted",
        names.arg=paste(as.character(popsizes*100),'%',sep=''),
        ylim=c(0,max(counts)*1.1),
        col=c(rgb(0,0,1,1/2),rgb(1,0,0,1/2),rgb(0,1,0,1/2)),
        beside=TRUE)
legend("topleft", inset=0.05, 
       c("Demographics", "Cascades", "Combined Model"), 
       fill=c(rgb(0,0,1,1/2),rgb(1,0,0,1/2),rgb(0,1,0,1/2)))
box(which='plot')

par(new=T)
counts = counts/(100/nvics)
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)
axis(side = 4)
mtext(side = 4, line = 3, "Number of Victims Predicted")


#### Precision-Recall Curve
plot(ecdf(correct_rank1),col='red',lwd=2,xlim=c(1,100))
plot(ecdf(correct_rank2),col='darkblue',lwd=2,add=T)
plot(ecdf(correct_rank3),col='darkgreen',lwd=2,add=T)
legend("bottomright", inset=0.05, 
       c("Demographics Model", "Cascade Model", "Combined Model"), 
       fill=c('red','darkblue','darkgreen'))