-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
512 lines (512 loc) · 31.4 KB
/
.Rhistory
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
}
stringbit = ""
}
i = i+1
}
if(nchar(stringbit) > 0){
new_string = paste0(new_string,"\n",stringbit)
}
return(new_string)
}
splitString(my_String)
splitString = function(string, max_chars = 15){
stringbits = strsplit(string, " ")[[1]]
new_string = ""
stringbit = ""
i = 1
while(i <= length(stringbits)){
if(nchar(stringbit) == 0){
stringbit = stringbits[i]
} else if(nchar(stringbit) < max_chars){
stringbit = paste(stringbit, stringbits[i])
} else {
if(nchar(new_string) == 0){
new_string = stringbit
} else {
new_string = paste0(new_string,"\n",stringbit)
}
stringbit = ""
}
i = i+1
}
if(nchar(stringbit) > 0){
new_string = paste0(new_string,"\n",stringbit)
}
return(new_string)
}
data.table(
characteristic = c("Role of host government", "Accessibility of pre-existing public health services", "Security environment", "Disease risk factors and burden") %>% sapply(splitString) %>% linebreak("l"),
scen_a = c("Relatively benign, non-oppressive entity (e.g. Somalia). Government has some control over the affected region and is perceived as legitimate (e.g. Burkina Faso)", "Moderate to good (e.g. the affected population has effective access to pre-existing health facilities offering routine vaccination; e.g. South Sudanese refugees in Uganda)", "Stable; populations have taken refuge in a secure region (e.g. most refugees). Low probability of further displacement", sprintf("Relatively low%s", footnote_marker_symbol(2))) %>% sapply(splitString(max_chars = 20)) %>% linebreak("l"),
scen_b = c("Involved in war crimes or otherwise hostile to parts/all of the affected population (e.g. South Sudan, Syria). Government is either not perceived as legitimate (e.g. Burma) or has limited/no control of the region (e.g. Afghanistan increasingly)", "Low or none (e.g. IDPs are in an unplanned site with no pre-existing health services, or the latter have minimal functionality/routine vaccination coverage (e.g. Tigray, Yemen)", "Volatile, with intermittent access to populations (e.g. Central African Republic, South Sudan, north-east Nigeria, or lake Chad region). High probability of further displacement", sprintf("Relatively high%s (particularly in the case of camp-based IDPs)", footnote_marker_symbol(2))) %>% sapply(splitString(max_chars = 20)) %>% linebreak("l")
) %>% kableExtra::kable(
caption="Relative best- and relative worst-case scenario for humanitarian PCV vaccination",
col.names=c("Characteristic", "Scenario A (best-case)", "Scenario B (worst-case)"),
booktabs=TRUE, escape=FALSE) %>%
kableExtra::kable_styling(latex_options = "HOLD_position") %>% footnote(symbol="Compared to the average crisis-affected population")
splitString = function(string, max_chars = 15){
stringbits = strsplit(string, " ")[[1]]
new_string = ""
stringbit = ""
i = 1
while(i <= length(stringbits)){
if(nchar(stringbit) == 0){
stringbit = stringbits[i]
} else if(nchar(stringbit) < max_chars){
stringbit = paste(stringbit, stringbits[i])
} else {
if(nchar(new_string) == 0){
new_string = stringbit
} else {
new_string = paste0(new_string,"\n",stringbit)
}
stringbit = ""
}
i = i+1
}
if(nchar(stringbit) > 0){
new_string = paste0(new_string,"\n",stringbit)
}
return(new_string)
}
data.table(
characteristic = c("Role of host government", "Accessibility of pre-existing public health services", "Security environment", "Disease risk factors and burden") %>% sapply(splitString) %>% linebreak("l"),
scen_a = c("Relatively benign, non-oppressive entity (e.g. Somalia). Government has some control over the affected region and is perceived as legitimate (e.g. Burkina Faso)", "Moderate to good (e.g. the affected population has effective access to pre-existing health facilities offering routine vaccination; e.g. South Sudanese refugees in Uganda)", "Stable; populations have taken refuge in a secure region (e.g. most refugees). Low probability of further displacement", sprintf("Relatively low%s", footnote_marker_symbol(2))) %>% sapply(function(x) splitString(x, max_chars = 20)) %>% linebreak("l"),
scen_b = c("Involved in war crimes or otherwise hostile to parts/all of the affected population (e.g. South Sudan, Syria). Government is either not perceived as legitimate (e.g. Burma) or has limited/no control of the region (e.g. Afghanistan increasingly)", "Low or none (e.g. IDPs are in an unplanned site with no pre-existing health services, or the latter have minimal functionality/routine vaccination coverage (e.g. Tigray, Yemen)", "Volatile, with intermittent access to populations (e.g. Central African Republic, South Sudan, north-east Nigeria, or lake Chad region). High probability of further displacement", sprintf("Relatively high%s (particularly in the case of camp-based IDPs)", footnote_marker_symbol(2))) %>% sapply(function(x) splitString(x, max_chars = 20)) %>% linebreak("l")
) %>% kableExtra::kable(
caption="Relative best- and relative worst-case scenario for humanitarian PCV vaccination",
col.names=c("Characteristic", "Scenario A (best-case)", "Scenario B (worst-case)"),
booktabs=TRUE, escape=FALSE) %>%
kableExtra::kable_styling(latex_options = "HOLD_position") %>% footnote(symbol="Compared to the average crisis-affected population")
splitString = function(string, max_chars = 15){
stringbits = strsplit(string, " ")[[1]]
new_string = ""
stringbit = ""
i = 1
while(i <= length(stringbits)){
if(nchar(stringbit) == 0){
stringbit = stringbits[i]
} else if(nchar(stringbit) < max_chars){
stringbit = paste(stringbit, stringbits[i])
} else {
if(nchar(new_string) == 0){
new_string = stringbit
} else {
new_string = paste0(new_string,"\n",stringbit)
}
stringbit = ""
}
i = i+1
}
if(nchar(stringbit) > 0){
new_string = paste0(new_string,"\n",stringbit)
}
return(new_string)
}
data.table(
characteristic = c("Role of host government", "Accessibility of pre-existing public health services", "Security environment", "Disease risk factors and burden") %>% sapply(function(x) splitString(x, max_chars = 12)) %>% linebreak("l"),
scen_a = c("Relatively benign, non-oppressive entity (e.g. Somalia). Government has some control over the affected region and is perceived as legitimate (e.g. Burkina Faso)", "Moderate to good (e.g. the affected population has effective access to pre-existing health facilities offering routine vaccination; e.g. South Sudanese refugees in Uganda)", "Stable; populations have taken refuge in a secure region (e.g. most refugees). Low probability of further displacement", sprintf("Relatively low%s", footnote_marker_symbol(2))) %>% sapply(function(x) splitString(x, max_chars = 16)) %>% linebreak("l"),
scen_b = c("Involved in war crimes or otherwise hostile to parts/all of the affected population (e.g. South Sudan, Syria). Government is either not perceived as legitimate (e.g. Burma) or has limited/no control of the region (e.g. Afghanistan increasingly)", "Low or none (e.g. IDPs are in an unplanned site with no pre-existing health services, or the latter have minimal functionality/routine vaccination coverage (e.g. Tigray, Yemen)", "Volatile, with intermittent access to populations (e.g. Central African Republic, South Sudan, north-east Nigeria, or lake Chad region). High probability of further displacement", sprintf("Relatively high%s (particularly in the case of camp-based IDPs)", footnote_marker_symbol(2))) %>% sapply(function(x) splitString(x, max_chars = 16)) %>% linebreak("l")
) %>% kableExtra::kable(
caption="Relative best- and relative worst-case scenario for humanitarian PCV vaccination",
col.names=c("Characteristic", "Scenario A (best-case)", "Scenario B (worst-case)"),
booktabs=TRUE, escape=FALSE) %>%
kableExtra::kable_styling(latex_options = "HOLD_position") %>% footnote(symbol="Compared to the average crisis-affected population")
c("Involved in war crimes or otherwise hostile to parts/all of the affected population (e.g. South Sudan, Syria). Government is either not perceived as legitimate (e.g. Burma) or has limited/no control of the region (e.g. Afghanistan increasingly)", "Low or none (e.g. IDPs are in an unplanned site with no pre-existing health services, or the latter have minimal functionality/routine vaccination coverage (e.g. Tigray, Yemen)", "Volatile, with intermittent access to populations (e.g. Central African Republic, South Sudan, north-east Nigeria, or lake Chad region). High probability of further displacement", sprintf("Relatively high%s (particularly in the case of camp-based IDPs)", footnote_marker_symbol(2))) %>% sapply(function(x) splitString(x, max_chars = 16))
scen_b = c("Involved in war crimes or otherwise hostile to parts/all of the affected population (e.g. South Sudan, Syria). Government is either not perceived as legitimate (e.g. Burma) or has limited/no control of the region (e.g. Afghanistan increasingly)", "Low or none (e.g. IDPs are in an unplanned site with no pre-existing health services, or the latter have minimal functionality/routine vaccination coverage (e.g. Tigray, Yemen)", "Volatile, with intermittent access to populations (e.g. Central African Republic, South Sudan, north-east Nigeria, or lake Chad region). High probability of further displacement", sprintf("Relatively high%s (particularly in the case of camp-based IDPs)", footnote_marker_symbol(2))) %>% sapply(function(x) splitString(x, max_chars = 10))
c("Involved in war crimes or otherwise hostile to parts/all of the affected population (e.g. South Sudan, Syria). Government is either not perceived as legitimate (e.g. Burma) or has limited/no control of the region (e.g. Afghanistan increasingly)", "Low or none (e.g. IDPs are in an unplanned site with no pre-existing health services, or the latter have minimal functionality/routine vaccination coverage (e.g. Tigray, Yemen)", "Volatile, with intermittent access to populations (e.g. Central African Republic, South Sudan, north-east Nigeria, or lake Chad region). High probability of further displacement", sprintf("Relatively high%s (particularly in the case of camp-based IDPs)", footnote_marker_symbol(2))) %>% sapply(function(x) splitString(x, max_chars = 10))
c("Involved in war crimes or otherwise hostile to parts/all of the affected population (e.g. South Sudan, Syria). Government is either not perceived as legitimate (e.g. Burma) or has limited/no control of the region (e.g. Afghanistan increasingly)", "Low or none (e.g. IDPs are in an unplanned site with no pre-existing health services, or the latter have minimal functionality/routine vaccination coverage (e.g. Tigray, Yemen)", "Volatile, with intermittent access to populations (e.g. Central African Republic, South Sudan, north-east Nigeria, or lake Chad region). High probability of further displacement", sprintf("Relatively high%s (particularly in the case of camp-based IDPs)", footnote_marker_symbol(2))) %>% sapply(function(x) splitString(x, max_chars = 10))
c("Involved in war crimes or otherwise hostile to parts/all of the affected population (e.g. South Sudan, Syria). Government is either not perceived as legitimate (e.g. Burma) or has limited/no control of the region (e.g. Afghanistan increasingly)", "Low or none (e.g. IDPs are in an unplanned site with no pre-existing health services, or the latter have minimal functionality/routine vaccination coverage (e.g. Tigray, Yemen)", "Volatile, with intermittent access to populations (e.g. Central African Republic, South Sudan, north-east Nigeria, or lake Chad region). High probability of further displacement", sprintf("Relatively high%s (particularly in the case of camp-based IDPs)", footnote_marker_symbol(2))) %>% sapply(function(x) splitString(x, max_chars = 10))
data.table(
characteristic = c("Role of host government", "Accessibility of pre-existing public health services", "Security environment", "Disease risk factors and burden") %>% sapply(function(x) splitString(x, max_chars = 10)) %>% linebreak("l"),
scen_a = c("Relatively benign, non-oppressive entity (e.g. Somalia). Government has some control over the affected region and is perceived as legitimate (e.g. Burkina Faso)", "Moderate to good (e.g. the affected population has effective access to pre-existing health facilities offering routine vaccination; e.g. South Sudanese refugees in Uganda)", "Stable; populations have taken refuge in a secure region (e.g. most refugees). Low probability of further displacement", sprintf("Relatively low%s", footnote_marker_symbol(2))) %>% sapply(function(x) splitString(x, max_chars = 10)) %>% linebreak("l"),
scen_b = c("Involved in war crimes or otherwise hostile to parts/all of the affected population (e.g. South Sudan, Syria). Government is either not perceived as legitimate (e.g. Burma) or has limited/no control of the region (e.g. Afghanistan increasingly)", "Low or none (e.g. IDPs are in an unplanned site with no pre-existing health services, or the latter have minimal functionality/routine vaccination coverage (e.g. Tigray, Yemen)", "Volatile, with intermittent access to populations (e.g. Central African Republic, South Sudan, north-east Nigeria, or lake Chad region). High probability of further displacement", sprintf("Relatively high%s (particularly in the case of camp-based IDPs)", footnote_marker_symbol(2))) %>% sapply(function(x) splitString(x, max_chars = 10)) %>% linebreak("l")
)
data.table(
characteristic = c("Role of host government", "Accessibility of pre-existing public health services", "Security environment", "Disease risk factors and burden") %>% sapply(function(x) splitString(x, max_chars = 10)) %>% linebreak("l"),
scen_a = c("Relatively benign, non-oppressive entity (e.g. Somalia). Government has some control over the affected region and is perceived as legitimate (e.g. Burkina Faso)", "Moderate to good (e.g. the affected population has effective access to pre-existing health facilities offering routine vaccination; e.g. South Sudanese refugees in Uganda)", "Stable; populations have taken refuge in a secure region (e.g. most refugees). Low probability of further displacement", sprintf("Relatively low%s", footnote_marker_symbol(2))) %>% sapply(function(x) splitString(x, max_chars = 10)) %>% linebreak("l"),
scen_b = c("Involved in war crimes or otherwise hostile to parts/all of the affected population (e.g. South Sudan, Syria). Government is either not perceived as legitimate (e.g. Burma) or has limited/no control of the region (e.g. Afghanistan increasingly)", "Low or none (e.g. IDPs are in an unplanned site with no pre-existing health services, or the latter have minimal functionality/routine vaccination coverage (e.g. Tigray, Yemen)", "Volatile, with intermittent access to populations (e.g. Central African Republic, South Sudan, north-east Nigeria, or lake Chad region). High probability of further displacement", sprintf("Relatively high%s (particularly in the case of camp-based IDPs)", footnote_marker_symbol(2))) %>% sapply(function(x) splitString(x, max_chars = 10)) %>% linebreak("l")
)
splitString("Involved in war crimes or otherwise")
splitString("Involved in war crimes or otherwise") %>% linebreak("l")
?linebreak
splitString("Involved in war crimes or otherwise") %>% linebreak("l", TRUE)
splitString("Involved in war crimes or otherwise") %>% linebreak("l", linebreaker="\n")
splitString("Involved in war crimes or otherwise") %>% linebreak("l", linebreaker="<br>")
splitString("Involved in war crimes or otherwise")
(string = "Involved in war crimes or otherwise")
string
stringbits = strsplit(string, " ")[[1]]
stringbits
new_string = ""
stringbit = ""
i = 1
if(nchar(stringbit) == 0){
stringbit = stringbits[i]
} else if(nchar(stringbit) < max_chars){
stringbit = paste(stringbit, stringbits[i])
} else {
if(nchar(new_string) == 0){
new_string = stringbit
} else {
new_string = paste0(new_string,"\n",stringbit)
}
stringbit = ""
}
i = i+1
if(nchar(stringbit) == 0){
stringbit = stringbits[i]
} else if(nchar(stringbit) < max_chars){
stringbit = paste(stringbit, stringbits[i])
} else {
if(nchar(new_string) == 0){
new_string = stringbit
} else {
new_string = paste0(new_string,"\n",stringbit)
}
stringbit = ""
}
if(nchar(stringbit) == 0){
stringbit = stringbits[i]
} else if(nchar(stringbit) < max_chars){
stringbit = paste(stringbit, stringbits[i])
} else {
if(nchar(new_string) == 0){
new_string = stringbit
} else {
new_string = paste0(new_string,"\n",stringbit)
}
stringbit = ""
}
i = i+1
stringbit
i
i <= length(stringbits)
nchar(stringbit) == 0
nchar(stringbit) < max_chars
stringbits[i]
stringbit = paste(stringbit, stringbits[i])
stringbit
i = i+1
nchar(stringbit) < max_chars
new_string = ""
stringbit = ""
i = 1
while(i <= length(stringbits)){
if(nchar(stringbit) == 0){
stringbit = stringbits[i]
} else if(nchar(stringbit) < max_chars){
stringbit = paste(stringbit, stringbits[i])
} else {
if(nchar(new_string) == 0){
new_string = stringbit
} else {
new_string = paste0(new_string,"\n",stringbit)
}
stringbit = ""
}
i = i+1
}
new_string
stringbit
stringbits = strsplit(string, " ")[[1]]
stringbits
new_string = ""
stringbit = ""
i = 1
if(nchar(stringbit) == 0){
stringbit = stringbits[i]
} else if(nchar(stringbit) < max_chars){
stringbit = paste(stringbit, stringbits[i])
} else {
if(nchar(new_string) == 0){
new_string = stringbit
} else {
new_string = paste0(new_string,"\n",stringbit)
}
stringbit = ""
}
i = i+1
if(nchar(stringbit) == 0){
stringbit = stringbits[i]
} else if(nchar(stringbit) < max_chars){
stringbit = paste(stringbit, stringbits[i])
} else {
if(nchar(new_string) == 0){
new_string = stringbit
} else {
new_string = paste0(new_string,"\n",stringbit)
}
stringbit = ""
}
i = i+1
i
nchar(stringbit) == 0
nchar(stringbit) < max_chars
stringbit
new_string = ""
stringbit = ""
i = 1
if(nchar(stringbit) == 0){
stringbit = stringbits[i]
} else if(nchar(stringbit) < max_chars){
stringbit = paste(stringbit, stringbits[i])
} else {
if(nchar(new_string) == 0){
new_string = stringbit
} else {
new_string = paste0(new_string,"\n",stringbit)
}
stringbit = ""
}
i = i+1
i
if(nchar(stringbit) == 0){
stringbit = stringbits[i]
} else if(nchar(stringbit) < max_chars){
stringbit = paste(stringbit, stringbits[i])
} else {
if(nchar(new_string) == 0){
new_string = stringbit
} else {
new_string = paste0(new_string,"\n",stringbit)
}
stringbit = ""
}
i = i+1
i
stringbit
if(nchar(stringbit) == 0){
stringbit = stringbits[i]
} else if(nchar(stringbit) < max_chars){
stringbit = paste(stringbit, stringbits[i])
} else {
if(nchar(new_string) == 0){
new_string = stringbit
} else {
new_string = paste0(new_string,"\n",stringbit)
}
stringbit = ""
}
i = i+1
i
stringbit
nchar(stringbit) < max_chars
nchar(new_string) == 0
stringbit
new_string = ""
stringbit = ""
i = 1
while(i <= length(stringbits)){
if(nchar(stringbit) == 0){
stringbit = stringbits[i]
i = i+1
} else if(nchar(stringbit) < max_chars){
stringbit = paste(stringbit, stringbits[i])
i = i+1
} else {
if(nchar(new_string) == 0){
new_string = stringbit
} else {
new_string = paste0(new_string,"\n",stringbit)
}
stringbit = ""
}
}
new_string
stringbit
caption="Relative best- and relative worst-case scenario for humanitarian PCV vaccination",
human_responses = fread("./data/humanitarian_responses.csv")
human_responses %>% setorder(type, position) %>% .[, -c("type", "position")]
human_responses[type == "idp"]
human_responses[type == "idp", .N]
?footnote
#company_id = 'CIK0001318605'
company_id = 'CIK0001618835'
#company_id = 'CIK0001411690'
company_facts_url = sprintf('https://data.sec.gov/api/xbrl/companyfacts/%s.json', company_id)
request = httr::GET(url=company_facts_url)
#' We check the return code passed by the server. If the server is configured
#' correctly, we should receive a 200 code (success)
if(request$status_code != 200){
stop("Something went wrong")
}
request = httr::GET(url=company_facts_url)
#' We check the return code passed by the server. If the server is configured
#' correctly, we should receive a 200 code (success)
if(request$status_code != 200){
stop("Something went wrong")
}
request = httr::GET(url=company_facts_url)
#' We check the return code passed by the server. If the server is configured
#' correctly, we should receive a 200 code (success)
if(request$status_code != 200){
stop("Something went wrong")
}
#' If the request was succesful, we can use the content function to retrieve the
#' response from our request. If all went well, we should receive a HTML
#' document.
#' The text on the webpage is encoded as 'Windows-1252'. We need to specify this
#' to the content function to allow it to properly read the page.
#' The content function will automatically parse this as an xml_document (which
#' is an R data type from the xml2 package)
response = httr::content(request, type='application/json', as='parsed')
common_stock_outstanding = response$facts$dei$EntityCommonStockSharesOutstanding$units$shares %>% lapply(as.data.table) %>% rbindlist(fill=T) %>%
.[, date_end := as.Date(end)]
common_stock_outstanding %>% ggplot(aes(x=date_end, y=val))+geom_point()
public_float = response$facts$dei$EntityPublicFloat$units$USD %>% lapply(as.data.table) %>% rbindlist(fill=T) %>%
.[, date_end := as.Date(end)]
public_float %>% ggplot(aes(x=date_end, y=val))+geom_point()
common_stock_outstanding %>% merge(public_float, by="frame") %>% .[!is.na(frame)] %>% .[, float_per_share := val.y/val.x] %>% ggplot(aes(x=date_end.x, xend=date_end.y, y=float_per_share, yend=float_per_share))+geom_segment()
response$facts$`us-gaap`$Assets$units$USD %>% lapply(as.data.table) %>% rbindlist(fill=T) %>% .[, date_end := as.Date(end)] %>% ggplot(aes(x=date_end, y=val))+geom_point()
response$facts$`us-gaap`$DebtCurrent$units$USD %>% lapply(as.data.table) %>% rbindlist(fill=T) %>% .[, date_end := as.Date(end)] %>% ggplot(aes(x=date_end, y=val))+geom_point()
response$facts$`us-gaap`$LongTermDebtCurrent$units$USD %>% lapply(as.data.table) %>% rbindlist(fill=T) %>% .[, date_end := as.Date(end)] %>% ggplot(aes(x=date_end, y=val))+geom_point()
response$facts$`us-gaap`$Cash$units$USD %>% lapply(as.data.table) %>% rbindlist(fill=T) %>% .[, date_end := as.Date(end)] %>% ggplot(aes(x=date_end, y=val))+geom_point()
response$facts$`us-gaap`$DebtCurrent$units$USD %>% lapply(as.data.table) %>% rbindlist(fill=T) %>% .[, date_end := as.Date(end)] %>% ggplot(aes(x=date_end, y=val))+geom_point()
response$facts$`us-gaap`$LongTermDebtCurrent$units$USD %>% lapply(as.data.table) %>% rbindlist(fill=T) %>% .[, date_end := as.Date(end)] %>% ggplot(aes(x=date_end, y=val))+geom_point()
response$facts$`us-gaap`$Cash$units$USD %>% lapply(as.data.table) %>% rbindlist(fill=T) %>% .[, date_end := as.Date(end)] %>% ggplot(aes(x=date_end, y=val))+geom_point()
1/0.1331
1/0.3935
48444/12
library("socialmixr")
socialmixr::list_surveys()
socialmixr::get_survey("https://zenodo.org/record/5226281#.YR-TzlvTVH6")
pacman::p_load(magrittr, socialmixr)
digaale_contact_data = socialmixr::get_survey("https://zenodo.org/record/5226281#.YR-TzlvTVH6")
digaale_contact_data %>% attributes()
digaale_contact_data %>% attr()
ls))
ls()
digaale_survey_population = read.csv("https://zenodo.org/record/5226281/files/espicc_somaliland_digaale_survey_population.csv")
digaale_survey_population
digaale_contact_data %>%
socialmixr::contact_matrix(survey.pop = digaale_survey_population, age.limits = digaale_survey_population$lower.age.limit, symmetric = TRUE, weights = "survey_weight", weigh.dayofweek = TRUE)
digaale_contact_data %>%
socialmixr::contact_matrix(survey.pop = digaale_survey_population, age.limits = digaale_survey_population$lower.age.limit, symmetric = TRUE, weights = "survey_weight", weigh.dayofweek = TRUE) %>%
image()
digaale_contact_data %>%
socialmixr::contact_matrix(survey.pop = digaale_survey_population, age.limits = digaale_survey_population$lower.age.limit, symmetric = TRUE, weights = "survey_weight", weigh.dayofweek = TRUE) %>%
.[["matrix"]] %>% image()
digaale_contact_data$participants
digaale_contact_data$participants[, c("dayofweek", "weekend")]
digaale_contact_data$participants[, c("dayofweek", "weekend")] %>% unique
digaale_contact_data$participants[, c("dayofweek", "dayofweek_name", "weekend")] %>% unique
digaale_contact_data$participants[, c("dayofweek", "dayofweek_name", "weekend")] %>% unique %>% setorder(dayofweek) %>% .[]
pacman::p_load(magrittr, socialmixr, data.table)
digaale_contact_data$participants[, c("dayofweek", "dayofweek_name", "weekend")] %>% unique %>% setorder(dayofweek) %>% .[]
digaale_contact_data$participants[, c("dayofweek", "dayofweek_name", "weekend")] %>% unique %>% setorder(dayofweek) %>%
.[, newdayofweek := dayofweek - 1]
digaale_contact_data$participants[, c("dayofweek", "dayofweek_name", "weekend")] %>% unique %>% setorder(dayofweek) %>%
.[, newdayofweek := dayofweek - 1] %>% .[]
digaale_contact_data$participants[, c("dayofweek", "dayofweek_name", "weekend")] %>% unique %>% setorder(dayofweek) %>%
.[, newdayofweek := dayofweek + 1] %>% .[]
digaale_contact_data$participants[, c("dayofweek", "dayofweek_name", "weekend")] %>% unique %>% setorder(dayofweek) %>%
.[, newdayofweek := ifelse(dayofweek == 6, 0, dayofweek + 1)] %>% .[]
digaale_contact_data$participants[, c("dayofweek", "dayofweek_name", "weekend")] %>% unique %>% setorder(dayofweek) .[]
digaale_contact_data$participants[, c("dayofweek", "dayofweek_name", "weekend")] %>% unique %>% setorder(dayofweek) %>% .[]
digaale_contact_data$participants[, dayofweek := ifelse(dayofweek == 6, 0, dayofweek + 1)]
digaale_contact_data$participants[, c("dayofweek", "dayofweek_name", "weekend")] %>% unique %>% setorder(dayofweek) %>% .[]
digaale_contact_data %>%
socialmixr::contact_matrix(survey.pop = digaale_survey_population, age.limits = digaale_survey_population$lower.age.limit, symmetric = TRUE, weights = "survey_weight", weigh.dayofweek = TRUE) %>%
.[["matrix"]] %>% image()
digaale_contact_matrix = digaale_contact_data %>%
socialmixr::contact_matrix(survey.pop = digaale_survey_population,
age.limits = digaale_survey_population$lower.age.limit,
symmetric = TRUE, weights = "survey_weight", weigh.dayofweek = TRUE)
digaale_contact_data %>%
socialmixr::contact_matrix(survey.pop = digaale_survey_population,
age.limits = digaale_survey_population$lower.age.limit,
symmetric = TRUE, weights = "survey_weight", weigh.dayofweek = TRUE) %>% cite()
digaale_contact_data %>% cite()
#' The estimated population size in Digaale (for provided age groups) can manually be downloaded
digaale_survey_population = data.table::fread("https://zenodo.org/record/5226281/files/espicc_somaliland_digaale_survey_population.csv")
#' The estimated population size in Digaale (for provided age groups) can manually be downloaded
digaale_survey_population =
data.table::fread("https://zenodo.org/record/5226281/files/espicc_somaliland_digaale_survey_population.csv")
digaale_contact_data$participants[, c("dayofweek", "dayofweek_name", "weekend")] %>% unique %>% setorder(dayofweek) %>% .[]
#' Get data from Zenodo
digaale_contact_data = socialmixr::get_survey("https://zenodo.org/record/5226281#.YR-TzlvTVH6")
digaale_contact_data$participants[, c("dayofweek", "dayofweek_name", "weekend")] %>% unique %>% setorder(dayofweek) %>% .[]
digaale_contact_data$participants[, c("dayofweek", "dayofweek_name", "weekend")] %>% unique %>% setorder(dayofweek) %>% .[]
pacman::p_load(magrittr, socialmixr, data.table)
#' Get data from Zenodo
digaale_contact_data = socialmixr::get_survey("https://zenodo.org/record/5226281#.YR-TzlvTVH6")
#' The estimated population size in Digaale (for provided age groups) can manually be downloaded
digaale_survey_population =
data.table::fread("https://zenodo.org/record/5226281/files/espicc_somaliland_digaale_survey_population.csv")
#' Note that weekends fall on Fridays and Saturdays in Somaliland.
#' - The dayofweek variable provided in the dataset has been kept consistent with R defaults (0: Sunday to 6: Saturday)
#' - socialmixr currently assumes dayofweek 5
digaale_contact_data$participants[, c("dayofweek", "dayofweek_name", "weekend")] %>% unique %>% setorder(dayofweek) %>% .[]
digaale_contact_matrix
pacman::p_load(magrittr, socialmixr, data.table)
#' Get data from Zenodo
digaale_contact_data = socialmixr::get_survey("https://zenodo.org/record/5226281#.YR-TzlvTVH6")
#' The estimated population size in Digaale (for provided age groups) can manually be downloaded
digaale_survey_population =
data.table::fread("https://zenodo.org/record/5226281/files/espicc_somaliland_digaale_survey_population.csv")
#' Note that weekends fall on Fridays and Saturdays in Somaliland.
#' - The dayofweek variable provided in the dataset has been kept consistent with R defaults (0: Sunday to 6: Saturday)
digaale_contact_data$participants[, c("dayofweek", "dayofweek_name", "weekend")] %>%
unique %>% setorder(dayofweek) %>% .[]
#' socialmixr currently assumes the weekend to fall on dayofweek 6 (Saturday) and 0 (Sunday)
#' - dayofweek can be manually edited so that Fridays and Saturdays are taken as the weekend, if you wish to weight
#' contacts by weekday
digaale_contact_data$participants[, dayofweek := ifelse(dayofweek == 6, 0, dayofweek + 1)]
#' The contact matrix can then be constructed as follows
#' - The provided survey_population can be used to construct a population representative matrix for Digaale IDP camp
#' - As the sample is not self-weighing (oversampling of young age groups), it is recommended to apply the survey_weight
#' as weights
digaale_contact_matrix = digaale_contact_data %>%
socialmixr::contact_matrix(survey.pop = digaale_survey_population,
age.limits = digaale_survey_population$lower.age.limit,
symmetric = TRUE, weights = "survey_weight", weigh.dayofweek = TRUE)
digaale_contact_matrix
digaale_contact_matrix$matrix
digaale_contact_matrix %>% round(1)
digaale_contact_matrix$matrix %>% round(1)
digaale_contact_matrix$matrix %>% rowSums()
digaale_contact_data$participants$sample_weight
digaale_contact_data$participants$sample_weight %>% summary()
digaale_contact_matrix$matrix %>% round(1)
getwd()
#' Install and load dependencies
#' - make sure you have pacman installed: install.packages("pacman")
#' - or install and load manually
pacman::p_load(data.table, survey, ggplot2, patchwork, magrittr, kableExtra, stringr, lmtest, zscorer)
setwd("~/workspace/espicc-somaliland-digaale-survey-2019")
getwd()
#' Set the analysis directory (usually the root directory of repo)
analysis_dir = getwd()
#' Set global options, create output folders, load helper functions, and load data
source(sprintf("%s/scripts/0_setup.R", analysis_dir))
#' This estimates the total population size in Digaale, and FPC to use in the models
#' - creates table_sB1_vacant_households
#' - creates table_sB2_households_visited
source(sprintf("%s/scripts/1_fpc_correction.R", analysis_dir))
#' This does some additional cleaning of the data, assigns age-groups, creates new variables, and creates the survey
#' objects to use when correcting for FPC and to do the poststratification
source(sprintf("%s/scripts/2_prepare_data.R", analysis_dir))
#' Create table 1: Characteristics of participating households and prevalence of risk factors in Digaale IDP camp
#' - creates table1_characteristics_and_risk_factors
source(sprintf("%s/scripts/3_table1.R", analysis_dir))
#' Create tables 2, 3, and supplemental table C1
#' - creates table2_travel
#' - creates table3_contacts
#' - creates table_sC1_school_work_sens
source(sprintf("%s/scripts/4_tables_other.R", analysis_dir))
#' Regression analysis assessing collected variables with self-reported pneumonia incidence
#' - creates table_sD1_regression_pneumonia
#' - creates table_sD2_regression_pneumonia_6m
source(sprintf("%s/scripts/5_tables_regression.R", analysis_dir))
#' Create figure 1: Demographic distributions in Digaale IDP camp
#' - creates figure1_demographics
source(sprintf("%s/scripts/6_figure1.R", analysis_dir))
#' Create figure 2: Contact frequencies, types, and matrices
#' - creates figure2_contacts
source(sprintf("%s/scripts/7_figure2.R", analysis_dir))
#' Additional analyses contact estimates
#' - creates figure_sC1_bootstrapped_matrices
#' - creates figure_sC2_intra_extra_household_contacts
#' - creates figure_sC3_contact_bysex
#' - creates figure_sC4_household_contacts_expected_reported
source(sprintf("%s/scripts/8_figures_supp.R", analysis_dir))