-
Notifications
You must be signed in to change notification settings - Fork 0
/
CombinedPlotsTreatedFoI_MHI_95pc_20_50_treat2x.R
165 lines (117 loc) · 8.09 KB
/
CombinedPlotsTreatedFoI_MHI_95pc_20_50_treat2x.R
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
library(ggplot2)
library(matrixStats)
library(cowplot)
# thresholds for medium-to-heavy infection
mediumHeavyInfectionThreshold_epg <- 2000 # WHO value for hookworm
diagnosticDivisor <- 24 # 24 for Kato-Katz.
mediumHeavyInfectionThreshold_counts <- mediumHeavyInfectionThreshold_epg / diagnosticDivisor
outpath <- "D:\\STH\\ModellingConsortium\\WRAquestion\\ForPublication\\FiguresAntonio\\"
# for column names and iterations
path <- "D:\\STH\\ModellingConsortium\\WRAquestion\\ForPublication\\ICLsimoutput\\"
file <- "fertilisedFemaleWorms_old_20-50_treat2x.RData"
stub <- substring(file, first=22, last=45)
results <- get(load(paste0(path, file)))
###############################################################################################
# FUNCTION TO DETERMINE MHI infections
###############################################################################################
getMHI <- function(eggCounts, threshold, scenario, refResults)
{
MHI <- eggCounts > threshold
MHI <- as.data.frame(cbind(refResults[, 1], MHI))
names(MHI) <- colnames(refResults)
MHIList <- split(MHI, MHI$rep)
MHIList <- lapply(MHIList, function(x){ x[, 1] <- NULL; x})
MHICountsList <- lapply(MHIList, rowSums)
MHICounts <- unlist(MHICountsList)
years <- 100
timerep=rep(seq(0, years, 1/12), 100)
time=seq(0, years, 1/12)
temp <- do.call(cbind, MHICountsList)
meanMHICounts <- rowMeans(temp)
sdMHICounts <- sqrt(rowVars(temp))
medianMHICounts <- rowMedians(temp)
p95MHICounts <- rowQuantiles(temp, probs=c(0.025, 0.975))
df.mhi <- data.frame(time=time, meanMHICounts=meanMHICounts/500*100, p5=p95MHICounts[,1]/500*100, p95=p95MHICounts[,2]/500*100)
df.mhi$scenario <- scenario
return(df.mhi)
}
###############################################################################################
# Figure 1a: 20-50% prevalence treat 2x per year, ICL model
###############################################################################################
# read in data
###############################################################################################
path <- "D:\\STH\\ModellingConsortium\\WRAquestion\\ForPublication\\ICLsimoutput\\"
file1 <- "redoneEggCountsOneList_old_20-50_treat2x.RData"
file2 <- "redoneEggCountsOneList_new_20-50_treat2x.RData"
file3 <- "eggCounts_20-50_untreated.RData"
###############################################################################################
# determine MHI infections in untreated scenario
###############################################################################################
eggCounts_untreated <- get(load(paste0(path, file3)))
df.mhi.icl.untreat <- getMHI(eggCounts_untreated, mediumHeavyInfectionThreshold_counts, "untreated", results)
rm(eggCounts_untreated)
###############################################################################################
# determine MHI infections in old treatment scenario
###############################################################################################
eggCounts_old <- get(load(paste0(path, file1)))
df.mhi.icl.old <- getMHI(eggCounts_old, mediumHeavyInfectionThreshold_counts, "old", results)
rm(eggCounts_old)
###############################################################################################
# determine MHI infections in new treatment scenario
###############################################################################################
eggCounts_new <- get(load(paste0(path, file2)))
df.mhi.icl.new <- getMHI(eggCounts_new, mediumHeavyInfectionThreshold_counts, "new", results)
rm(eggCounts_new)
################################################################################################
# combine data frames and plot
################################################################################################
df.mhi.icl.20_50 <- rbind(df.mhi.icl.untreat, df.mhi.icl.old, df.mhi.icl.new)
df.mhi.icl.20_50$scenario <- factor(df.mhi.icl.20_50$scenario, levels=c("new", "old", "untreated"))
p1 <- ggplot(df.mhi.icl.20_50)
p1 <- p1 + theme(panel.grid.major=element_blank(), panel.grid.minor=element_blank(), panel.background=element_blank(), axis.line=element_line(colour="black"), axis.title=element_text(size=24), axis.text=element_text(size=20), legend.title=element_text(size=20), legend.text=element_text(size=20))
p1 <- p1 + geom_ribbon(aes(x=time, ymin=p5, ymax=p95, fill=scenario), alpha=0.3) + scale_fill_manual(values=c("red", "blue", "seagreen"))
p1 <- p1 + geom_line(aes(x=time, y=meanMHICounts, colour=scenario), size=1, alpha=0.8) + scale_colour_manual(values=c("red", "blue", "seagreen"))
p1 <- p1 + scale_x_continuous(name="Age (years)", expand=c(0,0), limits=c(0, 72), breaks=seq(0, 100, 5))
p1 <- p1 + scale_y_continuous(name="% women with MHI", expand=c(0, 0)) + coord_cartesian(ylim=c(0,21))
print(p1)
###############################################################################################
# Figure 1b: 20-50% prevalence treat 1x per year, EMC model
###############################################################################################
# read in data
###############################################################################################
path <- "D:\\STH\\ModellingConsortium\\WRAquestion\\ForPublication\\EMCsimoutput\\"
file1 <- "redoneEggCountsOneList_old_20-50_treat2x.RData"
file2 <- "redoneEggCountsOneList_new_20-50_treat2x.RData"
file3 <- "eggCounts_20-50_untreated.RData"
###############################################################################################
# determine MHI infections in untreated scenario
###############################################################################################
eggCounts_untreated <- get(load(paste0(path, file3)))
df.mhi.emc.untreat <- getMHI(eggCounts_untreated, mediumHeavyInfectionThreshold_counts, "untreated", results)
rm(eggCounts_untreated)
###############################################################################################
# determine MHI infections in old treatment strategy scenario
###############################################################################################
eggCounts_old <- get(load(paste0(path, file1)))
df.mhi.emc.old <- getMHI(eggCounts_old, mediumHeavyInfectionThreshold_counts, "old", results)
rm(eggCounts_old)
###############################################################################################
# determine MHI infections in new treatment strategy scenario
###############################################################################################
eggCounts_new <- get(load(paste0(path, file2)))
df.mhi.emc.new <- getMHI(eggCounts_new, mediumHeavyInfectionThreshold_counts, "new", results)
rm(eggCounts_new)
################################################################################################
# combine data frames and plot
################################################################################################
df.mhi.emc.20_50 <- rbind(df.mhi.emc.untreat, df.mhi.emc.old, df.mhi.emc.new)
df.mhi.emc.20_50$scenario <- factor(df.mhi.emc.20_50$scenario, levels=c("new", "old", "untreated"))
p2 <- ggplot(df.mhi.emc.20_50)
p2 <- p2 + theme(panel.grid.major=element_blank(), panel.grid.minor=element_blank(), panel.background=element_blank(), axis.line=element_line(colour="black"), axis.title=element_text(size=24), axis.text=element_text(size=20), legend.title=element_text(size=20), legend.text=element_text(size=20))
p2 <- p2 + geom_ribbon(aes(x=time, ymin=p5, ymax=p95, fill=scenario), alpha=0.3) + scale_fill_manual(values=c("red", "blue", "seagreen"))
p2 <- p2 + geom_line(aes(x=time, y=meanMHICounts, colour=scenario), size=1, alpha=0.8) + scale_colour_manual(values=c("red", "blue", "seagreen"))
p2 <- p2 + scale_x_continuous(name="Age (years)", expand=c(0,0), limits=c(0, 72), breaks=seq(0, 100, 5))
p2 <- p2 + scale_y_continuous(name="% women with MHI", expand=c(0, 0)) + coord_cartesian(ylim=c(0,21))
print(p2)
pic_mhi_means <- plot_grid(p1, p2, labels=c('a', 'b'), label_size=18, ncol=2, hjust=0, vjust=1.0)
#save_plot(file=paste0(outpath, "pc95MHI", stub, ".pdf"), pic_mhi_means, base_height=8.5, base_width=19)