-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalysis_2017_public.Rmd
3203 lines (2176 loc) · 89 KB
/
analysis_2017_public.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: "mics6 2017"
author: "Lisa"
date: "12 août 2021"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## analysis of mics6 2017 data
### set-up
```{r options}
# OR | operator
options(scipen = 999) # suppress scientific notion
```
```{r load and install}
## check which packages are not installed
## if packages are not installed; install them and load
# Code found originally here
# https://vbaliga.github.io/verify-that-r-packages-are-installed-and-loaded/
# now you can access it here:
# https://vbaliga.github.io/posts/2019-04-28-verify-that-r-packages-are-installed-and-loaded/
# revised to fit here
## First specify the packages of interest
packages = c("tidyverse",
"janitor",
"haven",
"sjPlot",
"lubridate",
"survey",
"naniar",
"jtools",
"MASS",
"car",
"viridis",
"lme4",
"gtsummary",
"ggpubr",
"sf",
"tmap")
## Now load or install&load all
package.check <- lapply(
packages,
FUN = function(x) {
if (!require(x, character.only = TRUE)) {
install.packages(x, dependencies = TRUE)
library(x, character.only = TRUE)
}
}
)
```
### data - import
```{r dataset mics6 ch}
mics6.ch <- read_sav("./data/mics6/ch.sav")
sjPlot::view_df(mics6.ch)
```
```{r dataset mics6 wm}
mics6.wm <- read_sav("./data/mics6/wm.sav")
sjPlot::view_df(mics6.wm)
```
### data - preparation
#### mics6.ch - children under five
```{r mics6.ch overview}
# Mothers or primary caretakers of children under five – ch.sav
dim(mics6.ch)
# [1] 11812 443
#glimpse(mics6.ch)
# look at lables
sjPlot::view_df(mics6.ch)
mics6.ch %>% labelled::look_for("UF4")
# Mother / caretaker
mics6.ch %>% count(UF4) # range from 1-20
```
```{r clean variable names}
# change names of variables
# ideally, variable names are all in lower case
# I want to be consistent with all my code
mics6.ch %>% clean_names() -> mics6.ch
```
```{r selecting variables children dataset}
mics6.ch_2 <- subset(mics6.ch, select = c("hh1", "hh2", "uf1", "uf2", "uf3", "uf4", "ub2", "cage", "caged", "hh6", "hh7", "hh7r", "uf7d", "uf7y", "uf7m", "ub1d", "ub1m", "ub1y", "im12a", "im12b", "im12c", "im2", "im5", "im11", "im15", "im20", "im21", "im6h0d", "im6h0m", "im6h0y", "im6penta1d", "im6penta1m", "im6penta1y", "im6penta2d", "im6penta2m", "im6penta2y", "im6penta3d", "im6penta3m", "im6penta3y", "ethnicity", "melevel", "windex5", "hl4", "chweight", "hh6a", "hh6b", "cdisability", "uf10"))
```
#### mics6.wm - women: selecting data
```{r mics6.wm overview}
dim(mics6.wm)
# [1] 26088 409
#glimpse(mics6.wm)
sjPlot::view_df(mics6.wm)
```
```{r mics6.wm clean names}
mics6.wm %>% clean_names() -> mics6.wm
```
```{r selecting variables in womens dataset}
# selecting subset of variables of women's dataset
mics6.wm_2 <- subset(mics6.wm, select = c("wm1", "wm2", "wm3", "hh1", "hh2", "ln",
"mn2", "mn3a", "mn3b", "mn3c", "mn3f",
"mn3g", "mn3x", "mn3nr", "mn5", "mn20",
"cm17", "mn19a", "mn19b", "mn19c", "mn19f",
"mn19g", "mn19h", "mn19x", "mn19y", "mn19nr",
"wmweight"))
# change variable name in women dataset in order to match with children's
mics6.wm_2$uf4 <- mics6.wm_2$ln
mics6.wm_2 %>% count(uf4, ln) # to check if same
```
#### merging mics6.ch and mics6.wm: mics6.ch.wm
```{r children and womens data}
# Merge joining variables from dataset woman to dataset children_2017 using as key variable: UF4 (mothers or caretakers line number in ch.sav).
# Common variables used to merge are: HH1, HH2, UF4 in children, LN in women
mics6.ch.wm <- merge(mics6.ch_2, mics6.wm_2, by=c("hh1", "hh2", "uf4"), all.x = TRUE)
sjPlot::view_df(mics6.ch.wm)
# Are there any "NAs" for the women data
# Sometimes, the caretaker who fills out the children Q is not the mother
# W3 is womens line number
mics6.ch.wm %>% summarise(count=sum(is.na(wm3)))
```
### data preparation: create variables
#### socio-economic factors
```{r hh id}
# Household ID
mics6.ch.wm %>%
unite(hh_id, c(hh1, hh2), sep = "_", remove = FALSE, na.rm = FALSE) -> mics6.ch.wm
# Are there any duplicates?
mics6.ch.wm %>% group_by(hh_id) %>% filter(n()>1) %>% summarize(n=n())
# yes
mics6.ch.wm %>%
filter(ub2 <3) %>%
group_by(hh_id) %>% filter(n()>1) %>% summarize(n=n())
```
```{r hh double}
mics6.ch.wm %>%
group_by(hh_id) %>% mutate(duplicate.hh = n()>1) %>% ungroup() -> mics6.ch.wm
mics6.ch.wm %>% count(duplicate.hh) # TRUE 5391
mics6.ch.wm %>%
group_by(hh_id) %>% mutate(hh.1x = (n() == 1))%>% ungroup() -> mics6.ch.wm
mics6.ch.wm %>% count(hh.1x) # 6421
mics6.ch.wm %>%
group_by(hh_id) %>% mutate(hh.2x =(n() == 2)) %>% ungroup() -> mics6.ch.wm
mics6.ch.wm %>% count(hh.2x) # 4172 # NOTE: TRUE means that hh is in dataset exactly twice; FALSE can mean anything else!
mics6.ch.wm %>%
group_by(hh_id) %>% mutate(hh.3x = (n() == 3)) %>% ungroup() -> mics6.ch.wm
mics6.ch.wm %>% count(hh.3x) # 963 # /3 = 321
mics6.ch.wm %>%
group_by(hh_id) %>% mutate(hh.4x = (n() == 4)) %>% ungroup() -> mics6.ch.wm
mics6.ch.wm %>% count(hh.4x)
mics6.ch.wm %>%
group_by(hh_id) %>% mutate(hh.5ormore = n()>5) %>% ungroup() -> mics6.ch.wm
mics6.ch.wm %>% count(hh.5ormore) # TRUE 19
####### These variables are subset-specific -> they need to be redefined for the different subsets
```
```{r child id}
# Need a unique id for each child
# UF3 should be the individual number of each child (LN of child)
# UF1 = HH1
# UF2 = HH2
mics6.ch.wm %>%
unite(ch_id, c(uf1, uf2, uf3), sep = "_", remove = FALSE, na.rm = FALSE) -> mics6.ch.wm
mics6.ch.wm %>% group_by(ch_id) %>% filter(n()>1) %>% summarize(n=n()) # none...
# identify each child
```
```{r psu}
# Primary sampling units in this survey
# should be the cluster
mics6.ch.wm %>% count(hh1) # 1160
mics6.ch.wm %>% count(hh_id) # 8888
```
```{r child order}
# Label the order of the children by household according to age
mics6.ch.wm %>%
group_by(hh_id) %>%
arrange(caged) %>% # youngest child = 1 - this way
mutate(child_order = row_number()) %>% ungroup() -> mics6.ch.wm
mics6.ch.wm %>%
filter(duplicate.hh == TRUE) %>%
arrange(hh_id) %>%
dplyr::select(hh_id, ch_id, ub2, child_order)
# This variable needs to be redefined in each subset -> child order may be different in the different subsets
```
```{r women id}
# WM1 cluster number
# WM2 household number
# WM3 line number
mics6.ch.wm %>%
unite(wm_id, c(wm1, wm2, wm3), sep = "_", remove = FALSE, na.rm = FALSE) -> mics6.ch.wm
# But be careful, can be the same as child id
mics6.ch.wm %>% group_by(wm_id) %>% filter(n()>1) %>% summarize(n=n())
# yes, now we have duplicates; sometimes more
# What about the NA_NA_NA
mics6.ch.wm %>% filter(wm_id == "NA_NA_NA") # 444
# Children for which there is no mother data
```
```{r women double}
# how many wm_ids are double?
mics6.ch.wm %>% group_by(wm_id) %>% mutate(dup.wm = n()>1) %>% ungroup -> mics6.ch.wm
mics6.ch.wm %>% count(dup.wm) # 5164
### This variable needs to be re-defined in each subset
```
```{r stratum}
mics6.ch.wm %>% unite(stratum, c(hh7, hh6), sep = "_", remove = FALSE, na.rm = FALSE) -> mics6.ch.wm
mics6.ch.wm %>% count(stratum)
```
```{r date of interview}
# Day of the interview
mics6.ch.wm$uf7d_2 <- as.numeric(as.character(mics6.ch.wm$uf7d))
mics6.ch.wm$uf7y_2 <- as.numeric(as.character(mics6.ch.wm$uf7y))
mics6.ch.wm$uf7m_2 <- as.numeric(as.character(mics6.ch.wm$uf7m))
mics6.ch.wm %>% mutate(i_date = make_date(uf7y_2, uf7m_2, uf7d_2)) -> mics6.ch.wm
```
```{r date of birth for child}
mics6.ch.wm$ub1d_2 <- as.numeric(mics6.ch.wm$ub1d)
mics6.ch.wm$ub1m_2 <- as.numeric(mics6.ch.wm$ub1m)
mics6.ch.wm$ub1y_2 <- as.numeric(mics6.ch.wm$ub1y)
mics6.ch.wm %>% mutate(dob_ch = make_date(ub1y_2, ub1m_2, ub1d_2)) -> mics6.ch.wm
```
```{r age}
mics6.ch.wm %>% mutate(ub2_2 = ifelse(ub2 == 0, 0, 1)) -> mics6.ch.wm
mics6.ch.wm %>% count(ub2, ub2_2)
# Need age also as factor
mics6.ch.wm %>% dplyr::mutate(ub2_f = as.factor(ub2)) -> mics6.ch.wm
mics6.ch.wm %>% count(ub2, ub2_2, ub2_f) # corresponds to ag2_3 in mics4
```
```{r region}
mics6.ch.wm %>% count(hh7r, hh7) # provinces are grouped
# new variable; "center" should be the reference
mics6.ch.wm %>% mutate(hh7r_2 = ifelse(hh7r == 2, 0,
ifelse(hh7r == 3, 2, 1))) -> mics6.ch.wm
mics6.ch.wm %>% count(hh7r, hh7, hh7r_2) # central regions are the reference
```
```{r ethnicity}
mics6.ch.wm %>% count(ethnicity)
mics6.ch.wm %>% mutate(ethnicity_r = ifelse(ethnicity == 1, 1,
ifelse(ethnicity == 2, 2,
ifelse(ethnicity == 3, 3, 4)))) -> mics6.ch.wm
mics6.ch.wm %>% count(ethnicity, ethnicity_r)
# The numbers for "Chinese-Tibetan" are very low
# variable should be grouped once more?
mics6.ch.wm %>% mutate(ethnicity_r_2 = ifelse(ethnicity == 1, 1,
ifelse(ethnicity == 2, 2,
ifelse(ethnicity == 3, 3, 2)))) -> mics6.ch.wm
mics6.ch.wm %>% count(ethnicity, ethnicity_r_2)
```
```{r melevel}
mics6.ch.wm %>% count(melevel)
mics6.ch.wm %>% mutate(melevel_r = ifelse(melevel == 0, 0, 1)) -> mics6.ch.wm
mics6.ch.wm %>% mutate(melevel_r_2 = ifelse(melevel == 0, 0,
ifelse(melevel == 1, 1, 2))) -> mics6.ch.wm
mics6.ch.wm %>% count(melevel, melevel_r_2)
```
```{r windex}
mics6.ch.wm %>% count(windex5) # 0 does not belong here: These are the non-responders
mics6.ch.wm %>% filter(windex5 == 0) %>% count(uf10) # not at home
# even if these are falling out later when creating the subset, the "level" could very well be there??
# replace with NA
mics6.ch.wm %>% replace_with_na(replace = list(windex5 = 0)) -> mics6.ch.wm
mics6.ch.wm %>% mutate(windex5_2 = ifelse(windex5 == 1, 1, 2)) -> mics6.ch.wm
mics6.ch.wm %>% mutate(windex5_3 = ifelse(windex5 == 1, 1,
ifelse(windex5 == 2, 1,
ifelse(windex5 == 3, 2,
ifelse(windex5 == 4, 2, 3))))) -> mics6.ch.wm
```
```{r area}
mics6.ch.wm %>% count(hh6, hh6a)
```
#### antenatal care variables
```{r anc mn2}
# Questions only asked for last pregnancy in two years
mics6.ch.wm %>% count(mn2) # Did you see anyone for antenatal care during your pregnancy
#mics6.ch.wm %>% replace_with_na(replace = list(MN2 = "9")) -> mics6.ch.wm
# we grouped DK and no response to "no" before. In order to be consistent, lets do it here too
mics6.ch.wm %>% mutate(mn2_2 = ifelse(mn2 == 9, "2",
ifelse(mn2 == 1, "1",
ifelse(mn2 == 2, "2", "")))) -> mics6.ch.wm
```
```{r anc mn5}
mics6.ch.wm %>% count(mn5) # How many times did you receive ANC during this pregnancy
#mics6.ch.wm %>% replace_with_na(replace = list(MN5 = "99")) -> mics6.ch.wm
# 98 are DK!!!!!!!
# No 99???
mics6.ch.wm %>% count(mn2, mn5) # MN5 only for MN2 yes
mics6.ch.wm %>% mutate(mn5_2 = ifelse(mn5 <= 3, 1,
ifelse(mn5 > 3, 2, ""))) -> mics6.ch.wm
mics6.ch.wm %>% count(mn5_2, mn5)
```
```{r anc mn2 and mn5 combined}
mics6.ch.wm %>% count(mn5_2)
mics6.ch.wm %>% count(mn2_2, mn5_2)
mics6.ch.wm %>% mutate(mn2_mn5 = ifelse((mn2_2 == 1 & mn5_2 == 1), 1,
ifelse((mn2_2 == 1 & mn5_2 == 2), 2, 0))) -> mics6.ch.wm
mics6.ch.wm %>% count(mn2_2, mn5_2, mn2_mn5)
# 0 no
# 1 yes, less than 4
# 2 yes, more than 4 visits, incl 4
```
```{r anc mn20 pob}
mics6.ch.wm %>% count(mn20) # Where did you give birth?
# 96 = Other
#mics6.ch.wm %>% replace_with_na(replace = list(MN20 = "99")) -> mics6.ch.wm
# Question was asked to women with a live birth in the last two years
# create another variable containing the info of mn20 (for the descriptive table)
class(mics6.ch.wm$mn20)
mics6.ch.wm %>% dplyr::mutate(mn20_2 = as_factor(mn20))-> mics6.ch.wm
mics6.ch.wm %>% mutate(pob = dplyr::recode(mn20,
"11" = "1",
"12" = "1",
"21" = "2",
"22" = "2",
"26" = "2",
"31" = "3",
"32" = "3",
"33" = "3",
"36" = "3",
"96" = "3"
)) -> mics6.ch.wm
mics6.ch.wm %>% count(pob)
mics6.ch.wm %>% mutate(pob_2 = dplyr::recode(mn20,
"11" = "1", # home
"12" = "1", # home
"21" = "3", # gov hospital
"22" = "2", # gov HC
"26" = "3", # gov other
"31" = "3", # priv hospital
"32" = "3", # priv clinic
"33" = "3", # priv mat. home
"36" = "3", # priv other
"96" = "3" # other
)) -> mics6.ch.wm
mics6.ch.wm %>% count(pob_2)
mics6.ch.wm %>% mutate(pob_3 = dplyr::recode(mn20,
"11" = "1", # home
"12" = "1", # home
"21" = "2", # gov hospital
"22" = "2", # gov HC
"26" = "2", # gov other
"31" = "2", # priv hospital
"32" = "2", # priv clinic
"33" = "2", # priv mat. home
"36" = "2", # priv other
"96" = "2" # other
)) -> mics6.ch.wm
mics6.ch.wm %>% count(pob_3)
```
```{r anc mn19 assistance at delivery}
#mics6.ch.wm %>% count(mn19A, mn19B, mn19C, mn19F, mn19G, mn19H, mn19X, mn19Y, mn19NR)
mics6.ch.wm %>%
unite(mn19_all, c("mn19a", "mn19b", "mn19c", "mn19f", "mn19g", "mn19h", "mn19x",
"mn19y", "mn19nr"), sep = "_", remove = FALSE, na.rm = FALSE) -> mics6.ch.wm
class(mics6.ch.wm$mn19_all)
mics6.ch.wm %>% count(mn19_all)
# First, replace na
# "NA_NA_NA_NA_NA_NA_NA_NA_NA"
# ________
mics6.ch.wm %>%
replace_with_na(replace = list(mn19_all = "NA_NA_NA_NA_NA_NA_NA_NA_NA")) -> mics6.ch.wm
mics6.ch.wm %>% count(mn19_all)
mics6.ch.wm %>%
replace_with_na(replace = list(mn19_all = "________")) -> mics6.ch.wm
mics6.ch.wm %>% count(mn19_all)
mics6.ch.wm %>%
mutate(mn19_all_1 = ifelse((str_detect(mn19_all, "A") |
(str_detect(mn19_all, "B") |
(str_detect(mn19_all, "C")))), 1, 0)) -> mics6.ch.wm
# 1 = doctor, nurse, midwife, aux nurse
# 0 = others: trad birth attendant, relative, friend, community health worker
mics6.ch.wm %>% count(mn2_2, mn19_all_1)
mics6.ch.wm %>% count(pob, mn19_all_1)
```
```{r mn19_pob}
# combination variable
# assistance at delivery & Place of birth
mics6.ch.wm %>% count(mn19_all_1, pob)
mics6.ch.wm %>% count(mn19_all_1, pob_3)
# 0 1 no skilled ass & home
# 1 2 skilled assistance & not born at home
# all the rest
# Variable: NO or DK
mics6.ch.wm %>% mutate(mn19_pob = ifelse((mn19_all_1 == 0 & pob_3 == 1), 0,
ifelse((mn19_all_1 == 1 & pob_3 == 2), 1, 2))) -> mics6.ch.wm
```
#### information regarding vaccination
```{r recall or not}
# IM11
mics6.ch.wm %>% filter(ub2 < 3) %>% count(im11)
# If vaccination card or any other documents are not available to be checked, im11 was asked
mics6.ch.wm %>% count(im11, im12a, im12b, im12c)
# If response to im11 and im11 was always No or DK; child did not receive any vaccination!
# Variable: NO or DK
mics6.ch.wm %>%
mutate(im11_im12 = ifelse((im11 == 2 | im11 == 8) &
(im12a == 2 | im12a == 8) &
(im12b == 2 | im12b == 8) &
(im12c == 2 | im12c == 8), 0, 1)) -> mics6.ch.wm
mics6.ch.wm %>% count(im11_im12, im11, im12a, im12b, im12c)
mics6.ch.wm %>% count(im11, im11_im12)
# looks ok
mics6.ch.wm %>%
unite(im12_all, c(im12a, im12b, im12c), sep = "_", remove = FALSE, na.rm = FALSE) -> mics6.ch.wm
mics6.ch.wm %>% count(im12_all)
# Table: is there vaccination card, vaccination document seen, recall
mics6.ch.wm %>% count(im2, im5, im11, im12_all) # all NAs in kids under 3 are recall; not NA
# New variable
# recall - 0: no; vaccination documents were there
# recall - 1: yes; no vaccination documents
# Recode all entries into "1"
mics6.ch.wm %>% count(im11)
mics6.ch.wm %>% mutate(recall = ifelse(im11 == 1, 1,
ifelse(im11 == 2, 1, 1))) -> mics6.ch.wm
mics6.ch.wm %>% count(recall) # ok
# Replace all NA in children under 3 with "0"
mics6.ch.wm %>% mutate(recall = replace(recall, is.na(recall) & ub2 <3, 0)) -> mics6.ch.wm
mics6.ch.wm %>% count(recall)
mics6.ch.wm %>% count(im11, recall, im5) # seems like it did work
# BUT: Sometimes for the IM6 responses, there was the option for mother´s report.... This is essentially recall!
# I would check that for each vaccination individually
# in the table for the descriptive analysis; recall only shows 1 level (numbers are correct)
# why is that?
mics6.ch.wm %>% count(recall)
class(mics6.ch.wm$recall) # is numeric?
# should be a factor
mics6.ch.wm %>% dplyr::mutate(recall = as.factor(recall)) -> mics6.ch.wm
mics6.ch.wm %>% count(recall)
class(mics6.ch.wm$recall)
```
```{r source of information}
# Sometimes, it is nice to re-check where information is coming from. IM2 only asks if participants have any of the vaccination documents
# IM5 actually says which of them was AVAILABLE
# IM5 is only asked if participants respond that they have any of the documents
# All NA in IM5 responded they do not possess any vaccination document
mics6.ch.wm %>% filter(ub2 < 3) %>% count(im2, im5)
# First, need to convert NAs in IM5
mics6.ch.wm %>% mutate(im5_2 = replace(im5, is.na(im5) & ub2 < 3, 5)) -> mics6.ch.wm
mics6.ch.wm %>% count(im2, im5, im5_2, recall)
# recall variable IM11 in combination with IM5_2
mics6.ch.wm %>% filter(ub2 < 3) %>% count(im5_2, im11)
```
```{r hepb0_c}
mics6.ch.wm %>% mutate(hepb0_c = if_else(im6h0d <= 31 & im6h0d >=1, 1,
if_else(im6h0d == 0, 0,
if_else(im6h0d == 44, 44, 66)))) -> mics6.ch.wm
mics6.ch.wm %>% count(hepb0_c)
# if date is there = 1
# marked on card = 44
# mother reported = 66 # technically recall
# not given = 0
```
```{r imh6h0_date}
# Convert to numeric values: day/ month/ year
mics6.ch.wm$im6h0d_2 <- as.numeric(mics6.ch.wm$im6h0d)
mics6.ch.wm$im6h0m_2 <- as.numeric(mics6.ch.wm$im6h0m)
mics6.ch.wm$im6h0y_2 <- as.numeric(mics6.ch.wm$im6h0y)
# Now create the date
mics6.ch.wm %>% mutate(im6h0_date = make_date(im6h0y_2, im6h0m_2, im6h0d_2)) -> mics6.ch.wm
mics6.ch.wm %>% count(im6h0_date) # looks ok
```
```{r im6h0_time}
# Are there some children without a birthdate?
# The time since vaccination will be calculated based on birthdate and data of vaccination
mics6.ch.wm %>% filter(hepb0_c == 1) %>% summarise(count=sum(is.na(dob_ch))) # 4
# Time since vaccination
mics6.ch.wm$im6h0_time <- as.numeric(difftime(mics6.ch.wm$im6h0_date,
mics6.ch.wm$dob_ch, units = "days"))
summary(mics6.ch.wm$im6h0_time)
# Comments on time since vaccination:
# no negative values! negative values would indicate mistakes in dob or date of vaccination
```
```{r hepb0_c24}
# Card: vaccinated within 24 hours
mics6.ch.wm %>%
mutate(hepb0_c24 = ifelse(im6h0_time == 0, 0,
ifelse(im6h0_time == 1, 1, 2))) -> mics6.ch.wm
mics6.ch.wm %>% count(hepb0_c24)
```
```{r hepb0_c_2}
mics6.ch.wm %>% count(hepb0_c, hepb0_c24)
# combination of card within 24 hours and card date variable
mics6.ch.wm %>%
unite(hepb0_c_2, c(hepb0_c, hepb0_c24), sep = "_", remove = FALSE, na.rm = FALSE) -> mics6.ch.wm
mics6.ch.wm %>% count(hepb0_c_2)
# 0_NA 807 # no
# 1_0 1902 # yes, same day
# 1_1 265 # yes, one day after
# 1_2 632 # yes, later
# 1_NA 4 # 4 ppl without dob
# 44_NA 100 # yes, marked on card
# 66_NA 29 # yes, but mother's recall
# NA_NA 8073 # NA
# NA_NA needs to be replaced with NA
mics6.ch.wm %>% naniar::replace_with_na(replace = list(hepb0_c_2 = "NA_NA")) -> mics6.ch.wm
mics6.ch.wm %>% count(hepb0_c_2)
# Now combine recall and info from card
```
```{r hepb0_c_3}
# Need to recode
# 1_NA 4 these two categories mean that we dont know when they were vaccinated
# 44_NA 100
# 0_NA # 0
# 1_0 # 1_0
# 1_1 # 1_1
# 1_2 # 1_2
# 1_NA # 1_3
# 44_NA # 1_3
# 66_NA # 2
mics6.ch.wm %>%
mutate(hepb0_c_3 = ifelse(hepb0_c_2 == "0_NA", "C_0",
ifelse(hepb0_c_2 == "1_0", "C_1_0",
ifelse(hepb0_c_2 == "1_1", "C_1_1",
ifelse(hepb0_c_2 == "1_2", "C_1_2",
ifelse(hepb0_c_2 == "1_NA", "C_1_3",
ifelse(hepb0_c_2 == "44_NA", "C_1_3",
ifelse(hepb0_c_2 == "66_NA", "C_2", "")))))))) -> mics6.ch.wm
mics6.ch.wm %>% count(hepb0_c_2, hepb0_c_3)
```
```{r hepb0_r}
# First recode IM15 into hepb0_R: recall variable
mics6.ch.wm %>% count(im15)
mics6.ch.wm %>%
mutate(hepb0_r = dplyr::recode(im15,
"1" = "R_1",
"2" = "R_2",
"3" = "R_0",
"8" = "R_3",
"9" = "R_3")) -> mics6.ch.wm
mics6.ch.wm %>% count(im15, hepb0_r)
# R_0 # no
# R_1 # within 24 h
# R_2 # later
# R_3 # DK
mics6.ch.wm %>% count(recall, hepb0_r, im11_im12, im11)
# It is not yet correct
# In IM11 & IM12; if all responses were "NO"; there was no probing for the recall of vaccinations
# Therefore; soome of the NAs in the new variable need to be changed to "No" or "DK" #810 no and #24 DK
mics6.ch.wm %>%
mutate(hepb0_r = replace(hepb0_r, is.na(hepb0_r) & im11 == 2, "R_0")) %>%
mutate(hepb0_r = replace(hepb0_r, is.na(hepb0_r) & im11 == 8, "R_3")) -> mics6.ch.wm
mics6.ch.wm %>% count(hepb0_r)
```
```{r hepb0_rc}
# combine both recall and card variables
mics6.ch.wm %>% count(hepb0_r, hepb0_c_3)
mics6.ch.wm %>% mutate(hepb0_rc = coalesce(hepb0_r, hepb0_c_3)) -> mics6.ch.wm
mics6.ch.wm %>% count(hepb0_rc)
# Now, all responses should be categorized correctly !!!
mics6.ch.wm %>% count(recall, hepb0_rc, im11_im12, im11)
mics6.ch.wm %>% count(recall, hepb0_rc) # 29 people - should be recall!!
```
```{r hepb0_rc_2}
# hepatitis B birth dose (yes, no)
# DK will be grouped with no # NO RESPONSE will be grouped with no
# vaccination received; Within 24 hours or the next day, or later: 1
# no vaccination: 0
mics6.ch.wm %>%
mutate(hepb0_rc_2 = dplyr::recode(hepb0_rc,
"C_0" = "0",
"C_1_0" = "1",
"C_1_1" = "1",
"C_1_2" = "1",
"C_1_3" = "1",
"C_2" = "1",
"R_0" = "0",
"R_1" = "1",
"R_2" = "1",
"R_3" = "0")) -> mics6.ch.wm
mics6.ch.wm %>% count(hepb0_rc_2)
```
```{r hepb0_rc_3}
# hepatitis B birth dose (yes, no) - but according to source
# no difference between 24 h, same day, next day
# DK will be grouped with no # NO RESPONSE will be grouped with no
# no vaccination: 0
mics6.ch.wm %>%
mutate(hepb0_rc_3 = dplyr::recode(hepb0_rc,
"C_0" = "C_0",
"C_1_0" = "C_1",
"C_1_1" = "C_1",
"C_1_2" = "C_2",
"C_1_3" = "C_2",
"C_2" = "R_2",
"R_0" = "R_0",
"R_1" = "R_1",
"R_2" = "R_2",
"R_3" = "R_0")) -> mics6.ch.wm
mics6.ch.wm %>% count(hepb0_rc_3, hepb0_rc)
```
```{r penta1_c}
# convert to numeric + recode
mics6.ch.wm %>% mutate(penta1_c = if_else(im6penta1d <= 31 & im6penta1d >=1, 1,
if_else(im6penta1d == 0, 0,
if_else(im6penta1d == 44, 44, 66)))) -> mics6.ch.wm
mics6.ch.wm %>% count(penta1_c)
# if date is there = 1
# marked on card = 44
# mother reported = 66 # technically recall
# not given = 0
```
```{r penta1_date}
# Convert to numeric values: day/ month/ year
mics6.ch.wm$im6penta1d_2 <- as.numeric(mics6.ch.wm$im6penta1d)
mics6.ch.wm$im6penta1m_2 <- as.numeric(mics6.ch.wm$im6penta1m)
mics6.ch.wm$im6penta1y_2 <- as.numeric(mics6.ch.wm$im6penta1y)
# Now create the date
mics6.ch.wm %>% mutate(penta1_date =
make_date(im6penta1y_2, im6penta1m_2, im6penta1d_2)) -> mics6.ch.wm
mics6.ch.wm %>% count(penta1_date) # looks ok
```
```{r penta1_time}
# Are there some children without a birthdate?
# The time since vaccination will be calculated based on birthdate and data of vaccination
mics6.ch.wm %>% filter(penta1_c == 1) %>% summarise(count=sum(is.na(dob_ch))) # 3
# Time since vaccination
mics6.ch.wm$penta1_time <- as.numeric(difftime(mics6.ch.wm$penta1_date,
mics6.ch.wm$dob_ch, units = "days"))
summary(mics6.ch.wm$penta1_time)
# Comments on time since vaccination:
# no negative values! negative values would indicate mistakes in dob or date of vaccination
```
```{r penta1_c_2}
mics6.ch.wm %>% count(penta1_c)
# 66 needs to be replaced with NA because this is recall info and not card info
mics6.ch.wm$penta1_c_2 <- mics6.ch.wm$penta1_c
mics6.ch.wm %>% replace_with_na(replace = list(penta1_c_2 = "66")) -> mics6.ch.wm
mics6.ch.wm %>% count(penta1_c_2)
```
```{r penta1_c_3}
mics6.ch.wm %>% mutate(penta1_c_3 = ifelse(penta1_c == 0, "C_0",
ifelse(penta1_c == 1, "C_1",
ifelse(penta1_c == 44, "C_44", "C_66")))) -> mics6.ch.wm
mics6.ch.wm %>% count(penta1_c, penta1_c_3)
```
```{r penta recall}
mics6.ch.wm %>% count(im20, im21)
# R_0 # did not receive vaccination
# R_1-1 # received only 1 dose
# R_1-2 # received at least 2 doses
# R_1-3 # received at least 3 doses or more
# R_8 # DK
# R_9 # No response (missing)