-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract_tables.R
463 lines (382 loc) · 21 KB
/
extract_tables.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
# This script extracts individual tables for each figure from the main spreadsheet
rm(list=ls())
# Load libraries
library(dplyr)
library(tidyr)
# Load functions
source("R/recode_countries.R")
# Load spreadsheet
survey_data <- read.csv("data/Frontiers_data_V4.csv", stringsAsFactors = FALSE)
# Trim whitespace on country names
survey_data$country <- trimws(survey_data$country, which="right")
# Recode names to match between data
survey_data <- recode_countries(survey_data, "country")
# Recode endemic status
survey_data$progress.in.rabies.control..1free.2in.progress.3endemic <- ifelse(survey_data$progress.in.rabies.control..1free.2in.progress.3endemic==1, "Free",
ifelse(survey_data$progress.in.rabies.control..1free.2in.progress.3endemic==2, "In-progress", "Endemic"))
#----- Figure 1 ----------------------------------------------------------------
#----- Figure 1a
# Subset data
fig_1a <- survey_data %>%
dplyr::select(country, "endemic_status"=progress.in.rabies.control..1free.2in.progress.3endemic, interview) %>%
distinct()
# Fix interview status for countries with multiple rows
countries <- sort(unique(fig_1a$country))
for(i in countries){
# Get row index
indx = which(fig_1a$country == i)
# If there are multiple rows, remove the row with "no" in the interview column
if(length(indx)>1){
indx_rm = which(fig_1a$country == i & fig_1a$interview == "No")
fig_1a <- fig_1a[-indx_rm,]
}
}
# Save output
write.csv(fig_1a, "output/figure_1a.csv", row.names = FALSE)
#----- Figure 1b
# Subset data
fig_1b <- survey_data %>%
dplyr::select("endemic_status"=progress.in.rabies.control..1free.2in.progress.3endemic, "work_sector"=work.sector) %>%
group_by(work_sector, endemic_status) %>%
summarise(n = n())
# Collect totals
fig_1b_totals <- fig_1b %>%
group_by(work_sector) %>%
summarise(ord = sum(n)) %>%
arrange(desc(ord))
# Rearrange data based on totals
fig_1b <- fig_1b %>%
arrange(factor(work_sector, levels=fig_1b_totals$work_sector))
# Save output
write.csv(fig_1b, "output/figure_1b.csv", row.names = FALSE)
#----- Figure 2 ----------------------------------------------------------------
#----- Figure 2a
# Subset and process data
fig_2a <- survey_data %>%
dplyr::select(country, "endemic_status"=progress.in.rabies.control..1free.2in.progress.3endemic,
"disruption.to.mdv"=country.disruption.to.mdv) %>%
distinct() %>%
mutate("result" = ifelse(is.na(disruption.to.mdv), "Not available",
ifelse(disruption.to.mdv == "No", "No disruption",
ifelse(disruption.to.mdv == "Yes", "Disruption", NA)))) %>%
group_by(country, endemic_status, result) %>%
summarise(n = n())
# Fix interview status for countries with multiple rows
countries <- sort(unique(fig_2a$country))
for(i in countries){
# Get row index
indx = which(fig_2a$country == i)
# If there are multiple rows, keep the row with the highest number of responses
if(length(indx)>1){
indx_rm = which(fig_2a$country == i & fig_2a$n == min(fig_2a$n[indx]))
fig_2a <- fig_2a[-indx_rm,]
}
}
# CHECK
nrow(fig_2a)
table(fig_2a$endemic_status, fig_2a$result)
# Make final summary calculation
fig_2a <- fig_2a %>%
group_by(endemic_status, result) %>%
summarise(n=n())
# Save output
write.csv(fig_2a, "output/figure_2a.csv", row.names = FALSE)
#----- Figure 2b
# Subset and process data
fig_2b <- survey_data %>%
dplyr::select(country, "endemic_status"=progress.in.rabies.control..1free.2in.progress.3endemic,
"disruption.to.pep"=country.overall.disruption.to.PEP..people.s.health.seeking.behaviour...PEP.delivery.) %>%
distinct() %>%
mutate("result" = ifelse(is.na(disruption.to.pep), "Not available",
ifelse(disruption.to.pep == "No", "No disruption",
ifelse(disruption.to.pep == "Yes", "Disruption", NA)))) %>%
group_by(country, endemic_status, result) %>%
summarise(n = n())
# View(fig_2b[which(fig_2b$endemic_status=="In-progress"),])
# Fix interview status for countries with multiple rows
countries <- sort(unique(fig_2b$country))
for(i in countries){
# Get row index
indx = which(fig_2b$country == i)
# If there are multiple rows, keep the row with the highest number of responses
if(length(indx)>1){
indx_rm = which(fig_2b$country == i & fig_2b$n == min(fig_2b$n[indx]))
fig_2b <- fig_2b[-indx_rm,]
}
}
# CHECK
nrow(fig_2b)
table(fig_2b$endemic_status, fig_2b$result)
# Make final summary calculation
fig_2b <- fig_2b %>%
group_by(endemic_status, result) %>%
summarise(n=n())
# Save output
write.csv(fig_2b, "output/figure_2b.csv", row.names = FALSE)
#----- Figure 2c
# Subset and process data
fig_2c <- survey_data %>%
dplyr::select(country, "endemic_status"=progress.in.rabies.control..1free.2in.progress.3endemic,
"disruption.to.awareness.activities"=country.disruption.to.awareness.activities) %>%
distinct() %>%
mutate("result" = ifelse(is.na(disruption.to.awareness.activities), "Not available",
ifelse(disruption.to.awareness.activities == "No", "No disruption",
ifelse(disruption.to.awareness.activities == "Yes", "Disruption", NA)))) %>%
group_by(country, endemic_status, result) %>%
summarise(n = n())
# CHECK
nrow(fig_2c)
table(fig_2c$endemic_status, fig_2c$result)
# Make final summary calculation
fig_2c <- fig_2c %>%
group_by(endemic_status, result) %>%
summarise(n=n())
# Save output
write.csv(fig_2c, "output/figure_2c.csv", row.names = FALSE)
#----- Figure 3 ----------------------------------------------------------------
#----- Figure 3a (disruption to MDV)
# Subset and process data
fig_3a <- survey_data %>%
dplyr::select(country, "endemic_status"=progress.in.rabies.control..1free.2in.progress.3endemic,
no.staff.available, restrictions.on.staff.movement, no.vaccines.available,
no.consumables.available, difficult.to.adhere.to.COVID.19.guidelines,
people.afraid.of.leaving.home.gathering, increased.cost.of.organizing,
other2) %>%
gather(., question, response, no.staff.available:increased.cost.of.organizing) %>%
group_by(country, endemic_status, question) %>%
summarise(n=sum(response)) %>%
# Remove all zero response
filter(n > 0) %>%
# Make all country results equal
mutate(n = 1) %>%
# Recode result names
mutate(grouped_response = ifelse(question == "restrictions.on.staff.movement", "Movement restrictions", # "Restrictions on staff movement",
ifelse(question == "difficult.to.adhere.to.COVID.19.guidelines", "COVID-19 safety*", # "Difficult to adhere to COVID-19 guidelines",
ifelse(question == "people.afraid.of.leaving.home.gathering", "Fears*", # "People afraid of leaving home/gathering",
ifelse(question == "no.vaccines.available", "No/limited vaccines", # "No/limited vaccines available",
ifelse(question == "no.staff.available", "Staff shortages", # "No staff available",
ifelse(question == "increased.cost.of.organizing", "Increased costs", # "Increased cost of organizing",
ifelse(question == "no.consumables.available", "Lacking consumables", NA)))))))) %>% # "No consumables available",
group_by(endemic_status, grouped_response) %>%
summarise(n=sum(n))
# Collect totals
fig_3a_totals <- fig_3a %>%
group_by(grouped_response) %>%
summarise(ord = sum(n)) %>%
arrange(desc(ord))
# Rearrange data based on totals
fig_3a <- fig_3a %>%
arrange(factor(grouped_response, levels=fig_3a_totals$grouped_response))
# Save output
write.csv(fig_3a, "output/figure_3a.csv", row.names = FALSE)
#----- Figure 3b (disruption to access to PEP)
# Subset and process data
fig_3b <- survey_data %>%
dplyr::select(country, "endemic_status"=progress.in.rabies.control..1free.2in.progress.3endemic,
people.have.avoided.clinics.due.to.fear.of.COVID.19, people.cannot.afford.travel,
people.cannot.reach.clinics.because.of.reduced.public.transport,
people.have.delayed.going.to.clinics, people.have.relied.more.on.local.remedies,
people.have.used.toll.free.numbers.telemedicine, people.have.interrupted.PEP) %>%
gather(., question, response, people.have.avoided.clinics.due.to.fear.of.COVID.19:people.have.interrupted.PEP) %>%
group_by(country, endemic_status, question) %>%
summarise(n=sum(response)) %>%
# Remove all zero response
filter(n > 0) %>%
# Make all country results equal
mutate(n = 1) %>%
# Recode result names
mutate(grouped_response = ifelse(question == "people.have.avoided.clinics.due.to.fear.of.COVID.19", "Fears*", # "People feared COVID-19 in clinics",
ifelse(question == "people.cannot.afford.travel", "Transport cost", # "People could not afford travel",
ifelse(question == "people.cannot.reach.clinics.because.of.reduced.public.transport", "No public transport", # "People could not use public transportation",
ifelse(question == "people.have.delayed.going.to.clinics", "Delayed", # "People delayed going to clinics",
ifelse(question == "people.have.relied.more.on.local.remedies", "Used local healers/remedies", # "People relied on local remedies/healers",
ifelse(question == "people.have.used.toll.free.numbers.telemedicine", "Telemedicine", # "People used toll-free numbers/telemedicine",
ifelse(question == "people.have.interrupted.PEP", "Interrupted schedule", NA)))))))) %>% # "People interrupted the vaccination schedule",
group_by(endemic_status, grouped_response) %>%
summarise(n=sum(n))
# Collect totals
fig_3b_totals <- fig_3b %>%
group_by(grouped_response) %>%
summarise(ord = sum(n)) %>%
arrange(desc(ord))
# Rearrange data based on totals
fig_3b <- fig_3b %>%
arrange(factor(grouped_response, levels=fig_3b_totals$grouped_response))
# Save output
write.csv(fig_3b, "output/figure_3b.csv", row.names = FALSE)
#----- Figure 3c (disruption to delivery of PEP)
# Subset and process data
fig_3c <- survey_data %>%
mutate(vaccines.out.of.stock = ifelse(vaccines.out.of.stock.because.of.financial.constraints == 1 |
vaccines.out.of.stock.because.of.supply.issues == 1,
1, 0),
staff.less.diligent = ifelse(staff.less.diligent.due.to.stress == 1 |
staff.less.likely.to.recommend.PEP == 1,
1, 0)) %>%
dplyr::select(country, "endemic_status"=progress.in.rabies.control..1free.2in.progress.3endemic,
some.many.clinics.closed.converted, staff.redeployed, staff.reduced.due.to.quarantine.illness,
staff.less.diligent, follow.up.shots.delayed.cancelled, vaccines.out.of.stock,
vaccines.available.only.in.the.private.sector) %>%
gather(., question, response, some.many.clinics.closed.converted:vaccines.available.only.in.the.private.sector) %>%
group_by(country, endemic_status, question) %>%
summarise(n=sum(response)) %>%
# Remove all zero response
filter(n > 0) %>%
# Make all country results equal
mutate(n = 1) %>%
# Recode result names
mutate(grouped_response = ifelse(question == "some.many.clinics.closed.converted", "Clinics closed", # "Clinics closed/converted",
ifelse(question == "staff.redeployed", "Staff redeployment", # "Staff redeployed",
ifelse(question == "staff.reduced.due.to.quarantine.illness", "Staff absences", # "Staff reduced due to quarantine/illness",
ifelse(question == "staff.less.diligent", "Staff stress", # "Staff less diligant due to stress/vaccine shortage",
ifelse(question == "follow.up.shots.delayed.cancelled", "Follow up visits delayed/cancelled", # "Follow up vaccines delayed/cancelled",
ifelse(question == "vaccines.out.of.stock", "Vaccine shortages", # "No vaccines available",
ifelse(question == "vaccines.available.only.in.the.private.sector", "Vaccines only in private sector", NA)))))))) %>% # "Vaccines available only/mostly \nin the private sector",
group_by(endemic_status, grouped_response) %>%
summarise(n=sum(n))
# Collect totals
fig_3c_totals <- fig_3c %>%
group_by(grouped_response) %>%
summarise(ord = sum(n)) %>%
arrange(desc(ord))
# Rearrange data based on totals
fig_3c <- fig_3c %>%
arrange(factor(grouped_response, levels=fig_3c_totals$grouped_response))
# Save output
write.csv(fig_3c, "output/figure_3c.csv", row.names = FALSE)
#----- Figure 3d (disruption to surveillance)
# Subset and process data
fig_3d <- survey_data %>%
dplyr::select(country, "endemic_status"=progress.in.rabies.control..1free.2in.progress.3endemic,
no.staff.available.1, restrictions.on.staff.movement.1,
no.sample.collection.testing.kit.available,
no.budget, difficult.to.adhere.to.COVID.19.guidelines.1,
investigators.not.welcome.in.communities, other7) %>%
gather(., question, response, no.staff.available.1:other7) %>%
group_by(country, endemic_status, question) %>%
summarise(n=sum(response)) %>%
# Remove all zero response
filter(n > 0) %>%
# Make all country results equal
mutate(n = 1) %>%
# Recode result names
mutate(grouped_response = ifelse(question == "no.staff.available.1", "Staff shortages", # "No staff available",
ifelse(question == "restrictions.on.staff.movement.1", "Movement restrictions", # "Restrictions on staff movements",
ifelse(question == "no.sample.collection.testing.kit.available", "No consumables/equipment", # "No sample collection/testing kits available",
ifelse(question == "no.budget", "No budget", # "No budget",
ifelse(question == "difficult.to.adhere.to.COVID.19.guidelines.1", "COVID-19 safety*", # "Difficult to adhere to COVID-19 guidelines",
ifelse(question == "investigators.not.welcome.in.communities", "Investigators not welcome", # "Investigators not welcome in communities",
ifelse(question == "other7", "Other", NA)))))))) %>%
group_by(endemic_status, grouped_response) %>%
summarise(n=sum(n))
# Collect totals
fig_3d_totals <- fig_3d %>%
group_by(grouped_response) %>%
summarise(ord = sum(n)) %>%
arrange(desc(ord))
# Rearrange data based on totals
fig_3d <- fig_3d %>%
arrange(factor(grouped_response, levels=fig_3d_totals$grouped_response))
# Save output
write.csv(fig_3d, "output/figure_3d.csv", row.names = FALSE)
#----- Figure 4 ----------------------------------------------------------------
#----- Figure 4a (changes in free-roaming dog pops and behaviour)
# Subset and process data
fig_4a <- survey_data %>%
dplyr::select(country, "endemic_status"=progress.in.rabies.control..1free.2in.progress.3endemic,
more.free.roaming.dogs, fewer.free.roaming.dogs, dogs.more.aggressive,
dogs.in.poorer.health) %>%
gather(., question, response, more.free.roaming.dogs:dogs.in.poorer.health) %>%
group_by(country, endemic_status, question) %>%
summarise(n=sum(response)) %>%
# Remove all zero response
filter(n > 0) %>%
# Make all country results equal
mutate(n = 1) %>%
group_by(endemic_status, question) %>%
summarise(n=sum(n))
# Recode question responses
fig_4a$question[which(fig_4a$question=="more.free.roaming.dogs")] <- "More dogs" # "More free-roaming dogs"
fig_4a$question[which(fig_4a$question=="fewer.free.roaming.dogs")] <- "Fewer dogs" # "Fewer free-roaming dogs"
fig_4a$question[which(fig_4a$question=="dogs.more.aggressive")] <- "More aggression" # "Dogs more aggressive"
fig_4a$question[which(fig_4a$question=="dogs.in.poorer.health")] <- "Poorer health" # "Dogs in poorer health"
# Collect totals
fig_4a_totals <- fig_4a %>%
group_by(question) %>%
summarise(ord = sum(n)) %>%
arrange(desc(ord))
# Rearrange data based on totals
fig_4a <- fig_4a %>%
arrange(factor(question, levels=fig_4a_totals$question))
# Save output
write.csv(fig_4a, "output/figure_4a.csv", row.names = FALSE)
#----- Figure 4b (changes in human-dog interactions)
# Subset and process data
fig_4b <- survey_data %>%
dplyr::select(country, "endemic_status"=progress.in.rabies.control..1free.2in.progress.3endemic,
more.people.fed.them, people.complained.asked.for.solutions,
people.removed.killed.them, local.authority.removed.killed.them,
more.abandonment.due.to.fear.of.COVID.19,
more.abandonment.due.to.financial.constraints,
more.abandonment.due.to.other.reasons,) %>%
gather(., question, response, more.people.fed.them:more.abandonment.due.to.other.reasons) %>%
group_by(country, endemic_status, question) %>%
summarise(n=sum(response)) %>%
# Remove all zero response
filter(n > 0) %>%
# Make all country results equal
mutate(n = 1) %>%
group_by(endemic_status, question) %>%
summarise(n=sum(n))
# Recode question responses
fig_4b$question[which(fig_4b$question=="more.people.fed.them")] <- "More feeding of free-roaming dogs" # "More people fed them"
fig_4b$question[which(fig_4b$question=="people.complained.asked.for.solutions")] <- "Complaints/requests for intervention" # "Complaints/requests" # "People complained/asked for solutions"
fig_4b$question[which(fig_4b$question=="people.removed.killed.them")] <- "Communities removed/killed dogs" # "People removed/killed them"
fig_4b$question[which(fig_4b$question=="local.authority.removed.killed.them")] <- "Officials removed/killed dogs" # "Official workers removed/killed them"
fig_4b$question[which(fig_4b$question=="more.abandonment.due.to.fear.of.COVID.19")] <- "Abandonment (fear of COVID-19)" # "Abandonment (fear)" # "Abandonment due to fear of COVID-19"
fig_4b$question[which(fig_4b$question=="more.abandonment.due.to.financial.constraints")] <- "Abandonment (dog-keeping costs)" # "Abandonment (cost)" # "Abandonment due to financial constraints"
fig_4b$question[which(fig_4b$question=="more.abandonment.due.to.other.reasons")] <- "Abandonment (other reasons)" # "Abandonment due to other reasons"
# Collect totals
fig_4b_totals <- fig_4b %>%
group_by(question) %>%
summarise(ord = sum(n)) %>%
arrange(desc(ord))
# Rearrange data based on totals
fig_4b <- fig_4b %>%
arrange(factor(question, levels=fig_4b_totals$question))
# Save output
write.csv(fig_4b, "output/figure_4b.csv", row.names = FALSE)
#----- Figure 4c (changes in media reporting of dogs)
# Subset and process data
fig_4c <- survey_data %>%
dplyr::select(country, "endemic_status"=progress.in.rabies.control..1free.2in.progress.3endemic,
attacks.on.dogs, attacks.on.other.animals, attacks.on.humans,
animal.rabies.cases.deaths, human.exposures.deaths, human.cruelty,
care) %>%
gather(., question, response, attacks.on.dogs:care) %>%
group_by(country, endemic_status, question) %>%
summarise(n=sum(response)) %>%
# Remove all zero response
filter(n > 0) %>%
# Make all country results equal
mutate(n = 1) %>%
group_by(endemic_status, question) %>%
summarise(n=sum(n))
# Recode question responses
fig_4c$question[which(fig_4c$question=="attacks.on.dogs")] <- "More attacks on dogs" # "More attacks on dogs"
fig_4c$question[which(fig_4c$question=="attacks.on.other.animals")] <- "More attacks on livestock" # "More attacks on other animals"
fig_4c$question[which(fig_4c$question=="attacks.on.humans")] <- "More attacks on people" # "More attacks on humans"
fig_4c$question[which(fig_4c$question=="animal.rabies.cases.deaths")] <- "More animal rabies" # "More animal rabies cases"
fig_4c$question[which(fig_4c$question=="human.exposures.deaths")] <- "More human exposures/deaths" # "More human rabies exposures/deaths"
fig_4c$question[which(fig_4c$question=="human.cruelty")] <- "More cruelty" # "More cases of human cruelty towards dogs"
fig_4c$question[which(fig_4c$question=="care")] <- "More care" # "More cases of human care towards dogs"
# Collect totals
fig_4c_totals <- fig_4c %>%
group_by(question) %>%
summarise(ord = sum(n)) %>%
arrange(desc(ord))
# Rearrange data based on totals
fig_4c <- fig_4c %>%
arrange(factor(question, levels=fig_4c_totals$question))
# Save output
write.csv(fig_4c, "output/figure_4c.csv", row.names = FALSE)