-
Notifications
You must be signed in to change notification settings - Fork 1
/
preparation_analysis.R
519 lines (396 loc) · 30.9 KB
/
preparation_analysis.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
#########################
# preparation_analysis.r
#########################
######
##incidence
#######
data_new_inc$row_number<-seq.int(nrow(data_new_inc))
#make variable vivax_new in incidence data frame with actual case numbers
data_new_inc$vivax_new<-data_new_inc$case_numbers_vivax
data_new_inc$falciparum_new<-data_new_inc$case_numbers_falciparum
x<-c(1:length(data_new_inc$Intervention))
for (val in x){
if(is.na(data_new_inc$vivax_new[val])){data_new_inc$vivax_new[val]<-data_new_inc$inc_converted_vivax[val]}}
x<-c(1:length(data_new_inc$Intervention))
for (val in x){
if(is.na(data_new_inc$falciparum_new[val])){data_new_inc$falciparum_new[val]<-data_new_inc$inc_converted_falc[val]}}
#get the time bins by steps of 6 months for categorical time
data_new_inc$time_incidence_cat <- cut(data_new_inc$time_incidence, breaks=c(-36, 0 , 6, 12, 18, 24, 72))
######
##code for intial proportion of Pv (high if above or equal to 50%)
#######
#add a before data point for comparison and take the average where there are more than one
data_new_inc$time_zero<-data_new_inc$time_incidence
data_new_inc$time_zero[data_new_inc$Intervention=='control']<-0
s<-data_new_inc[data_new_inc$time_zero<=0,c('vivax_new',"falciparum_new",'study_number_new')]
s$initial_proportion<-s$vivax_new/(s$vivax_new+s$falciparum_new)
data_new_inc$initial_proportion<-data_new_inc$vivax_new
data_new_inc$initial_proportion<-NA
x<-unique(s$study_number_new)
for (val in x){
s$initial_proportion_cat[s$study_number_new==val]<-mean(s$initial_proportion[s$study_number_new==val])
}
for (val in x){
numrec<-length(data_new_inc$initial_proportion[data_new_inc$study_number_new==val])
data_new_inc$initial_proportion[data_new_inc$study_number_new==val]<-rep(s$initial_proportion_cat[s$study_number_new==val][1], numrec)
}
data_new_inc$initial_proportion_cat[data_new_inc$initial_proportion<0.5]<-'low'
data_new_inc$initial_proportion_cat[data_new_inc$initial_proportion>=0.5]<-'high'
data_new_inc$initial_proportion_cat<-as.factor(data_new_inc$initial_proportion_cat)
#classify controls as time category before interventions happened
data_new_inc$time_incidence_cat[data_new_inc$Intervention=='control']<-'(-36,0]'
#drop levels that are not used
data_new_inc$seasonality<-as.character(data_new_inc$seasonality)
data_new_inc$seasonality<-as.factor(data_new_inc$seasonality)
data_new_inc$age_incidence<-as.character(data_new_inc$age_incidence)
data_new_inc$age_incidence<-as.factor(data_new_inc$age_incidence)
data_new_inc$season_survey_incidence<-as.character(data_new_inc$season_survey_incidence)
data_new_inc$season_survey_incidence<-as.factor(data_new_inc$season_survey_incidence)
data_new_inc$incidence_diagnostics<-as.character(data_new_inc$incidence_diagnostics)
data_new_inc$incidence_diagnostics<-as.factor(data_new_inc$incidence_diagnostics)
data_new_inc$relapse_pattern_white<-as.character(data_new_inc$relapse_pattern_white)
data_new_inc$relapse_pattern_white<-as.factor(data_new_inc$relapse_pattern_white)
##########
##data frames for the different interventions
#########
#LLIN first time
data_inc_LLIN_first<-data_new_inc[(data_new_inc$Intervention=='LLIN 1st dist')| (data_new_inc$Intervention=='control' & data_new_inc$Intervention[data_new_inc$row_number+1]=='LLIN 1st dist'),]
data_inc_LLIN_first$seasonality<-as.character(data_inc_LLIN_first$seasonality)
data_inc_LLIN_first$seasonality<-as.factor(data_inc_LLIN_first$seasonality)
data_inc_LLIN_first$age_incidence<-as.character(data_inc_LLIN_first$age_incidence)
data_inc_LLIN_first$age_incidence<-as.factor(data_inc_LLIN_first$age_incidence)
data_inc_LLIN_first$season_survey_incidence<-as.character(data_inc_LLIN_first$season_survey_incidence)
data_inc_LLIN_first$season_survey_incidence<-as.factor(data_inc_LLIN_first$season_survey_incidence)
data_inc_LLIN_first$incidence_diagnostics<-as.character(data_inc_LLIN_first$incidence_diagnostics)
data_inc_LLIN_first$incidence_diagnostics<-as.factor(data_inc_LLIN_first$incidence_diagnostics)
data_inc_LLIN_first$time_incidence_cat<-as.character(data_inc_LLIN_first$time_incidence_cat)
data_inc_LLIN_first$time_incidence_cat<-as.factor(data_inc_LLIN_first$time_incidence_cat)
#LLIN repeated time
data_inc_LLIN_rep<-data_new_inc[(data_new_inc$Intervention=='LLIN later dist')| (data_new_inc$Intervention=='control' & data_new_inc$Intervention[data_new_inc$row_number+1]=='LLIN later dist'),]
data_inc_LLIN_rep$seasonality<-as.character(data_inc_LLIN_rep$seasonality)
data_inc_LLIN_rep$seasonality<-as.factor(data_inc_LLIN_rep$seasonality)
data_inc_LLIN_rep$age_incidence<-as.character(data_inc_LLIN_rep$age_incidence)
data_inc_LLIN_rep$age_incidence<-as.factor(data_inc_LLIN_rep$age_incidence)
data_inc_LLIN_rep$season_survey_incidence<-as.character(data_inc_LLIN_rep$season_survey_incidence)
data_inc_LLIN_rep$season_survey_incidence<-as.factor(data_inc_LLIN_rep$season_survey_incidence)
data_inc_LLIN_rep$incidence_diagnostics<-as.character(data_inc_LLIN_rep$incidence_diagnostics)
data_inc_LLIN_rep$incidence_diagnostics<-as.factor(data_inc_LLIN_rep$incidence_diagnostics)
data_inc_LLIN_rep$time_incidence_cat<-as.character(data_inc_LLIN_rep$time_incidence_cat)
data_inc_LLIN_rep$time_incidence_cat<-as.factor(data_inc_LLIN_rep$time_incidence_cat)
#one dataset that combines repeated and first time distribution of nets
data_inc_LLIN_all<-rbind(data_inc_LLIN_first,data_inc_LLIN_rep)
#LLIN rest
data_inc_LLIN<-data_new_inc[(data_new_inc$Intervention=='LLIN')| (data_new_inc$Intervention=='control' & data_new_inc$Intervention[data_new_inc$row_number+1]=='LLIN'),]
data_inc_LLIN$seasonality<-as.character(data_inc_LLIN$seasonality)
data_inc_LLIN$seasonality<-as.factor(data_inc_LLIN$seasonality)
data_inc_LLIN$age_incidence<-as.character(data_inc_LLIN$age_incidence)
data_inc_LLIN$age_incidence<-as.factor(data_inc_LLIN$age_incidence)
data_inc_LLIN$season_survey_incidence<-as.character(data_inc_LLIN$season_survey_incidence)
data_inc_LLIN$season_survey_incidence<-as.factor(data_inc_LLIN$season_survey_incidence)
data_inc_LLIN$incidence_diagnostics<-as.character(data_inc_LLIN$incidence_diagnostics)
data_inc_LLIN$incidence_diagnostics<-as.factor(data_inc_LLIN$incidence_diagnostics)
data_inc_LLIN$time_incidence_cat<-as.character(data_inc_LLIN$time_incidence_cat)
data_inc_LLIN$time_incidence_cat<-as.factor(data_inc_LLIN$time_incidence_cat)
#untreated
data_inc_untreated<-data_new_inc[(data_new_inc$Intervention=='untreated nets')| (data_new_inc$Intervention=='control' & data_new_inc$Intervention[data_new_inc$row_number+1]=='untreated nets'),]
data_inc_untreated$seasonality<-as.character(data_inc_untreated$seasonality)
data_inc_untreated$seasonality<-as.factor(data_inc_untreated$seasonality)
data_inc_untreated$age_incidence<-as.character(data_inc_untreated$age_incidence)
data_inc_untreated$age_incidence<-as.factor(data_inc_untreated$age_incidence)
data_inc_untreated$season_survey_incidence<-as.character(data_inc_untreated$season_survey_incidence)
data_inc_untreated$season_survey_incidence<-as.factor(data_inc_untreated$season_survey_incidence)
data_inc_untreated$incidence_diagnostics<-as.character(data_inc_untreated$incidence_diagnostics)
data_inc_untreated$incidence_diagnostics<-as.factor(data_inc_untreated$incidence_diagnostics)
data_inc_untreated$time_incidence_cat<-as.character(data_inc_untreated$time_incidence_cat)
data_inc_untreated$time_incidence_cat<-as.factor(data_inc_untreated$time_incidence_cat)
#net retreatment
data_inc_retreat<-data_new_inc[(data_new_inc$Intervention=='net retreatment')| (data_new_inc$Intervention=='control' & data_new_inc$Intervention[data_new_inc$row_number+1]=='net retreatment'),]
data_inc_retreat$seasonality<-as.character(data_inc_retreat$seasonality)
data_inc_retreat$seasonality<-as.factor(data_inc_retreat$seasonality)
data_inc_retreat$age_incidence<-as.character(data_inc_retreat$age_incidence)
data_inc_retreat$age_incidence<-as.factor(data_inc_retreat$age_incidence)
data_inc_retreat$season_survey_incidence<-as.character(data_inc_retreat$season_survey_incidence)
data_inc_retreat$season_survey_incidence<-as.factor(data_inc_retreat$season_survey_incidence)
data_inc_retreat$incidence_diagnostics<-as.character(data_inc_retreat$incidence_diagnostics)
data_inc_retreat$incidence_diagnostics<-as.factor(data_inc_retreat$incidence_diagnostics)
data_inc_retreat$time_incidence_cat<-as.character(data_inc_retreat$time_incidence_cat)
data_inc_retreat$time_incidence_cat<-as.factor(data_inc_retreat$time_incidence_cat)
#MDA first time
data_inc_MDA_first<-data_new_inc[(data_new_inc$Intervention=='MDA 1st')| (data_new_inc$Intervention=='control' & data_new_inc$Intervention[data_new_inc$row_number+1]=='MDA 1st'),]
data_inc_MDA_first$seasonality<-as.character(data_inc_MDA_first$seasonality)
data_inc_MDA_first$seasonality<-as.factor(data_inc_MDA_first$seasonality)
data_inc_MDA_first$age_incidence<-as.character(data_inc_MDA_first$age_incidence)
data_inc_MDA_first$age_incidence<-as.factor(data_inc_MDA_first$age_incidence)
data_inc_MDA_first$season_survey_incidence<-as.character(data_inc_MDA_first$season_survey_incidence)
data_inc_MDA_first$season_survey_incidence<-as.factor(data_inc_MDA_first$season_survey_incidence)
data_inc_MDA_first$incidence_diagnostics<-as.character(data_inc_MDA_first$incidence_diagnostics)
data_inc_MDA_first$incidence_diagnostics<-as.factor(data_inc_MDA_first$incidence_diagnostics)
data_inc_MDA_first$time_incidence_cat<-as.character(data_inc_MDA_first$time_incidence_cat)
data_inc_MDA_first$time_incidence_cat<-as.factor(data_inc_MDA_first$time_incidence_cat)
#change the time categories for MDA to shorter
data_inc_MDA_first$time_incidence_cat <- cut(data_inc_MDA_first$time_incidence, breaks=c(-36, 0,2,4,28))
#MDA repeated
data_inc_MDA_rep<-data_new_inc[(data_new_inc$Intervention=='MDA repeated')| (data_new_inc$Intervention=='control' & data_new_inc$Intervention[data_new_inc$row_number+1]=='MDA repeated'),]
data_inc_MDA_rep$seasonality<-as.character(data_inc_MDA_rep$seasonality)
data_inc_MDA_rep$seasonality<-as.factor(data_inc_MDA_rep$seasonality)
data_inc_MDA_rep$age_incidence<-as.character(data_inc_MDA_rep$age_incidence)
data_inc_MDA_rep$age_incidence<-as.factor(data_inc_MDA_rep$age_incidence)
data_inc_MDA_rep$season_survey_incidence<-as.character(data_inc_MDA_rep$season_survey_incidence)
data_inc_MDA_rep$season_survey_incidence<-as.factor(data_inc_MDA_rep$season_survey_incidence)
data_inc_MDA_rep$incidence_diagnostics<-as.character(data_inc_MDA_rep$incidence_diagnostics)
data_inc_MDA_rep$incidence_diagnostics<-as.factor(data_inc_MDA_rep$incidence_diagnostics)
data_inc_MDA_rep$time_incidence_cat<-as.character(data_inc_MDA_rep$time_incidence_cat)
data_inc_MDA_rep$time_incidence_cat<-as.factor(data_inc_MDA_rep$time_incidence_cat)
data_inc_MDA_rep$time_incidence<-as.numeric(data_inc_MDA_rep$time_incidence)
#hist(data_inc_MDA_rep$time_incidence, breaks=seq(-36,28,by=1))
data_inc_MDA_rep$time_incidence_cat <- cut(data_inc_MDA_rep$time_incidence, breaks=c(-36, 0,2,4,28))
#combination of repeated and first time
data_inc_MDA_all<-rbind(data_inc_MDA_first,data_inc_MDA_rep)
#MDA rest
data_inc_MDA<-data_new_inc[(data_new_inc$Intervention=='MDA')| (data_new_inc$Intervention=='control' & data_new_inc$Intervention[data_new_inc$row_number+1]=='MDA'),]
data_inc_MDA$seasonality<-as.character(data_inc_MDA$seasonality)
data_inc_MDA$seasonality<-as.factor(data_inc_MDA$seasonality)
data_inc_MDA$age_incidence<-as.character(data_inc_MDA$age_incidence)
data_inc_MDA$age_incidence<-as.factor(data_inc_MDA$age_incidence)
data_inc_MDA$season_survey_incidence<-as.character(data_inc_MDA$season_survey_incidence)
data_inc_MDA$season_survey_incidence<-as.factor(data_inc_MDA$season_survey_incidence)
data_inc_MDA$incidence_diagnostics<-as.character(data_inc_MDA$incidence_diagnostics)
data_inc_MDA$incidence_diagnostics<-as.factor(data_inc_MDA$incidence_diagnostics)
data_inc_MDA$time_incidence_cat<-as.character(data_inc_MDA$time_incidence_cat)
data_inc_MDA$time_incidence_cat<-as.factor(data_inc_MDA$time_incidence_cat)
#IRS first
data_inc_IRS_first<-data_new_inc[(data_new_inc$Intervention=='IRS 1st time')| (data_new_inc$Intervention=='control' & data_new_inc$Intervention[data_new_inc$row_number+1]=='IRS 1st time'),]
data_inc_IRS_first$seasonality<-as.character(data_inc_IRS_first$seasonality)
data_inc_IRS_first$seasonality<-as.factor(data_inc_IRS_first$seasonality)
data_inc_IRS_first$age_incidence<-as.character(data_inc_IRS_first$age_incidence)
data_inc_IRS_first$age_incidence<-as.factor(data_inc_IRS_first$age_incidence)
data_inc_IRS_first$season_survey_incidence<-as.character(data_inc_IRS_first$season_survey_incidence)
data_inc_IRS_first$season_survey_incidence<-as.factor(data_inc_IRS_first$season_survey_incidence)
data_inc_IRS_first$incidence_diagnostics<-as.character(data_inc_IRS_first$incidence_diagnostics)
data_inc_IRS_first$incidence_diagnostics<-as.factor(data_inc_IRS_first$incidence_diagnostics)
data_inc_IRS_first$time_incidence_cat<-as.character(data_inc_IRS_first$time_incidence_cat)
data_inc_IRS_first$time_incidence_cat<-as.factor(data_inc_IRS_first$time_incidence_cat)
#IRS repeated
data_inc_IRS_rep<-data_new_inc[(data_new_inc$Intervention=='IRS repeated time')| (data_new_inc$Intervention=='control' & data_new_inc$Intervention[data_new_inc$row_number+1]=='IRS repeated time'),]
data_inc_IRS_rep$seasonality<-as.character(data_inc_IRS_rep$seasonality)
data_inc_IRS_rep$seasonality<-as.factor(data_inc_IRS_rep$seasonality)
data_inc_IRS_rep$age_incidence<-as.character(data_inc_IRS_rep$age_incidence)
data_inc_IRS_rep$age_incidence<-as.factor(data_inc_IRS_rep$age_incidence)
data_inc_IRS_rep$season_survey_incidence<-as.character(data_inc_IRS_rep$season_survey_incidence)
data_inc_IRS_rep$season_survey_incidence<-as.factor(data_inc_IRS_rep$season_survey_incidence)
data_inc_IRS_rep$incidence_diagnostics<-as.character(data_inc_IRS_rep$incidence_diagnostics)
data_inc_IRS_rep$incidence_diagnostics<-as.factor(data_inc_IRS_rep$incidence_diagnostics)
data_inc_IRS_rep$time_incidence_cat<-as.character(data_inc_IRS_rep$time_incidence_cat)
data_inc_IRS_rep$time_incidence_cat<-as.factor(data_inc_IRS_rep$time_incidence_cat)
#IRS rest
data_inc_IRS<-data_new_inc[(data_new_inc$Intervention=='IRS')| (data_new_inc$Intervention=='control' & data_new_inc$Intervention[data_new_inc$row_number+1]=='IRS'),]
data_inc_IRS$seasonality<-as.character(data_inc_IRS$seasonality)
data_inc_IRS$seasonality<-as.factor(data_inc_IRS$seasonality)
data_inc_IRS$age_incidence<-as.character(data_inc_IRS$age_incidence)
data_inc_IRS$age_incidence<-as.factor(data_inc_IRS$age_incidence)
data_inc_IRS$season_survey_incidence<-as.character(data_inc_IRS$season_survey_incidence)
data_inc_IRS$season_survey_incidence<-as.factor(data_inc_IRS$season_survey_incidence)
data_inc_IRS$incidence_diagnostics<-as.character(data_inc_IRS$incidence_diagnostics)
data_inc_IRS$incidence_diagnostics<-as.factor(data_inc_IRS$incidence_diagnostics)
data_inc_IRS$time_incidence_cat<-as.character(data_inc_IRS$time_incidence_cat)
data_inc_IRS$time_incidence_cat<-as.factor(data_inc_IRS$time_incidence_cat)
#all IRS
data_inc_IRS_all<-rbind(data_inc_IRS_first,data_inc_IRS_rep, data_inc_IRS)
#increased case managment
data_inc_case<-data_new_inc[(data_new_inc$Intervention=='increased case management')| (data_new_inc$Intervention=='control' & data_new_inc$Intervention[data_new_inc$row_number+1]=='increased case management'),]
data_inc_case$seasonality<-as.character(data_inc_case$seasonality)
data_inc_case$seasonality<-as.factor(data_inc_case$seasonality)
data_inc_case$age_incidence<-as.character(data_inc_case$age_incidence)
data_inc_case$age_incidence<-as.factor(data_inc_case$age_incidence)
data_inc_case$season_survey_incidence<-as.character(data_inc_case$season_survey_incidence)
data_inc_case$season_survey_incidence<-as.factor(data_inc_case$season_survey_incidence)
data_inc_case$incidence_diagnostics<-as.character(data_inc_case$incidence_diagnostics)
data_inc_case$incidence_diagnostics<-as.factor(data_inc_case$incidence_diagnostics)
data_inc_case$time_incidence_cat<-as.character(data_inc_case$time_incidence_cat)
data_inc_case$time_incidence_cat<-as.factor(data_inc_case$time_incidence_cat)
######
##prevalence
#######
data_new_prev$row_number<-seq.int(nrow(data_new_prev))
#variable vivax_new and falciparum_new with actual number of people infected
data_new_prev$vivax_new<-data_new_prev$pr_numb_vivax_LM
data_new_prev$falciparum_new<-data_new_prev$pr_numb_falciparum_LM
x<-c(1:length(data_new_prev$Intervention))
for (val in x){
if(is.na(data_new_prev$vivax_new[val])){data_new_prev$vivax_new[val]<-data_new_prev$pr_numb_vivax_PCR[val]}}
for (val in x){
if(is.na(data_new_prev$falciparum_new[val])){data_new_prev$falciparum_new[val]<-data_new_prev$pr_numb_falciparum_PCR[val]}}
x<-c(1:length(data_new_prev$Intervention))
for (val in x){
if(is.na(data_new_prev$vivax_new[val])){data_new_prev$vivax_new[val]<-data_new_prev$prev_converted_viv[val]}}
for (val in x){
if(is.na(data_new_prev$falciparum_new[val])){data_new_prev$falciparum_new[val]<-data_new_prev$prev_converted_falc[val]}}
######
##code for intial proportion of Pv
#######
data_new_prev$time_zero<-data_new_prev$time_prevalence
data_new_prev$time_zero[data_new_prev$Intervention=='control']<-0
s<-data_new_prev[data_new_prev$time_zero<=0,c('vivax_new',"falciparum_new",'study_number_new')]
s$initial_proportion<-s$vivax_new/(s$vivax_new+s$falciparum_new)
data_new_prev$initial_proportion<-data_new_prev$vivax_new
data_new_prev$initial_proportion<-NA
x<-unique(s$study_number_new)
for (val in x)
{s$initial_proportion_cat[s$study_number_new==val]<-mean(s$initial_proportion[s$study_number_new==val])
}
for (val in x) {
numrec<-length(data_new_prev$initial_proportion[data_new_prev$study_number_new==val])
data_new_prev$initial_proportion[data_new_prev$study_number_new==val]<-rep( s$initial_proportion_cat[s$study_number_new==val][1], numrec)
}
data_new_prev$initial_proportion_cat[data_new_prev$initial_proportion<0.5]<-'low'
data_new_prev$initial_proportion_cat[data_new_prev$initial_proportion>=0.5]<-'high'
data_new_prev$initial_proportion_cat<-as.factor(data_new_prev$initial_proportion_cat)
#get the time bins
#hist(data_new_prev$time_prevalence, breaks=seq(-90,402,by=6))
data_new_prev$time_prevalence_cat <- cut(data_new_prev$time_prevalence, breaks=c(-90, 0 , 6, 12, 18, 24, 402))
#classify control into before intervention time category
data_new_prev$time_prevalence_cat[data_new_prev$Intervention=='control']<-'(-90,0]'
#LLIN first time
data_prev_LLIN_first<-data_new_prev[(data_new_prev$Intervention=='LLIN 1st dist')| (data_new_prev$Intervention=='control' & data_new_prev$Intervention[data_new_prev$row_number+1]=='LLIN 1st dist'),]
data_prev_LLIN_first$seasonality<-as.character(data_prev_LLIN_first$seasonality)
data_prev_LLIN_first$seasonality<-as.factor(data_prev_LLIN_first$seasonality)
data_prev_LLIN_first$age_prevalence<-as.character(data_prev_LLIN_first$age_prevalence)
data_prev_LLIN_first$age_prevalence<-as.factor(data_prev_LLIN_first$age_prevalence)
data_prev_LLIN_first$season_survey_prevalence<-as.character(data_prev_LLIN_first$season_survey_prevalence)
data_prev_LLIN_first$season_survey_prevalence<-as.factor(data_prev_LLIN_first$season_survey_prevalence)
data_prev_LLIN_first$time_prevalence_cat<-as.character(data_prev_LLIN_first$time_prevalence_cat)
data_prev_LLIN_first$time_prevalence_cat<-as.factor(data_prev_LLIN_first$time_prevalence_cat)
#LLIN repeated time
data_prev_LLIN_rep<-data_new_prev[(data_new_prev$Intervention=='LLIN later dist')| (data_new_prev$Intervention=='control' & data_new_prev$Intervention[data_new_prev$row_number+1]=='LLIN later dist'),]
data_prev_LLIN_rep$seasonality<-as.character(data_prev_LLIN_rep$seasonality)
data_prev_LLIN_rep$seasonality<-as.factor(data_prev_LLIN_rep$seasonality)
data_prev_LLIN_rep$age_prevalence<-as.character(data_prev_LLIN_rep$age_prevalence)
data_prev_LLIN_rep$age_prevalence<-as.factor(data_prev_LLIN_rep$age_prevalence)
data_prev_LLIN_rep$season_survey_prevalence<-as.character(data_prev_LLIN_rep$season_survey_prevalence)
data_prev_LLIN_rep$season_survey_prevalence<-as.factor(data_prev_LLIN_rep$season_survey_prevalence)
data_prev_LLIN_rep$time_prevalence_cat<-as.character(data_prev_LLIN_rep$time_prevalence_cat)
data_prev_LLIN_rep$time_prevalence_cat<-as.factor(data_prev_LLIN_rep$time_prevalence_cat)
#exclude the ones that only have 24 months after the intervention or find no cases before interventon or after
data_prev_LLIN_rep$row_number<-seq.int(nrow(data_prev_LLIN_rep))
b<-data_prev_LLIN_rep$row_number[data_prev_LLIN_rep$study_number_new==39]
b<-c(b,data_prev_LLIN_rep$row_number[data_prev_LLIN_rep$study_number_new==173])
b<-c(b,data_prev_LLIN_rep$row_number[data_prev_LLIN_rep$study_number_new==184])
b<-c(b,data_prev_LLIN_rep$row_number[data_prev_LLIN_rep$study_number_new==189])
b<-c(b,data_prev_LLIN_rep$row_number[data_prev_LLIN_rep$study_number_new==38])
b<-c(b,data_prev_LLIN_rep$row_number[data_prev_LLIN_rep$study_number_new==167])
b<-c(b,data_prev_LLIN_rep$row_number[data_prev_LLIN_rep$study_number_new==168])
b<-c(b,data_prev_LLIN_rep$row_number[data_prev_LLIN_rep$study_number_new==171])
b<-c(b,data_prev_LLIN_rep$row_number[data_prev_LLIN_rep$study_number_new==176])
b<-c(b,data_prev_LLIN_rep$row_number[data_prev_LLIN_rep$study_number_new==204])
b<-c(b,data_prev_LLIN_rep$row_number[data_prev_LLIN_rep$study_number_new==364])
data_prev_LLIN_rep<-data_prev_LLIN_rep[-c(b),]
data_prev_LLIN_rep$row_number<-seq.int(nrow(data_prev_LLIN_rep))
#one data frame for first time distribution and repeated
data_prev_LLIN_all<-rbind(data_prev_LLIN_first,data_prev_LLIN_rep)
#LLIN rest
data_prev_LLIN<-data_new_prev[(data_new_prev$Intervention=='LLIN')| (data_new_prev$Intervention=='control' & data_new_prev$Intervention[data_new_prev$row_number+1]=='LLIN'),]
data_prev_LLIN$seasonality<-as.character(data_prev_LLIN$seasonality)
data_prev_LLIN$seasonality<-as.factor(data_prev_LLIN$seasonality)
data_prev_LLIN$age_prevalence<-as.character(data_prev_LLIN$age_prevalence)
data_prev_LLIN$age_prevalence<-as.factor(data_prev_LLIN$age_prevalence)
data_prev_LLIN$season_survey_prevalence<-as.character(data_prev_LLIN$season_survey_prevalence)
data_prev_LLIN$season_survey_prevalence<-as.factor(data_prev_LLIN$season_survey_prevalence)
data_prev_LLIN$time_prevalence_cat<-as.character(data_prev_LLIN$time_prevalence_cat)
data_prev_LLIN$time_prevalence_cat<-as.factor(data_prev_LLIN$time_prevalence_cat)
#untreated
data_prev_untreated<-data_new_prev[(data_new_prev$Intervention=='untreated nets')| (data_new_prev$Intervention=='control' & data_new_prev$Intervention[data_new_prev$row_number+1]=='untreated nets'),]
data_prev_untreated$seasonality<-as.character(data_prev_untreated$seasonality)
data_prev_untreated$seasonality<-as.factor(data_prev_untreated$seasonality)
data_prev_untreated$age_prevalence<-as.character(data_prev_untreated$age_prevalence)
data_prev_untreated$age_prevalence<-as.factor(data_prev_untreated$age_prevalence)
data_prev_untreated$season_survey_prevalence<-as.character(data_prev_untreated$season_survey_prevalence)
data_prev_untreated$season_survey_prevalence<-as.factor(data_prev_untreated$season_survey_prevalence)
data_prev_untreated$time_prevalence_cat<-as.character(data_prev_untreated$time_prevalence_cat)
data_prev_untreated$time_prevalence_cat<-as.factor(data_prev_untreated$time_prevalence_cat)
#net retreatment
data_prev_retreat<-data_new_prev[(data_new_prev$Intervention=='net retreatment')| (data_new_prev$Intervention=='control' & data_new_prev$Intervention[data_new_prev$row_number+1]=='net retreatment'),]
data_prev_retreat$seasonality<-as.character(data_prev_retreat$seasonality)
data_prev_retreat$seasonality<-as.factor(data_prev_retreat$seasonality)
data_prev_retreat$age_prevalence<-as.character(data_prev_retreat$age_prevalence)
data_prev_retreat$age_prevalence<-as.factor(data_prev_retreat$age_prevalence)
data_prev_retreat$season_survey_prevalence<-as.character(data_prev_retreat$season_survey_prevalence)
data_prev_retreat$season_survey_prevalence<-as.factor(data_prev_retreat$season_survey_prevalence)
data_prev_retreat$time_prevalence_cat<-as.character(data_prev_retreat$time_prevalence_cat)
data_prev_retreat$time_prevalence_cat<-as.factor(data_prev_retreat$time_prevalence_cat)
#MDA first time
data_prev_MDA_first<-data_new_prev[(data_new_prev$Intervention=='MDA 1st')| (data_new_prev$Intervention=='control' & data_new_prev$Intervention[data_new_prev$row_number+1]=='MDA 1st'),]
data_prev_MDA_first$seasonality<-as.character(data_prev_MDA_first$seasonality)
data_prev_MDA_first$seasonality<-as.factor(data_prev_MDA_first$seasonality)
data_prev_MDA_first$age_prevalence<-as.character(data_prev_MDA_first$age_prevalence)
data_prev_MDA_first$age_prevalence<-as.factor(data_prev_MDA_first$age_prevalence)
data_prev_MDA_first$season_survey_prevalence<-as.character(data_prev_MDA_first$season_survey_prevalence)
data_prev_MDA_first$season_survey_prevalence<-as.factor(data_prev_MDA_first$season_survey_prevalence)
data_prev_MDA_first$time_prevalence_cat<-as.character(data_prev_MDA_first$time_prevalence_cat)
data_prev_MDA_first$time_prevalence_cat<-as.factor(data_prev_MDA_first$time_prevalence_cat)
#change it into three monthly categories
#hist(data_prev_MDA_first$time_prevalence, breaks=seq(-68,402,by=1))
data_prev_MDA_first$time_prevalence_cat <- cut(data_prev_MDA_first$time_prevalence, breaks=c(-68, 0,3,7,402))
#MDA repeated
data_prev_MDA_rep<-data_new_prev[(data_new_prev$Intervention=='MDA repeated')| (data_new_prev$Intervention=='control' & data_new_prev$Intervention[data_new_prev$row_number+1]=='MDA repeated'),]
data_prev_MDA_rep$seasonality<-as.character(data_prev_MDA_rep$seasonality)
data_prev_MDA_rep$seasonality<-as.factor(data_prev_MDA_rep$seasonality)
data_prev_MDA_rep$age_prevalence<-as.character(data_prev_MDA_rep$age_prevalence)
data_prev_MDA_rep$age_prevalence<-as.factor(data_prev_MDA_rep$age_prevalence)
data_prev_MDA_rep$season_survey_prevalence<-as.character(data_prev_MDA_rep$season_survey_prevalence)
data_prev_MDA_rep$season_survey_prevalence<-as.factor(data_prev_MDA_rep$season_survey_prevalence)
data_prev_MDA_rep$time_prevalence_cat<-as.character(data_prev_MDA_rep$time_prevalence_cat)
data_prev_MDA_rep$time_prevalence_cat<-as.factor(data_prev_MDA_rep$time_prevalence_cat)
#hist(data_prev_MDA_rep$time_prevalence, breaks=seq(-68,402,by=1))
data_prev_MDA_rep$time_prevalence_cat <- cut(data_prev_MDA_rep$time_prevalence, breaks=c(-68, 0,3,7,402))
#MDA rest
data_prev_MDA<-data_new_prev[(data_new_prev$Intervention=='MDA')| (data_new_prev$Intervention=='control' & data_new_prev$Intervention[data_new_prev$row_number+1]=='MDA'),]
data_prev_MDA$seasonality<-as.character(data_prev_MDA$seasonality)
data_prev_MDA$seasonality<-as.factor(data_prev_MDA$seasonality)
data_prev_MDA$age_prevalence<-as.character(data_prev_MDA$age_prevalence)
data_prev_MDA$age_prevalence<-as.factor(data_prev_MDA$age_prevalence)
data_prev_MDA$season_survey_prevalence<-as.character(data_prev_MDA$season_survey_prevalence)
data_prev_MDA$season_survey_prevalence<-as.factor(data_prev_MDA$season_survey_prevalence)
data_prev_MDA$time_prevalence_cat<-as.character(data_prev_MDA$time_prevalence_cat)
data_prev_MDA$time_prevalence_cat<-as.factor(data_prev_MDA$time_prevalence_cat)
#IRS first
data_prev_IRS_first<-data_new_prev[(data_new_prev$Intervention=='IRS 1st time')| (data_new_prev$Intervention=='control' & data_new_prev$Intervention[data_new_prev$row_number+1]=='IRS 1st time'),]
data_prev_IRS_first$seasonality<-as.character(data_prev_IRS_first$seasonality)
data_prev_IRS_first$seasonality<-as.factor(data_prev_IRS_first$seasonality)
data_prev_IRS_first$age_prevalence<-as.character(data_prev_IRS_first$age_prevalence)
data_prev_IRS_first$age_prevalence<-as.factor(data_prev_IRS_first$age_prevalence)
data_prev_IRS_first$season_survey_prevalence<-as.character(data_prev_IRS_first$season_survey_prevalence)
data_prev_IRS_first$season_survey_prevalence<-as.factor(data_prev_IRS_first$season_survey_prevalence)
data_prev_IRS_first$time_prevalence_cat<-as.character(data_prev_IRS_first$time_prevalence_cat)
data_prev_IRS_first$time_prevalence_cat<-as.factor(data_prev_IRS_first$time_prevalence_cat)
#IRS repeated
data_prev_IRS_rep<-data_new_prev[(data_new_prev$Intervention=='IRS repeated time')| (data_new_prev$Intervention=='control' & data_new_prev$Intervention[data_new_prev$row_number+1]=='IRS repeated time'),]
data_prev_IRS_rep$seasonality<-as.character(data_prev_IRS_rep$seasonality)
data_prev_IRS_rep$seasonality<-as.factor(data_prev_IRS_rep$seasonality)
data_prev_IRS_rep$age_prevalence<-as.character(data_prev_IRS_rep$age_prevalence)
data_prev_IRS_rep$age_prevalence<-as.factor(data_prev_IRS_rep$age_prevalence)
data_prev_IRS_rep$season_survey_prevalence<-as.character(data_prev_IRS_rep$season_survey_prevalence)
data_prev_IRS_rep$season_survey_prevalence<-as.factor(data_prev_IRS_rep$season_survey_prevalence)
data_prev_IRS_rep$time_prevalence_cat<-as.character(data_prev_IRS_rep$time_prevalence_cat)
data_prev_IRS_rep$time_prevalence_cat<-as.factor(data_prev_IRS_rep$time_prevalence_cat)
#IRS rest
data_prev_IRS<-data_new_prev[(data_new_prev$Intervention=='IRS')| (data_new_prev$Intervention=='control' & data_new_prev$Intervention[data_new_prev$row_number+1]=='IRS'),]
data_prev_IRS$seasonality<-as.character(data_prev_IRS$seasonality)
data_prev_IRS$seasonality<-as.factor(data_prev_IRS$seasonality)
data_prev_IRS$age_prevalence<-as.character(data_prev_IRS$age_prevalence)
data_prev_IRS$age_prevalence<-as.factor(data_prev_IRS$age_prevalence)
data_prev_IRS$season_survey_prevalence<-as.character(data_prev_IRS$season_survey_prevalence)
data_prev_IRS$season_survey_prevalence<-as.factor(data_prev_IRS$season_survey_prevalence)
data_prev_IRS$time_prevalence_cat<-as.character(data_prev_IRS$time_prevalence_cat)
data_prev_IRS$time_prevalence_cat<-as.factor(data_prev_IRS$time_prevalence_cat)
#data frame for all IRS no matter which round
data_prev_IRS_all<-rbind(data_prev_IRS_first,data_prev_IRS_rep, data_prev_IRS)
#increased case managment
data_prev_case<-data_new_prev[(data_new_prev$Intervention=='increased case management')| (data_new_prev$Intervention=='control' & data_new_prev$Intervention[data_new_prev$row_number+1]=='increased case management'),]
data_prev_case$seasonality<-as.character(data_prev_case$seasonality)
data_prev_case$seasonality<-as.factor(data_prev_case$seasonality)
data_prev_case$age_prevalence<-as.character(data_prev_case$age_prevalence)
data_prev_case$age_prevalence<-as.factor(data_prev_case$age_prevalence)
data_prev_case$season_survey_prevalence<-as.character(data_prev_case$season_survey_prevalence)
data_prev_case$season_survey_prevalence<-as.factor(data_prev_case$season_survey_prevalence)
data_prev_case$time_prevalence_cat<-as.character(data_prev_case$time_prevalence_cat)
data_prev_case$time_prevalence_cat<-as.factor(data_prev_case$time_prevalence_cat)