From 8fadc0e29d96b4394a787e730c732ba21252147a Mon Sep 17 00:00:00 2001 From: Ben Green Date: Wed, 16 Sep 2015 12:56:17 -0400 Subject: updated prediction plotting scripts --- R Scripts/predict-victims-plots.R | 18 +++++++++--------- R Scripts/predict-victims.R | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/R Scripts/predict-victims-plots.R b/R Scripts/predict-victims-plots.R index dee3cdc..3dfba60 100644 --- a/R Scripts/predict-victims-plots.R +++ b/R Scripts/predict-victims-plots.R @@ -4,7 +4,8 @@ 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 +lambda_opt = which.max(colMeans(correct_rank<1382)) +correct_rank3 = correct_rank[,lambda_opt] # 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])), @@ -17,31 +18,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) -counts = counts*100/nvics barplot(counts, xlab="Size of High-Risk Population", - ylab="Percent of Victims Predicted", + ylab="Victims Predicted", names.arg=paste(as.character(popsizes*100),'%',sep=''), - ylim=c(0,max(counts)*1.1), + 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)), 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", "Cascades", "Combined Model"), + 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))) 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) + 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,xlim=c(1,100)) +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) legend("bottomright", inset=0.05, diff --git a/R Scripts/predict-victims.R b/R Scripts/predict-victims.R index 7caaf13..3a531db 100644 --- a/R Scripts/predict-victims.R +++ b/R Scripts/predict-victims.R @@ -48,7 +48,7 @@ days = Reduce(union, list(lcc_verts$fatal_day,lcc_verts$nonfatal_day_1, days = days[!is.na(days)] days = sort(days) days = split(days, ceiling(seq_along(days)/92)) -lambdas = c(0, exp(seq(log(0.0000001), log(.95), length.out=100)), 1) +lambdas = c(0, exp(seq(log(0.0001), log(0.01), length.out=100)), 1) ##### Loop through days correct_rank = c() @@ -106,4 +106,4 @@ for(i in 1:length(days)){ print(proc.time()-ptm) } -# save(correct_rank, file='Results/correct_rank_91415.RData') \ No newline at end of file +# save(correct_rank, file='Results/correct_rank_91515.RData') \ No newline at end of file -- cgit v1.2.3-70-g09d2