-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecks.Rmd
435 lines (362 loc) · 15.1 KB
/
checks.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
---
title: "R Notebook"
output:
html_document:
df_print: paged
---
*This is a test. let me know what you think.*
# Setting workspace
```{r, echo=FALSE, warning=F}
source("functions.R")
library(tidyverse)
readxl::excel_sheets("REACH_SOM2101_JMCNA_CleanData_v5.xlsx")
cleann <- readxl::read_excel("REACH_SOM2101_JMCNA_CleanData_v5.xlsx", "Clean_Data")
logg <- readxl::read_excel("REACH_SOM2101_JMCNA_CleanData_v5.xlsx", "Cleaning_Log")
raww <- readxl::read_excel("REACH_SOM2101_JMCNA_CleanData_v5.xlsx", "Raw_Data")
dell <- readxl::read_excel("REACH_SOM2101_JMCNA_CleanData_v5.xlsx", "Deletions")
```
# Checking your cleaning log
I am checking your cleaning log against your clean data.
```{r, echo=FALSE, warning=F}
old_new_values <- mapply(old_new,
cleaning_log = split(logg, row.names(logg)),
variable = "Question",
MoreArgs = list(
data_raw = raww,
data_clean = cleann,
uuid_raw = "uuid",
uuid_clean = "uuid",
uuid_cleaning_log = "uuid"
),
SIMPLIFY = F) %>% do.call(rbind, .)
dd <- logg %>%
mutate(binding = paste0(uuid, Question)) %>%
left_join(old_new_values) %>%
mutate(check_raw = `Old Value` == value_raw,
check_clean = `New Value` == value_clean) %>%
select(-c(binding, ID, `Follow-up`, Enumerator, Community, `Modified by?`, Notes, check_raw),
uuid, Question,`Old Value`, `New Value`, value_raw, value_clean, check_clean, Reason)
```
```{r}
dd$check_clean %>% table(useNA = "ifany")
```
Out of your 25k entries, you have 12k correct, 4k not correct and 10k as NA.
## NA's
Let's now just focus on the NA
```{r}
dd %>%
filter(is.na(check_clean)) %>%
group_by(Question) %>%
tally() %>%
arrange(desc(n))
```
### How-to read
```{r}
dd %>% head()
```
Question: from your cleaning log
uuid: uuid
Old Value: from your cleaning log
New value: from your cleaning log
Reason: from your cleaning log
value_raw : value from raw dataset
value_clean: value from clean dataset
check_clean: New Value (from cleaning log) is the same as value_clean (from clean data)
### ALL
```{r}
logg %>% filter(Question == "All") %>% mutate(uuid_dup = duplicated(uuid))
```
there are 1681 survey deleted, there are 1676 in the deletion log.
there are 9 uuid duplicated in the cleaning log for deletion
action: none needed.
### sanitation_features_other:
```{r}
dd %>% filter(Question == "sanitation_features_other", is.na(check_clean))
```
it seems there are 10% of the household who does not have toilets.
action: to be check with the skip logic
### main_source_water_other
```{r}
dd %>% filter(Question == "main_source_water_other", is.na(check_clean))
dd %>%
filter(Question == "main_source_water_other", is.na(check_clean)) %>%
select(uuid, `New Value`) %>%
left_join(select(cleann, main_source_water, uuid))
```
action: Explore what happened, was the "other" recoded?
### when_arrived_current_location
```{r}
dd %>% filter(Question == "when_arrived_current_location", is.na(check_clean)) %>%
View()
```
In your cleaning log, the "New Value" is empty, while there is a value in the clean dataset. No reason written
action: Explore what happened
### when_leave_place_origin
```{r}
dd %>% filter(Question == "when_leave_place_origin", is.na(check_clean)) %>%
View()
```
Same as above.
### 67"
```{r}
dd %>% filter(Question == "67", is.na(check_clean))
```
Not sure what 67 variable is for, but same as above. In addition, all of them were turn to 67 while the value were different
Action: investigate on your side.
### sanitation_facilities_problems_other
```{r}
dd %>% filter(Question == "sanitation_facilities_problems_other", is.na(check_clean)) %>%
pull(Reason) %>% table()
dd %>% filter(Question == "sanitation_facilities_problems_other", is.na(check_clean),
Reason != "other options recoded",
Reason != "other options recoded in the choice list")
dd %>%
filter(Question == "sanitation_facilities_problems_other", is.na(check_clean),
Reason != "other options recoded",
Reason != "other options recoded in the choice list") %>%
select(uuid, `New Value`) %>%
left_join(select(cleann, sanitation_facilities_problems, uuid)) %>%
select(`New Value`, sanitation_facilities_problems) %>% table()
```
Same as for main source of water. Check if recoding happened or should happen.
Action: explore what happened when recoding other.
### shelter_issues_other
```{r}
dd %>%
filter(Question == "shelter_issues_other", is.na(check_clean))
dd %>%
filter(Question == "shelter_issues_other", is.na(check_clean))%>%
select(uuid, `New Value`) %>%
left_join(select(cleann, shelter_issues, uuid)) %>%
select(`New Value`, shelter_issues) %>% table()
```
It seems there is "no issues". Should it be removed as you did then? Or removed?
Action: investigate if re-coding correct.
### hh_main_source_income_other
```{r}
dd %>%
filter(Question == "hh_main_source_income_other", is.na(check_clean)) %>%
select(uuid, `Old Value`) %>%
left_join(select(cleann, shelter_issues, uuid))
dd %>%
filter(Question == "hh_main_source_income_other", is.na(check_clean)) %>%
pull(Reason) %>%
table()
dd %>%
filter(Question == "hh_main_source_income_other", is.na(check_clean)) %>%
select(uuid, `Old Value`) %>%
left_join(select(cleann, starts_with("hh_main_source_income"), uuid))
```
does Clarification from choices and Clarification from translation means re-classfied?
Action: Check if clarification were correclty re-coded/classified.
### common_type_ids_other
```{r}
dd %>%
filter(Question == "common_type_ids_other", is.na(check_clean)) %>%
select(uuid, `Old Value`, `New Value`) %>%
left_join(select(cleann, starts_with("common_type_ids"), uuid))
```
Same as the the others "other"
Action: check recoding and action.
### General comment
For all others that are removed because of "none", maybe because of missing skip logic during the coding,
do you need to also remove all the questions? or add a "none" in your select mutiple? Or do you want just to report as
that and include the "no-issues" in the denominator?
e.g. do you want to report :
(1) XX % of households reported to have an issue. From the ones reporting an issue, YY% reported as OPTION1 as an issue.
(2) Amongst all the households, XX% reported no issues, YY% reported OPTION1 as an issue.
for (1) you would want to recode the none as missing for all options so that you can use the skiplogic.
## wrong cleaning value.
```{r}
dd %>% filter(check_clean == F)
dd %>% filter(check_clean == F) %>% nrow()
```
### re-coding FALSE and TRUE to 0/1
```{r}
logg2 <- logg %>%
mutate(`New Value` = ifelse(`New Value` == "FALSE", 0, `New Value`),
`New Value`= ifelse(`New Value` == "TRUE", 1, `New Value`))
old_new_values2 <- mapply(old_new,
cleaning_log = split(logg2, row.names(logg2)),
variable = "Question",
MoreArgs = list(
data_raw = raww,
data_clean = cleann,
uuid_raw = "uuid",
uuid_clean = "uuid",
uuid_cleaning_log = "uuid"
),
SIMPLIFY = F) %>% do.call(rbind, .)
dd2 <- logg2 %>%
mutate(binding = paste0(uuid, Question)) %>%
left_join(old_new_values2) %>%
mutate(check_raw = `Old Value` == value_raw,
check_clean = `New Value` == value_clean) %>%
select(-c(binding, ID, `Follow-up`, Enumerator, Community, `Modified by?`, Notes, check_raw),
uuid, Question,`Old Value`, `New Value`, value_raw, value_clean, check_clean, Reason)
dd2 %>% filter(check_clean == F) %>% nrow()
```
With changing the T/F we are reducing to 705 wrong values!
```{r}
dd2 %>% filter(check_clean == F)
```
It seems "casuel _labour _Wages _construction _etc" has a typo.
```{r}
dd2 %>% filter(check_clean == F,
`New Value` != "casuel _labour _Wages _construction _etc") %>% nrow()
```
Down to 535.
```{r}
dd2 %>% filter(check_clean == F,
`New Value` != "casuel _labour _Wages _construction _etc")
```
It seems some values are off.
Action: please check those.
# cleaninginspectoR
```{r}
inspec <- cleaninginspectoR::inspect_all(cleann, "uuid")
```
It seems you have lots of outliers.
```{r}
inspec %>%
filter(issue_type %in% c("log normal distribution outlier", "normal distribution outlier")) %>%
group_by(variable) %>%
tally()
```
Action: Please check all those variables for LOW and HIGH values.
# Extra check:
## calculations
I don't have the KOBO so I am just checking the obvious one
### calculation total hh
```{r}
cleann %>%
select(males_0_2y:total_hh) %>%
mutate(across(.fns = as.numeric)) %>%
mutate(total_cal = rowSums(across(males_0_2y:females_60_older)),
check = total_cal == total_hh) %>%
pull(check) %>%
table(useNA = "ifany")
```
All good
Action: none needed
### age_pregnent_female_give_birth
```{r}
cleann$age_pregnent_female_give_birth %>% table(useNA = "ifany")
```
Action: change the 1 year old pregnant woman to NA?
## checks outliers LOW
I am not sure what does estimate_hh_income refers to but you have very low values all the estimate_hh_income.XXXX have very low values. People earning .20 dollars. See below for anything less than 5(USD?) (0's excluded)
```{r}
cleann %>%
select(uuid, starts_with("estimate_hh_income.")) %>%
mutate(across(starts_with("estimate_hh_income."), ~(. < 5 & . > 0), .names = "{.col}_less_5"))
```
Action: needed please checked those values.
## calculation part 2
### hh_children
```{r}
cleann %>%
mutate(across(.cols = males_0_2y:females_12_17y, .fns = as.numeric)) %>%
mutate(total_cal = rowSums(across(males_0_2y:females_12_17y)),
check = total_cal == hh_children) %>%
pull(check) %>%
table(useNA = "ifany")
cleann %>%
mutate(across(.cols = males_0_2y:females_12_17y, .fns = as.numeric)) %>%
mutate(total_cal = rowSums(across(males_0_2y:females_12_17y)),
check = total_cal == hh_children) %>%
filter(check == F) %>%
select(uuid, males_0_2y:females_12_17y,hh_children, total_cal)
```
There are calculations that were not corrected.
Action: Please ammend
### school_age_children
```{r}
cleann %>%
mutate(across(.cols = males_3_5y:females_12_17y, .fns = as.numeric)) %>%
mutate(total_cal = rowSums(across(males_3_5y:females_12_17y)),
check = total_cal == school_age_children) %>%
filter(check == F) %>%
select(uuid, males_3_5y:females_12_17y,school_age_children, total_cal)
```
As above.
### hh_female
The KOBO calculation includes children males and females from 6 to 11. That variable is only used to
filter on the *pregnant_female_give_birth*. If you are not going to analyse it, just delete it
After checking for only females from 12 to 59, you should turn about 380 *pregnant_female_give_birth* and the
2 follow-up questions *pregnant_female_give_birth_yes*, *age_pregnent_female_give_birth* to NA.
```{r}
cleann %>%
mutate(across(.cols = c(females_12_17y, females_18_40, females_41_59), .fns = as.numeric)) %>%
mutate(check_female = rowSums(across(c(females_12_17y, females_18_40, females_41_59))) > 0) %>%
select(check_female, pregnant_female_give_birth) %>%
table(useNA = "ifany")
cleann %>%
mutate(across(.cols = c(females_12_17y, females_18_40, females_41_59), .fns = as.numeric)) %>%
mutate(check_female = rowSums(across(c(females_12_17y, females_18_40, females_41_59))) > 0,
to_be_fixed = check_female == F & !is.na(pregnant_female_give_birth) ) %>%
filter(to_be_fixed == T) %>%
select(uuid, check_female, pregnant_female_give_birth, pregnant_female_give_birth_yes, age_pregnent_female_give_birth)
```
### sum_persons_having_difficulty
You are suming ${seeing_memb}+${hearing_memb}+${walking_climbing_memb}+${remembering_memb}+${selft_care_memb}+${communicating_memb}
and then create a loop from it. If you a person had 2 difficulites, you would have a sum of 2, hence creating a loop for 2 persons and not one.
Action: how are you going to deal with that?
### sum_rooms
```{r}
cleann %>%
mutate(across(.cols = shelt_count.bedrooms:shelt_count.other_sh, .fns = as.numeric)) %>%
mutate(total_cal = rowSums(across(shelt_count.bedrooms:shelt_count.other_sh)),
check = total_cal == shelt_count.sum_rooms) %>%
filter(check == F) %>%
select(uuid, males_3_5y:females_12_17y,school_age_children, total_cal)
```
There 1849 calculation to be corrected.
Action: please ammend or remove the column if not needed
# list of checks not implemented?
From your script you shared, you have a list of checks that were not implemented:
- pregnant_female_give_birth_yes > 2
- age_pregnent_female_give_birth < 15
- children_working.permanent_job_child_male > 3
- children_working.permanent_job_child_female > 3
- sharing_sanitation_facilities_yes > 14 "how more then 14 hh share a latrine?"
- how_many_shelters > 8 "how one hh can own 8 or more shelters?"
- shelter_rooms_note > 3
- shelt_count.bedrooms > 3
- shelt_count.living_rooms > 3
- shelt_count.kitchens > 3
- shelt_count.toilets shelt_count.other_sh > 3
- shelt_count.sum_rooms > 3
Why were those not checked?
## Check for shelter rooms above 3
```{r}
cleann %>%
select(uuid, shelt_count.bedrooms:shelt_count.other_sh) %>%
mutate(across(shelt_count.bedrooms:shelt_count.other_sh, ~ (.> 3), .names = "{.col}_above_3")) %>%
summarise(across(ends_with("above_3"), sum))
cleann %>%
select(uuid, shelt_count.bedrooms:shelt_count.other_sh) %>%
mutate(across(shelt_count.bedrooms:shelt_count.other_sh, ~ (.> 3), .names = "{.col}_above_3"))
```
## time residency
I am not sure what this refers to but the number of months is not the conversion of years into months. Please check again those
variables as they currently do not make sense.
# HHS
```{r}
cleann %>%
mutate(hhs1 = case_when(how_often_fs_happen == "often_10_plus" ~ 2,
how_often_fs_happen %in% c("rately_1_2", "sometimes_3_10") ~ 1,
is.na(how_often_fs_happen) ~ 0),
hhs2 = case_when(often_go_sleep_night_hungry == "often_10_plus" ~ 2,
often_go_sleep_night_hungry %in% c("rately_1_2", "sometimes_3_10") ~ 1,
is.na(often_go_sleep_night_hungry) ~ 0),
hhs3 = case_when(often_not_eating_whole_day_night == "often_10_plus" ~ 2,
often_not_eating_whole_day_night %in% c("rately_1_2", "sometimes_3_10") ~ 1,
is.na(often_not_eating_whole_day_night) ~ 0),
hhs_score = hhs1 + hhs2 + hhs3,
hhs_cat = cut(hhs_score, breaks = c(0,5,7), labels = c("low-none-severe", "extreme"), right = F)) %>%
select(hhs_cat, district) %>% table(useNA = "ifany") %>% prop.table(2)
```
bonndheere, wadajir and yaarqshiid are at the 5% threshold. If any HHS score for a strata is above 5 % we should check
with Matt and Katie.
Action: Are you going to report as Banadir as a whole or for each city boundary ? (maybe Khada and Dharkenley)