R/list_bias_data.R

Defines functions list_bias_data

Documented in list_bias_data

#' list_bias_data
#'
#' @param dat 
#'
list_bias_data <- function(dat){
  # get bias/mult info
  # is NOT yet set up to work for more than 1 country
  # (same multiplier would be assigned)
  # following old jags model implementation here
  # where 1 refers to no multiplier added
  data_biasmult <- dat %>%
    dplyr::mutate(geo.ind = ifelse(has_geographical_region_bias == "N", 
                                   1, 
                                   1+ 1)) %>% 
    #    tempHACK while update to fix fpemdata is pending, this allows for max 1 geobais per country only
    #                                   1+ as.numeric(as.factor(geographical_region_bias_reason)))) %>%
    # update LA 2019/3/30
    dplyr::mutate(hw.ind = ifelse(is.element(group_type_relative_to_baseline, c("BS", "HW", "PW")), 2, 1)) %>%
    dplyr::mutate(emal.ind = ifelse(is.element(group_type_relative_to_baseline, c("AL", "EM", "FM")), 2, 1)) %>%
    dplyr::mutate(sa.ind = ifelse(is.element(group_type_relative_to_baseline, c("SA")), 2, 1)) %>%
    dplyr::mutate(posbias.ind = ifelse(has_non_pregnant_and_other_positive_biases == "N", 1, 
                                       1+ 1)) %>%
    #    tempHACK while update to fix fpemdata is pending, this allows for max 1 posbais per country only
    #                                   1+ as.numeric(as.factor(non_pregnant_and_other_positive_biases_reason)))) %>%
    
    dplyr::mutate(age.ind = ifelse(age_group_bias != "?", 1, 2)) %>% # again, 1 is baseline
    dplyr::mutate(posage.ind = ifelse(age_group_bias != "+", 1, 2)) %>% # again, 1 is baseline
    dplyr::mutate(negage.ind = ifelse(age_group_bias != "-", 1, 2)) %>% # again, 1 is baseline
    dplyr::mutate(folk.ind = ifelse(has_traditional_method_bias == "Y", 1, 0)) %>%
    dplyr::mutate(source.MICS.ind = ifelse(has_absence_of_probing_questions_bias == "Y", 1, 0)) %>%
    dplyr::mutate(mpos.ind = ifelse(modern_method_bias == "+", 1, 0)) %>%
    dplyr::mutate(mneg.ind = ifelse(modern_method_bias == "-", 1, 0)) %>%
    dplyr::select(geo.ind, hw.ind, emal.ind, sa.ind, posbias.ind, age.ind, posage.ind, negage.ind,
                  folk.ind, source.MICS.ind, mpos.ind, mneg.ind)
  
  maxcat <- apply(data_biasmult, 2, max) # relevant for multipliers
  
  jagsdata_add <- c(
    as.list(data_biasmult),
    list(
      ncat.geo = maxcat['geo.ind'], 
      ncat.hw = maxcat['hw.ind'],
      ncat.emal = maxcat['emal.ind'], 
      ncat.sa = maxcat['sa.ind'],
      ncat.posbias = maxcat['posbias.ind'],
      ncat.age = maxcat['age.ind'],
      ncat.posage = maxcat['posage.ind'],
      ncat.negage  = maxcat['negage.ind']
    )
  )
  return(jagsdata_add)
}
FPRgroup/fpemmodeling documentation built on April 8, 2020, 12:32 p.m.