# OBJECTIVE 3 ANNUAL SURVEY - INDONESIA: HOUSEHOLD - 11 Nov 2019 to ??
library (tidyverse)
library (lubridate)
library (stringr)
rm(list = ls())
setwd("S:/R-MNHS-SPHPM-EPM-IDEpi/RISE/4. Surveys/3. Objectives/2. ID/3/20191118_T4_annual_survey/2. Data/1. raw data")
# DEFINE TODAY FOR DAILY QC - this is the date of data collection
date <- "2019-11-11"
day.qc <- ymd (date)
rm(date)
###############
# OPEN DATA FILES
###############
# HOUSEHOLD SURVEY
hhd <- read_csv (file = "T4_ID_annual_v1.csv")
child_loop <- read_csv (file = "T4_ID_annual_v1-child_loop.csv")
child_feces_kit <- read_csv (file = "T4_ID_annual_v1-feces_kit.csv")
#upload all files so corrections script can run
#add this once collecting feces samples
setwd("S:/R-MNHS-SPHPM-EPM-IDEpi/RISE/4. Surveys/3. Objectives/2. ID/3/20190527_O3_4_6mo_survey/3. ID/2. Data/1. raw data/practice data")
feces <- read_csv (file = "RISE_O3_feces_ID_v2_practice.csv")
child_feces_collect <- read_csv (file = "RISE_O3_feces_ID_v2_practice-feces_collection.csv")
###############
# FIX DATES
###############
# need to fix dates to allow for return visits with survey left open (can't use "today")
hhd$endtime <- date(dmy_hms (hhd$endtime))
#############################################
## Correct known errors in the data ##
#############################################
# setwd("S:/R-MNHS-SPHPM-EPM-IDEpi/RISE/4. Surveys/3. Objectives/2. ID/3/20190902_O3_stool sampling/2. Data/2. code")
# source("O3_T3_ID-corrections.R")
# setwd("S:/R-MNHS-SPHPM-EPM-IDEpi/RISE/4. Surveys/3. Objectives/2. ID/3/20190902_O3_stool sampling/2. Data")
#MERGE
child <- full_join(hhd, child_feces_kit, by = c("KEY" = "PARENT_KEY"))
child_survey <- full_join(hhd, child_loop, by = c("KEY" = "PARENT_KEY"))
feces_pickup <- full_join(feces, child_feces_collect, by = c("KEY" = "PARENT_KEY"))
#############################################
#############################################
# SUBSET - ONLY DATA COLLECTED TODAY
#############################################
#############################################
subhhd <- subset (hhd, endtime == day.qc,
select = c (extract_settlement, settlement_barcode, extract_house_no, gift_yn, feces_participate, verify1,
duration15, time12, time13))
subchild <- subset (child, endtime == day.qc,
select = c (extract_settlement, settlement_barcode, extract_house_no, feces_kit_barcode,
feces_kit_barcode_note))
subchildsurvey <- subset (child_survey, endtime == day.qc,
select = c (extract_settlement, settlement_barcode, extract_house_no, child_no_survey, health_general_child))
subfeces <- subset (feces_pickup, endtime == day.qc,
select = c (extract_settlement, settlement_barcode, extract_house_no, feces_sample_yn, barcode_feces,
barcode_feces_text))
#############################################
#############################################
# DAILY QC REPORT
#############################################
#############################################
#############################################
####### what settlements were visited #######
#############################################
#household surveys:
settlement_hhd <- subhhd %>%
select (settlement_barcode)
# then group
settlement.hhd <- settlement_hhd %>%
arrange (settlement_barcode) %>%
group_by (settlement_barcode) %>%
summarize (count = n ())
settlement.list.hhd <- pull (settlement.hhd, var = settlement_barcode)
#feces pickup
settlement_feces <- subfeces %>%
select (settlement_barcode)
# then group
settlement.feces <- settlement_feces %>%
arrange (settlement_barcode) %>%
group_by (settlement_barcode) %>%
summarize (count = n ())
settlement.list.feces <- pull (settlement.feces, var = settlement_barcode)
#############################################
# HOUSEHOLD SURVEYS
#############################################
#number started
nrow(subhhd)
#number of hhd surveys
hhd.complete <- subhhd %>%
filter (!is.na(gift_yn))
#############################################
# FECES KITS HANDED OUT
#############################################
#CHILD
kit_child <- subchild %>%
filter (!is.na(feces_kit_barcode) | !is.na(feces_kit_barcode_note))
#############################################
# health surveys completed
#############################################
#CHILD
survey_child <- subchildsurvey %>%
filter (is.na(child_no_survey) & !is.na(health_general_child))
#############################################
# feces samples collected
#############################################
#CHILD
feces_samples <- subfeces %>%
filter (!is.na(barcode_feces) | !is.na(barcode_feces_text))
#############################################
# survey length
#############################################
#FULL SURVEY
survey_time <- subhhd %>%
filter (gift_yn==1) %>% #only surveys that progressed; someone at home
mutate (dur15 = duration15/60)
summary(survey_time$dur15)
#collective efficacy and action
o5 <- subhhd %>%
filter (gift_yn==1) %>% #only surveys that progressed; someone at home
mutate (t12 = ymd_hms (time12),
t13 = ymd_hms (time13),
dur = (t13 - t12)/60)
summary(as.integer(o5$dur))
#############################################
# VERIFICATION ERRORS
# check that all surveys collected were verified by respondents
hhd.no.verify <- subhhd %>%
filter (verify1 == 0)
feces.no.verify <- subfeces %>%
filter (verify1 == 0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.