-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindicators.Rmd
3671 lines (3295 loc) · 150 KB
/
indicators.Rmd
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
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Indicators calculation functions"
output: html_document
editor_options:
chunk_output_type: console
---
<!-- Run this 'development' chunk -->
<!-- Store every call to library() that you need to explore your functions -->
```{r development, include=FALSE}
library(testthat)
```
```{r development-load}
# Load already included functions if relevant
pkgload::load_all(export_all = FALSE)
```
# Impact Indicators
## impact_2_2
```{r function-impact_2_2}
#' impact_2_2
#'
#' **Proportion of Persons of Concern residing in physically safe and secure
#' settlements with access to basic facilities**
#'
#' Once electricity, healthcare, drinking water and adequate shelter are
#' calculated, check the values for each variable before,
#' calculating 2.2 impact indicator.
#'
#'
#' ---------
#' # inter_electricity
#'
#' Households lighting provides a sense of safety and security within and outside
#' the households after sunset.
#'
#' If households lack access to electricity, especially for lighting and
#' connectivity, this affects the occupants' security and limits their
#' opportunities for socialization, learning and self-reliance.
#'
#' **Numerator**: Population with access to electricity, especially for lighting
#' and connectivity
#'
#' **Denominator**: Total population
#'
#' **Formula**: *LIGHT01* = 1 & *LIGHT03* != 1, 96, 98
#'
#' ---------
#' # inter_healthcare
#'
#' Access to healthcare depends on availability of healthcare, including physical
#' reach, acceptability and affordability for all.
#' For this indicator, the focus is on the availability of healthcare system.
#' According to [The Sphere Handbook](https://spherestandards.org/wp-content/uploads/Sphere-Handbook-2018-EN.pdf),
#' primary healthcare facility should be accessible within one hour's walk from dwellings.
#' **Numerator**: Population that can reach a primary healthcare facility within one hour from dwellings
#' **Denominator**: Total population
#' **Formula**: *HEA01* != 96, 98 & *HEA03* <= 60
#' (reachable within one hour/60 minutes)
#'
#'
#' ---------
#' # inter_drinkingwater
#'
#' Access to clean drinking water is essential for a person's survival and well
#' being and a precursor for achieving protection outcomes related to health,
#' education and economic developed.
#' The calculation for access drinking water is linked to SGD Indicator
#' [6.1.1](https://unstats.un.org/sdgs/metadata/files/Metadata-06-01-01.pdf).
#' The questionnaire module and the analysis guidance is taken from [UNICEF MICS6](https://mics.unicef.org/tools#analysis).
#'
#' **Numerator**: Population using improved sources of drinking water either in their dwelling/yard/plot or within 30 minutes round trip collection time
#'
#' **Denominator**: Total population
#'
#' **Formula**:
#' *DWA03* < 30 (under 30 minutes), &
#' *DWA01* != 7,9,13,96,98 &
#' *DWA02* != 3
#'
#' This basic service is calculated from the main dataset
#' There are three conditions as below improved source,
#' in dwelling/yard/plot and reachable under 30 minutes
#'
#'
#' ---------
#' # inter_shelter
#'
#' The right to access adequate housing is protected by international law.
#' The concept of "adequacy" means that housing is more than four walls and a
#' roof as indicated in [The Sphere Handbook](https://spherestandards.org/wp-content/uploads/Sphere-Handbook-2018-EN.pdf).
#' Habitable housing primarily refers to the fact that the housing should provide
#' protection from cold, damp, heat, rain, wind, and other threats to health,
#' structural hazards, and disease vectors and it should not be overcrowded.
#' As shelter/housing is primarily a contextual element, there may be
#' discrepancies from country to country on how this data is measured.
#'
#' Adequate shelter is measured based on having improved material for the
#' dwelling as indicated in [DHS](https://dhsprogram.com/pubs/pdf/AS61/AS61.pdf)
#' publication on housing conditions which is also used by [MICS6](https://mics.unicef.org/tools).
#'
#' Overcrowding is also used which occurs if there are more than three people
#' per habitable room as defined by [UN-Habitat](https://www.ncbi.nlm.nih.gov/books/NBK535289/table/ch3.tab2/).
#'
#' **Numerator**: Population that have access to adequate housing
#' **Denominator**: Total population
#'
#' **Formula**:
#'
#' *DWE01* = 1,2 &
#' *DWE02* = 3,4,5,6,7,8,9 &
#' *DWE03* = 8,9,10,11,12,13 &
#' *DWE04* = 10,11,12,13,14,15 &
#' crowding (*HH01*/*DWE05*) \<= 3
#'
#' Adequate shelter is calculated from the main dataset
#' classify as habitable when improved/adequate shelter
#'
#'
#'
#' ---------
#' # Compile alll
#' Once all variables are correctly calculated, we can compute the final
#' variable for impact 2.2 indicator.
#' **Numerator**: Population residing in physically safe and secure settlements with access to basic facilities
#' **Denominator**: Total population
#' **Formula**: *shelter*=1 & *electricity*=1 & *healthcare*=1 & *drinkingwater*=1
#'
#' Impact 2.2 is "1" if all services above are accessible
#'
#' @param datalist A list with all hierarchical data frame for a survey data set.
#' format is expected to match the Excel export synchronized from kobo to RILD
#' and loaded with kobocruncher::kobo_data()
#'
#'
#' @importFrom dplyr mutate case_when
#' @importFrom labelled labelled
#'
#' @return new calculated variable - appended or not...
#'
#' @export
impact_2_2 <- function(datalist ){
## Mapper
mapper = list(
hierarchy = "main",
variablemap = data.frame(
label =
c("1. When anyone in your household is sick, where do they go to seek care?",
"2. How do you reach this facility if you need to seek care?",
"3. How long does it take to go there when you use the mode of transport that you mentioned above?",
"4. Does this household use anything for lighting?", "5. What does this household use most of the time as energy for lighting, or as a light source?",
"6. What source of electricity is used most of the time in this household?",
"1. What is the main source of drinking water for this household?",
"2. Where is this ${source} - ${source2} located?", "Unit", "Time",
"4. In the last 30 days, has there been any time when your household did not have sufficient quantities of drinking water when needed?",
"1.What type of dwelling does the household live in?", "2. Main material of the dwelling floor",
"3. Main material of the roof.", "4. Main material of the exterior walls",
"5. How many separate rooms do the members of your household occupy?",
"8. Does your household pay any rent?", "9. Can your household generally afford to pay the rent without any major financial distress?",
"What is the total number of persons in this household ? (including the respondent)"
)
,
variable =
c("HEA01", "HEA02", "HEA03", "LIGHT01", "LIGHT02", "LIGHT03",
"DWA01", "DWA02", "DWA03a", "DWA03b", "DWA04", "DWE01", "DWE02",
"DWE03", "DWE04", "DWE05", "DWE08", "DWE09", "HH01")
),
modalitymap = data.frame(
variable =
c("HEA01", "HEA01", "HEA01", "HEA01", "HEA01", "HEA01", "HEA01",
"HEA02", "HEA02", "HEA02", "HEA02", "HEA03", "LIGHT01", "LIGHT01",
"LIGHT02", "LIGHT02", "LIGHT02", "LIGHT02", "LIGHT02", "LIGHT02",
"LIGHT02", "LIGHT02", "LIGHT02", "LIGHT02", "LIGHT02", "LIGHT02",
"LIGHT02", "LIGHT02", "LIGHT03", "LIGHT03", "LIGHT03", "LIGHT03",
"LIGHT03", "LIGHT03", "LIGHT03", "LIGHT03", "LIGHT03", "LIGHT03",
"DWA01", "DWA01", "DWA01", "DWA01", "DWA01", "DWA01", "DWA01",
"DWA01", "DWA01", "DWA01", "DWA01", "DWA01", "DWA01", "DWA01",
"DWA01", "DWA01", "DWA01", "DWA01", "DWA02", "DWA02", "DWA02",
"DWA03a", "DWA03a", "DWA03b", "DWA04", "DWA04", "DWE01", "DWE01",
"DWE01", "DWE01", "DWE01", "DWE01", "DWE01", "DWE01", "DWE01",
"DWE01", "DWE02", "DWE02", "DWE02", "DWE02", "DWE02", "DWE02",
"DWE02", "DWE02", "DWE02", "DWE02", "DWE03", "DWE03", "DWE03",
"DWE03", "DWE03", "DWE03", "DWE03", "DWE03", "DWE03", "DWE03",
"DWE03", "DWE03", "DWE03", "DWE03", "DWE04", "DWE04", "DWE04",
"DWE04", "DWE04", "DWE04", "DWE04", "DWE04", "DWE04", "DWE04",
"DWE04", "DWE04", "DWE04", "DWE04", "DWE04", "DWE04", "DWE05",
"DWE08", "DWE08", "DWE09", "DWE09", "DWE09", "DWE09", "HH01")
,
label =
c("NGO facility (charity, faith-based organization)", "UNHCR Health Partner (Caritas, Save the Children)",
"Public Clinics / Hospitals", "Private Clinics / Hospitals",
"Pharmacy", "Other, specify", "Don\'t know", "By walk", "Private car",
"Public transport (bus, boat)", "Other, specify", NA, "Yes",
"No", "Electricity (including solar mini-grids, hybrid mini-grids and national grid)",
"Electricity (from diesel generator)", "Solar home system", "Solar-powered lantern or flashlight",
"Rechargeable flashlight, mobile, torch or lantern", "Battery powered flashlight, torch or lantern",
"Biogas lamp", "LPG lamp", "Gasoline lamp", "Kerosene or paraffin lamp",
"Oil lamp", "Candle", "Open fire", "Other, specify", "No electricity in household",
"National grid connection from [COMPANY]", "Local mini grid",
"Solar home system", "Solar lantern", "Electric generator", "Rechargeable battery",
"Dry cell battery / torch", "Other, specify", "Don\'t know", "Piped Into Dwelling",
"Piped Into Yard/Plot", "Piped To Neighbor", "Public Tap/Standpipe",
"Tube Well/Borehole", "Protected Dug Well", "Unprotected Dug Well",
"Protected Spring", "Unprotected Spring", "Rain Water Collection",
"Tanker Truck/Water Vendor", "Cart With Small Tank/Drum", "Surface Water (River, Stream, Pond, Dam, Canal)",
"Bottled Water", "Sachet Water", "Water Kiosk", "Other (Specify)",
"Don\'t Know", "In Own Dwelling", "In Own Yard/Plot", "Elsewhere",
"Minutes", "Hours", NA, "Yes", "No", "Apartment", "House", "Tent",
"Caravan", "Collective Center", "Worksite/Unfinished Home/ Abandoned Building",
"Farm Building", "School, mosque, church or other religious building",
"Garage, shop, workshop, or other structure not meant as residential space",
"Other (Specify)", "Earth/sand", "Dung", "Wood planks", "Palm/bamboo",
"Parquet or polished wood", "Vinyl or asphalt strips", "Ceramic tiles",
"Cement", "Carpet", "Other (Specify)", "No roof", "Thatch/Palm leaf",
"Sod", "Rustic mat", "Palm/bamboo", "Wood planks", "Cardboard",
"Metal/tin", "Wood", "Calamine/Cement fibre", "Ceramic tiles",
"Cement", "Roofing shingles", "Other (Specify)", "No walls",
"Cane/Palm/ Trunks", "Dirt", "Bamboo with mud", "Stone with mud",
"Uncovered adobe", "Plywood", "Cardboard", "Reused wood", "Cement",
"Stone with lime/ cement", "Bricks", "Cement blocks", "Covered adobe",
"Wood planks/shingles", "Other (Specify)", NA, "Yes", "No", "Always",
"Often", "Sometimes", "Never", NA)
,
standard =
c("1", "2", "3", "4", "5", "96", "98", "1", "2", "3", "96", NA,
"1", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
"11", "12", "13", "96", "1", "2", "3", "4", "5", "6", "7", "8",
"96", "98", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
"11", "12", "13", "14", "15", "16", "96", "98", "1", "2", "3",
"1", "2", NA, "1", "0", "1", "2", "3", "4", "5", "6", "7", "8",
"9", "96", "1", "2", "3", "4", "5", "6", "7", "8", "9", "96",
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12",
"13", "96", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
"11", "12", "13", "14", "15", "96", NA, "1", "0", "1", "2", "3",
"4", NA)
))
## So first we check that we have what we need in the data set based on the mapper
check_map <- fct_check_map(datalist = datalist,
mapper = mapper)
if ( check_map == FALSE) {
cat( "There are missing data requirement to calculate Indicator Impact 2.2")
} else {
## now pull the calculation...
## Electricity ########
datalist[["main"]]$electricity <- dplyr::case_when(
datalist[["main"]]$LIGHT01 == 1 &
(as.integer(datalist[["main"]]$LIGHT03) != 1 |
as.integer(datalist[["main"]]$LIGHT03)!= 96 |
as.integer(datalist[["main"]]$LIGHT03) != 98) ~ 1,
TRUE ~ 0 )
datalist[["main"]]$electricity <- labelled::labelled(
datalist[["main"]]$electricity,
labels = c('Yes' = 1, 'No' = 0 ),
label = "Access to electricity")
## healthcare ########
datalist[["main"]]$healthcare <-
dplyr::case_when((
as.integer(datalist[["main"]]$HEA01) != 96 |
as.integer(datalist[["main"]]$HEA01) != 98) &
as.integer(datalist[["main"]]$HEA03) <= 60 ~ 1,
TRUE ~ 0)
datalist[["main"]]$healthcare <- labelled::labelled(datalist[["main"]]$healthcare,
labels = c('Yes' = 1, 'No' = 0 ),
label = "Access to healthcare facility")
## Drinking Water #################
datalist[["main"]]$time_DWA <- dplyr::case_when(
as.integer(datalist[["main"]]$DWA03a) == 1 ~ 1,
as.integer(datalist[["main"]]$DWA03a) == 2 ~ 60)
#convert hour into minutes
# datalist[["main"]]$time_DWA <- as.numeric(datalist[["main"]]$time_DWA)
datalist[["main"]]$time_tot <- datalist[["main"]]$time_DWA *
as.numeric(datalist[["main"]]$DWA03b)
datalist[["main"]]$reachableU30 <- dplyr::case_when(
datalist[["main"]]$time_tot > 30 ~ 0,
TRUE ~ 1)
# reachable under 30 minutes
datalist[["main"]]$dwa_cond1 <- dplyr::case_when(
as.integer(datalist[["main"]]$DWA01) != 7 |
as.integer(datalist[["main"]]$DWA01) != 9 |
as.integer(datalist[["main"]]$DWA01) != 13 |
as.integer(datalist[["main"]]$DWA01) != 96 |
as.integer(datalist[["main"]]$DWA01) != 98 ~ 1,
TRUE ~ 0)
# improved source
datalist[["main"]]$dwa_cond2 <- dplyr::case_when(
#UNDER30 MIN
as.integer(datalist[["main"]]$reachableU30) == 1 &
as.integer(datalist[["main"]]$DWA02) == 3 ~ 1,
# NOT UNDER30 MIN
as.integer(datalist[["main"]]$reachableU30) == 0 &
as.integer(datalist[["main"]]$DWA02) == 3 ~ 0,
# in the dwelling/yard/plot
as.integer(datalist[["main"]]$DWA02) == 1 |
as.integer(datalist[["main"]]$DWA02) == 2 ~ 1,
TRUE ~ NA )
datalist[["main"]]$drinkingwater <- dplyr::case_when(
(as.integer(datalist[["main"]]$dwa_cond1) == 1 &
as.integer(datalist[["main"]]$dwa_cond2) == 1 ) ~ 1,
TRUE ~ 0)
datalist[["main"]]$drinkingwater <- labelled::labelled(datalist[["main"]]$drinkingwater,
labels = c('Yes' = 1, 'No' = 0 ),
label = "Access to drinking water")
## shelter #########
#Only apartment and house
datalist[["main"]]$dwe01_cat <-
dplyr::case_when(
( as.integer(datalist[["main"]]$DWE01) == 1 |
as.integer(datalist[["main"]]$DWE01) == 2) ~ 1,
TRUE ~ 0 )
## unimproved floor when earth,sand,clay,mud, dung or other
datalist[["main"]]$dwe02_cat<- dplyr::case_when(
(as.integer(datalist[["main"]]$DWE02) == 1 |
as.integer(datalist[["main"]]$DWE02) == 2 |
as.integer(datalist[["main"]]$DWE02) == 96) ~ 0,
TRUE ~ 1 )
## unimproved roof all options except metal,wood,ceramic tiles, cement, roofing shingles/sheets
datalist[["main"]]$dwe03_cat<- dplyr::case_when(
(as.integer(datalist[["main"]]$DWE03) == 8 |
as.integer(datalist[["main"]]$DWE03) == 9 |
as.integer(datalist[["main"]]$DWE03) == 10 |
as.integer(datalist[["main"]]$DWE03) == 11 |
as.integer(datalist[["main"]]$DWE03) == 12 |
as.integer(datalist[["main"]]$DWE03) == 13 ) ~ 1 ,
TRUE ~ 0)
## improved wall: cement,stone,bricks,cement blocks, covered adobe, wood planks
datalist[["main"]]$dwe04_cat<- dplyr::case_when(
(as.integer(datalist[["main"]]$DWE04) == 10|
as.integer(datalist[["main"]]$DWE04) == 11 |
as.integer(datalist[["main"]]$DWE04) == 12 |
as.integer(datalist[["main"]]$DWE04) == 13 |
as.integer(datalist[["main"]]$DWE04) == 14 |
as.integer(datalist[["main"]]$DWE04) == 15 ) ~ 1,
TRUE ~ 0)
## Calculate crowding index - overcrowded when more than 3 persons
datalist[["main"]]$crowding <- as.numeric(datalist[["main"]]$HH01) /
as.numeric(datalist[["main"]]$DWE05)
datalist[["main"]]$dwe05_cat<- dplyr::case_when( ##if crowding <= 3, not overcrowded
datalist[["main"]]$crowding <= 3 ~ 1,
TRUE ~ 0)
####Calculate if all 5 conditions are met for adequate shelter
##dwe01_cat / dwe02_cat / dwe03_cat / dwe04_cat / dwe05_cat
datalist[["main"]]$shelter<- dplyr::case_when(
as.integer(datalist[["main"]]$dwe01_cat) == 0 |
as.integer(datalist[["main"]]$dwe02_cat) == 0 |
as.integer(datalist[["main"]]$dwe03_cat) == 0 |
as.integer(datalist[["main"]]$dwe04_cat) == 0 |
as.integer(datalist[["main"]]$dwe05_cat) == 0 ~ 0,
as.integer(datalist[["main"]]$dwe01_cat) == 1 &
as.integer(datalist[["main"]]$dwe02_cat) == 1 &
as.integer(datalist[["main"]]$dwe03_cat) == 1 &
as.integer(datalist[["main"]]$dwe04_cat) == 1 &
as.integer(datalist[["main"]]$dwe05_cat) == 1 ~ 1)
datalist[["main"]]$shelter <- labelled::labelled( datalist[["main"]]$shelter,
labels = c('Yes' = 1, 'No' = 0 ),
label = "Access to adequate shelter")
## Compile alll ####
datalist[["main"]]$impact2_2 <- dplyr::case_when(
as.integer(datalist[["main"]]$shelter) == 0 |
as.integer(datalist[["main"]]$electricity) == 0 |
as.integer(datalist[["main"]]$drinkingwater) == 0 |
as.integer(datalist[["main"]]$healthcare) == 0 ~ 0,
as.integer(datalist[["main"]]$shelter) == 1 &
as.integer(datalist[["main"]]$electricity) == 1 &
as.integer(datalist[["main"]]$drinkingwater) == 1 &
as.integer(datalist[["main"]]$healthcare) == 1 ~ 1)
datalist[["main"]]$impact2_2 <- labelled::labelled(
datalist[["main"]]$impact2_2,
labels =c(
"Yes" = 1,
"No" = 0
),
label = "Proportion of PoCs residing in physically safe and secure settlements with access to basic facilities")
}
return(datalist)
}
```
```{r example-impact_2_2, message=TRUE, warning=FALSE}
## data, cf example fct_re_map()
datalist <- kobocruncher::kobo_data( system.file("dummy_RMS_CAPI_v2_mapped.xlsx",
package = "IndicatorCalc"))
## Apply calculation
datalist <- impact_2_2(datalist)
table(datalist[["main"]]$impact2_2, useNA = "ifany")
fct_plot_indic_donut(indicator = datalist[["main"]]$impact2_2,
iconunicode = "f140")
## Can get the details as well
table(datalist[["main"]]$electricity, useNA = "ifany")
fct_plot_indic_donut(indicator = datalist[["main"]]$electricity,
iconunicode = "f0e7")
table(datalist[["main"]]$healthcare, useNA = "ifany")
fct_plot_indic_donut(indicator = datalist[["main"]]$healthcare,
iconunicode = "f479")
table(datalist[["main"]]$drinkingwater, useNA = "ifany")
fct_plot_indic_donut(indicator = datalist[["main"]]$drinkingwater,
iconunicode = "e006")
## Check intermediary variables
table(datalist[["main"]]$dwa_cond1, useNA = "ifany")
table(datalist[["main"]]$reachableU30, useNA = "ifany")
table(datalist[["main"]]$DWA02, useNA = "ifany")
table(datalist[["main"]]$dwa_cond2, useNA = "ifany")
# Tabulate
table(datalist[["main"]]$dwe01_cat, useNA = "ifany")
table(datalist[["main"]]$dwe02_cat, useNA = "ifany")
table(datalist[["main"]]$dwe03_cat, useNA = "ifany")
table(datalist[["main"]]$dwe04_cat, useNA = "ifany")
table(datalist[["main"]]$dwe05_cat, useNA = "ifany")
table(datalist[["main"]]$shelter, useNA = "ifany")
#plot
fct_plot_indic_donut(datalist[["main"]]$shelter,
iconunicode = "e54f")
```
```{r tests-impact_2_2}
test_that("impact2_2 works", {
expect_true(inherits(impact_2_2, "function"))
})
```
## impact2_3
```{r function-impact2_3}
#' impact2_3
#'
#' **Proportion of PoC with access to health services**
#'
#' This indicator measures access to primary health care services for persons
#' of concern in need of health services.
#'
#' Health services refers to preventive, pro-motive, curative, rehabilitative
#' and palliative health services.
#'
#' It is linked to SDG indicator [3.8.1](https://www.who.int/data/gho/data/themes/topics/service-coverage)
#' on the coverage of essential health services.
#'
#' The standard questions for this indicator are taken from UNHCR's [HAUS](https://www.unhcr.org/strategic-health-information.html) monitors trends
#' in how refugees outside of camps access and utilize health services over time.
#' Healthcare can be delivered through a combination of community level, mobile
#' and fixed healthcare facilities.
#' The number, type and location of each will vary by context.
#' The standard questionnaire module will help us to understand these differences.
#'
#' | Standard Questions |
#' |:------------------:|
#' | HACC01 - HACC04 |
#'
#' **Numerator**: Population who have received the asked for health services in the previous 30 days
#'
#' **Denominator**: Total population who have asked for health services in the previous 30 days
#'
#' **Formula**: *HACC01*=1 + / ((*HACC03*=1 & *HACC04*!=7,8,96) + *HACC01*=1)
#'
#' This indicator comes from the individual dataset
#' Calculate those who were not able to access due to reasons
#' unrelated to asked services (when HACC04 is 7 or 8 or 96)
#'
#' @param datalist A list with all hierarchical data frame for a survey data set.
#' format is expected to match the Excel export synchronized from kobo to RILD
#' and loaded with kobocruncher::kobo_data()
#'
#'
#' @importFrom dplyr mutate case_when
#' @importFrom labelled labelled
#'
#' @return new calculated variable - appended or not...
#'
#' @export
impact2_3 <- function(datalist ){
# # Mapper ,
# mapper = list(
# hierarchy = "ind",
# variablemap = data.frame(
# label =
# c("1. During the past 30 days, has ${name_individual} consulted a health practitioner, dentist, traditional healer, or pharmacist, or visited a health center?",
# "2. For what reason(s) did ${name_individual} seek consultation?",
# "3. During the past 30 days, has ${name_individual} needed health services that’s/he could not have access to?",
# "4. Why has ${name_individual} been unable to access a medical treatment in the past 30 days?"
# )
# ,
# variable =
# c("HACC01", "HACC02", "HACC03", "HACC04")
# ),
# modalitymap = data.frame(
# variable =
# c("HACC01", "HACC01", "HACC02", "HACC02", "HACC02", "HACC02",
# "HACC02", "HACC02", "HACC03", "HACC03", "HACC04", "HACC04", "HACC04",
# "HACC04", "HACC04", "HACC04", "HACC04", "HACC04", "HACC04", "HACC04",
# "HACC04")
# ,
# label =
# c("Yes", "No", "Illness", "Injury", "General check-up (not for pregnancy)",
# "Pre/Postnatal check-up", "Giving birth", "Other (Specify)",
# "Yes", "No", "Lack of money", "No medical personnel available",
# "Turned away because facility was full", "Turned away because facility was closed",
# "Hospital/Clinic not having enough supplies or tests", "Health facility is too far",
# "Fear of contracting a communicable disease (e.g. COVID-19)",
# "Lockdown/Travel restrictions", "Too Far/transport issues", "Health facility is destroyed",
# "Other (Specify)")
# ,
# standard =
# c("1", "0", "1", "2", "3", "4", "5", "96", "1", "0", "1", "2",
# "3", "4", "5", "6", "7", "8", "9", "10", "96")
# ))
# ## So first we check that we have what we need in the data set based on the mapper
# check_map <- fct_check_map(datalist = datalist,
# mapper = mapper)
# if ( check_map == FALSE) {
# cat( "There are missing data requirement to calculate Indicator Impact 2.3")
# } else {
#
#
# datalist[["ind"]]$health_NOacc <- dplyr::case_when(
# as.integer(datalist[["ind"]]$HACC03) == 1 &
# (as.integer(datalist[["ind"]]$HACC04_7) == 1 |
# as.integer(datalist[["ind"]]$HACC04_8) == 1 |
# as.integer(datalist[["ind"]]$HACC04_96) == 1 ) ~ 0,
#
# as.integer(datalist[["ind"]]$HACC03) == 1 &
# (as.integer(datalist[["ind"]]$HACC04_1) == 1 |
# as.integer(datalist[["ind"]]$HACC04_2) == 1 |
# as.integer(datalist[["ind"]]$HACC04_3) == 1 |
# as.integer(datalist[["ind"]]$HACC04_4) == 1 |
# as.integer(datalist[["ind"]]$HACC04_5) == 1 |
# as.integer(datalist[["ind"]]$HACC04_6) == 1 |
# as.integer(datalist[["ind"]]$HACC04_9) == 1 |
# as.integer(datalist[["ind"]]$HACC04_10) == 1) ~ 1,
#
# TRUE ~ 0)
# # table(datalist[["ind"]]$health_NOacc, useNA = "ifany")
#
# datalist[["ind"]]$health_NOacc <- as.numeric(datalist[["ind"]]$health_NOacc)
# datalist[["ind"]]$HACC01 <- as.numeric(datalist[["ind"]]$HACC01)
#
#
# ## Add up who needed services ( both who accessed and did not access)
# datalist[["ind"]]$HACC_need <- datalist[["ind"]]$HACC01 + datalist[["ind"]]$health_NOacc
#
# datalist[["ind"]]$impact2_3 <- datalist[["ind"]]$HACC01 / datalist[["ind"]]$HACC_need
#
# datalist[["ind"]]$impact2_3 <- dplyr::case_when(
# datalist[["ind"]]$impact2_3 == 1 ~ 1,
# datalist[["ind"]]$impact2_3 == 0.5 ~ 0,
# datalist[["ind"]]$impact2_3 == 0 ~ 0,
# TRUE ~ NA_real_ )
#
# datalist[["ind"]]$impact2_3 <- labelled::labelled( datalist[["ind"]]$impact2_3,
# labels =c( "Yes"=1, "No"=0 ),
# label = "Proportion of PoC with access to health services")
# }
# return(datalist)
}
```
```{r example-impact2_3, message=TRUE, warning=FALSE}
## data, cf example fct_re_map()
# datalist <- kobocruncher::kobo_data( system.file("dummy_RMS_CAPI_v2_mapped.xlsx",
# package = "IndicatorCalc"))
# ## Apply calculation
# datalist <- impact2_3(datalist )
#
# ## Visualise value
# fct_plot_indic_donut(indicator = datalist[["ind"]]$impact2_3,
# iconunicode = "f140")
```
```{r tests-impact2_3}
test_that("impact2_3 works", {
expect_true(inherits(impact2_3, "function"))
})
```
## impact3_2a
```{r function-impact3_2a}
#' impact3_2a
#'
#' **Proportion of Persons of Concern enrolled in primary education**
#'
#' This indicator measures the number of students enrolled in primary education,
#' regardless of age, expressed as a percentage of the official school-age population
#' corresponding to the respective same level of education.
#'
#' This is also referred to as Gross enrollment rate (GER).
#'
#' It is linked to SGD indicator 4.1.1 on quality education.
#'
#' The standard questions for this indicator are taken from UNHCR's
#' [Standardized Education Module](https://www.unhcr.org/60804b214.pdf) which
#' are adapted primarily from the IHSN/EPDC and MICS indicator and questionnaire frameworks.
#'
#' *Definitions*:
#'
#' 1. "Enrollment" refers individuals officially registered in a primary/secondary school education programme.
#'
#' 2. "Primary education" is designed to provide students with fundamental skills in reading, writing and mathematics.
#'
#' Duration typically varies from 4 to 7 years.
#' The most common duration is 6 years.
#' It corresponds to ISCED (International Standard Classification of Education) level 1.
#'
#' 3. "Primary school age" depends on the education system and it varies from country to country.
#' Children typically enter in primary education between age 5 and 7 and leave at the age of 10 and 12.
#'
#' | Standard Questions |
#' |:------------------:|
#' | EDU01-EDU04 |
#'
#' **Numerator**: Population enrolled in primary education (regardless of age)
#' **Denominator**: Total primary school age population (to be adjusted by the country for enumeration)
#'
#' **Formula**: (*EDU01*=1 & *EDU02*=1 & *EDU03*=2) / Number of children aged from 6 to 10
#'
#' This indicator comes from the individual dataset
#'
#' @param datalist A list with all hierarchical data frame for a survey data set.
#' format is expected to match the Excel export synchronized from kobo to RILD
#' and loaded with kobocruncher::kobo_data()
#'
#' @importFrom dplyr mutate case_when
#' @importFrom labelled labelled
#'
#' @return new calculated variable - appended or not...
#'
#' @export
impact3_2a <- function(datalist ){
## Mapper
mapper = list(
hierarchy = "ind",
variablemap = data.frame(
label =
c("1. Has ${child_edu_name} ever attended school?", "2. Did ${child_edu_name} attend school or pre-school at any time during current school year?",
"3. During this/that school year , what level is (was) ${child_edu_name} attending?",
"4. What type of school?", "6. Can you estimate how old is ${HH02}?"
)
,
variable =
c("EDU01", "EDU02", "EDU03", "EDU04", "HH07")
),
modalitymap = data.frame(
variable =
c("EDU01", "EDU01", "EDU02", "EDU02", "EDU03", "EDU03", "EDU03",
"EDU03", "EDU03", "EDU03", "EDU03", "EDU04", "EDU04", "EDU04",
"EDU04", "EDU04", "EDU04", "EDU04", "HH07")
,
label =
c("Yes", "No", "Yes", "No", "Early Childhood Education or Pre-primary",
"Primary", "Secondary", "Secondary - Technical and Vocational Education and Training (TVET)",
"Post-secondary - Technical and Vocational Education and Training (TVET)",
"Tertiary", "Don\u2019t know", "Government or public", "UN or NGO (non-governmental organization)",
"Religious or faith-based organization", "Community", "Private",
"Other (specify)", "Don\u2019t know", NA)
,
standard =
c("1", "0", "1", "0", "1", "2", "3", "4", "5", "6", "98", "1",
"2", "3", "4", "5", "96", "98", NA)
))
## So first we check that we have what we need in the data set based on the mapper
check_map <- fct_check_map(datalist = datalist,
mapper = mapper)
if ( check_map == FALSE) {
cat( "There are missing data requirement to calculate Indicator Impact 3.2.a")
} else {
datalist[["ind"]]$edu_primary<- dplyr::case_when(
as.integer(datalist[["ind"]]$EDU01) == 1 &
as.integer(datalist[["ind"]]$EDU02) == 1 &
as.integer(datalist[["ind"]]$EDU03) == 2 ~ 1,
as.integer(datalist[["ind"]]$EDU01) == 0 |
as.integer(datalist[["ind"]]$EDU02) == 0 ~ 0,
TRUE ~ 0)
#Adjust age group for primary school enrollment --> this to go in function var...
datalist[["ind"]]$age_primary<- dplyr::case_when(
as.integer(datalist[["ind"]]$HH07) >= 6 &
as.integer(datalist[["ind"]]$HH07) <= 10 ~ 1,
TRUE ~ NA_real_)
datalist[["ind"]]$impact3_2a <- sum(datalist[["ind"]]$edu_primary, na.rm = TRUE) /
sum(datalist[["ind"]]$age_primary, na.rm = TRUE)
datalist[["ind"]]$impact3_2a <- labelled::labelled(datalist[["ind"]]$impact3_2a,
labels = c('Yes' = 1, 'No' = 0 ),
label = "Proportion of persons of concern enrolled in primary education")
}
return(datalist)
}
```
```{r example-impact3_2a, message=TRUE, warning=FALSE}
## data, cf example fct_re_map()
datalist <- kobocruncher::kobo_data( system.file("dummy_RMS_CAPI_v2_mapped.xlsx",
package = "IndicatorCalc"))
## Apply calculation
datalist <- impact3_2a(datalist )
table(datalist[["ind"]]$impact3_2a, useNA = "ifany")
table(datalist[["ind"]]$edu_primary, useNA = "ifany")
table(datalist[["ind"]]$age_primary, useNA = "ifany")
## Visualise value
fct_plot_indic_donut(indicator = datalist[["ind"]]$impact3_2a,
iconunicode = "f140")
```
```{r tests-impact3_2a}
test_that("impact3_2a works", {
expect_true(inherits(impact3_2a, "function"))
})
```
## impact3_2b
```{r function-impact3_2b}
#' impact3_2b
#'
#' **Proportion of Persons of Concern enrolled in secondary education**
#'
#' This indicator measures the number of students enrolled in secondary education,
#' regardless of age, expressed as a percentage of the official school-age population
#' corresponding to the respective same level of education.
#'
#' This is also referred to as Gross enrollment rate (GER).
#' It is linked to SGD indicator 4.1.1 on quality education.
#'
#' The standard questions for this indicator are taken from UNHCR's [Standardized Education Module](https://www.unhcr.org/60804b214.pdf) which are adapted primarily from
#' the IHSN/EPDC and MICS indicator and questionnaire frameworks.
#'
#' Definitions:
#'
#' 1. "Enrollment" refers individuals officially registered in a primary/secondary school education programme.
#'
#' 2. "Secondary education" provides learning and educational activities building on primary education and preparing for both first labour market entry as well as further study.
#'
#' The common duration is 6 years and is often divided between lower and upper secondary education (corresponding respectively to ISCED 2 and 3).
#'
#' 3. "Secondary school age" depends on the education system and differ from
#' country to country.
#' Children typically enter secondary education between age 11 and 13 and leave between age 17-19.
#'
#' 4. Whenever possible, operations are encouraged also to disaggregate data between lower and upper secondary
#'
#' | Standard Questions |
#' |:------------------:|
#' | EDU01-EDU04 |
#'
#' **Numerator**: Population enrolled in secondary education (regardless of age)
#' **Denominator**: Total secondary school age population (to be adjusted by the country for enumeration)
#'
#' **Formula**: (*EDU01*=1 & *EDU02*=1 & (*EDU03*=3,4) / Number of children aged from 11 to 18
#'
#' This indicator comes from the individual dataset
#'
#' Include if they are attending secondary or secondary -technical and vocational
#'
#' @param datalist A list with all hierarchical data frame for a survey data set.
#' format is expected to match the Excel export synchronized from kobo to RILD
#' and loaded with kobocruncher::kobo_data()
#'
#' @importFrom dplyr mutate case_when
#' @importFrom labelled labelled
#'
#' @return new calculated variable - appended or not...
#'
#' @export
impact3_2b <- function(datalist ){
# mapper ,
mapper = list(
hierarchy = "ind",
variablemap = data.frame(
label =
c("1. Has ${child_edu_name} ever attended school?", "2. Did ${child_edu_name} attend school or pre-school at any time during current school year?",
"3. During this/that school year , what level is (was) ${child_edu_name} attending?",
"4. What type of school?", "6. Can you estimate how old is ${HH02}?"
)
,
variable =
c("EDU01", "EDU02", "EDU03", "EDU04", "HH07")
),
modalitymap = data.frame(
variable =
c("EDU01", "EDU01", "EDU02", "EDU02", "EDU03", "EDU03", "EDU03",
"EDU03", "EDU03", "EDU03", "EDU03", "EDU04", "EDU04", "EDU04",
"EDU04", "EDU04", "EDU04", "EDU04", "HH07")
,
label =
c("Yes", "No", "Yes", "No", "Early Childhood Education or Pre-primary",
"Primary", "Secondary", "Secondary - Technical and Vocational Education and Training (TVET)",
"Post-secondary - Technical and Vocational Education and Training (TVET)",
"Tertiary", "Don\u2019t know", "Government or public", "UN or NGO (non-governmental organization)",
"Religious or faith-based organization", "Community", "Private",
"Other (specify)", "Don\u2019t know", NA)
,
standard =
c("1", "0", "1", "0", "1", "2", "3", "4", "5", "6", "98", "1",
"2", "3", "4", "5", "96", "98", NA)
))
## So first we check that we have what we need in the data set based on the mapper
check_map <- fct_check_map(datalist = datalist,
mapper = mapper)
if ( check_map == FALSE) {
cat( "There are missing data requirement to calculate Indicator Impact 3.2.b")
} else {
datalist[["ind"]]$edu_secondary<- dplyr::case_when(
as.integer(datalist[["ind"]]$EDU01) == 1 &
as.integer(datalist[["ind"]]$EDU02) == 1 &
( as.integer(datalist[["ind"]]$EDU03) == 3 |
as.integer(datalist[["ind"]]$EDU03) == 4) ~ 1,
as.integer(datalist[["ind"]]$EDU01) == 0 |
as.integer(datalist[["ind"]]$EDU02) == 0 ~ 0,
TRUE ~ 0)
#Adjust age group for secondary school enrollment
##calculated as 11 to 18 above --> put as function variable...
datalist[["ind"]]$age_secondary<- dplyr::case_when(
as.integer(datalist[["ind"]]$HH07) >= 11 &
as.integer(datalist[["ind"]]$HH07) <= 18 ~ 1,
TRUE ~ NA_real_)
datalist[["ind"]]$impact3_2b <- sum(datalist[["ind"]]$edu_secondary, na.rm= TRUE) /
sum(datalist[["ind"]]$age_secondary, na.rm = TRUE)
datalist[["ind"]]$impact3_2b <- labelled::labelled(datalist[["ind"]]$impact3_2b,
labels = c('Yes' = 1, 'No' = 0 ),
label = "Proportion of persons of concern enrolled in secondary education")
}
return(datalist)
}
```
```{r example-impact3_2b, message=TRUE, warning=FALSE}
## data, cf example fct_re_map()
datalist <- kobocruncher::kobo_data( system.file("dummy_RMS_CAPI_v2_mapped.xlsx",
package = "IndicatorCalc"))
## Apply calculation
datalist <- impact3_2b(datalist )
## Visualise value
fct_plot_indic_donut(indicator = datalist[["ind"]]$impact3_2b,
iconunicode = "f140")
```
```{r tests-impact3_2b}
test_that("impact3_2b works", {
expect_true(inherits(impact3_2b, "function"))
})
```
## impact3_3
```{r function-impact3_3}
#' impact3_3
#'
#' **Proportion of population that feel safe walking alone in their neighbourhood**
#'
#' This indicator measures the proportion of persons of concern who self-report
#' feeling safe while walking alone in her/his neighborhood after dark.
#' It is linked to SDG indicator [16.1.4](https://unstats.un.org/sdgs/metadata/files/Metadata-16-01-04.pdf).
#'
#' The standard module for this indicator is taken from SGD indicator owner UNODC.
#' This indicator only pertains to self-reported feeling of 'safety' and not
#' 'security' since security is associated with additional external factors.
#'
#' | Standard Questions |
#' |:------------------:|
#' | SAF01 |
#'
#' **Numerator**: Population who self-report feeling safe walking alone in
#' their neighborhood after dark
#'
#' **Denominator**: Total population
#' **Formula**: *SAF01*=1,2 / *SAF01*=1,2,3,4
#'
#' This indicator comes from main dataset based on the respondent randomly
#' selected for individual level
#'
#' if unsafe or very unsafe 0, 98 and 99 go into blank
#' I never walk alone will also go into blank if any
#'
#' @param datalist A list with all hierarchical data frame for a survey data set.
#' format is expected to match the Excel export synchronized from kobo to RILD
#' and loaded with kobocruncher::kobo_data()
#'
#' @importFrom dplyr mutate case_when
#' @importFrom labelled labelled
#'
#' @return new calculated variable - appended or not...
#'
#' @export
impact3_3 <- function(datalist ){
# Mapper
mapper = list(
hierarchy = "main",
variablemap = data.frame(
label =
"1. How safe does ${name_selectedadult18} feel walking alone in your area/neighbourhood after dark?"
,
variable =
"SAF01"
),
modalitymap = data.frame(
variable =
c("SAF01", "SAF01", "SAF01", "SAF01", "SAF01", "SAF01")
,
label =
c("Very safe", "Fairly safe", "Bit unsafe", "Very unsafe", "Don\u2019t know",
"Prefer not to respond")
,
standard =
c("1", "2", "3", "4", "98", "99")
))
## So first we check that we have what we need in the data set based on the mapper
check_map <- fct_check_map(datalist = datalist,
mapper = mapper)
if ( check_map == FALSE) {
cat( "There are missing data requirement to calculate Indicator Impact 3.3")
} else {
datalist[["main"]]$impact3_3 <- dplyr::case_when(
as.integer(datalist[["main"]]$SAF01) == 1 |
as.integer(datalist[["main"]]$SAF01) == 2 ~ 1,
as.integer(datalist[["main"]]$SAF01) == 3 |
as.integer(datalist[["main"]]$SAF01) == 4 ~ 0 ,
as.integer(datalist[["main"]]$SAF01) == 98 |
as.integer(datalist[["main"]]$SAF01) == 99 ~ NA_real_)
datalist[["main"]]$impact3_3 <- labelled::labelled(datalist[["main"]]$impact3_3,
labels = c('Yes' = 1, 'No' = 0 ),
label = "Proportion of population that feel safe walking alone in their neighbourhood")
}
return(datalist)
}
```
```{r example-impact3_3, message=TRUE, warning=FALSE}
## data, cf example fct_re_map()
datalist <- kobocruncher::kobo_data( system.file("dummy_RMS_CAPI_v2_mapped.xlsx",
package = "IndicatorCalc"))
## Apply calculation
datalist <- impact3_3(datalist)