data-raw/validate_api_to_msd.R

## PROJECT: WAVELENGTH
## AUTHOR:  A.Chafetz, B.Kagniniwa, T.Essam | USAID
## PURPOSE: API VS MSD COMPARISON
## LICENSE: MIT
## UPDATED:


df_api <- update_meta_mer(upload = FALSE)

df_msd_agg <- glamr::si_path() %>%
  glamr::return_latest("OU_IM") %>%
  readr::read_rds()

df_msd_agg <- df_msd_agg %>%
  dplyr::filter(fiscal_year == 2021,
                fundingagency == "USAID",
                indicator %in% c("HTS_TST", "HTS_TST_POS", "TX_NEW", "TX_CURR", "PrEP_NEW", "VMMC_CIRC"),
                standardizeddisaggregate == "Total Numerator") %>%
  dplyr::group_by(countryname, indicator) %>%
  dplyr::summarise(mer_results = sum(cumulative, na.rm = TRUE),
                   mer_targets = sum(targets, na.rm = TRUE)) %>%
  dplyr::ungroup() %>%
  tidyr::pivot_longer(starts_with("mer"), names_to = "type", values_to = "value_msd")

df_api_agg <- df_api %>%
  dplyr::filter(indicator %in% c("HTS_TST", "HTS_TST_POS", "TX_NEW", "TX_CURR", "PrEP_NEW", "VMMC_CIRC")) %>%
  dplyr::group_by(countryname, indicator) %>%
  dplyr::summarise(mer_results = sum(mer_results, na.rm = TRUE),
                   mer_targets = sum(mer_targets, na.rm = TRUE)) %>%
  dplyr::ungroup() %>%
  tidyr::pivot_longer(starts_with("mer"), names_to = "type", values_to = "value_api")

df_combo <- dplyr::full_join(df_msd_agg, df_api_agg)

df_combo <- df_combo %>%
  dplyr::mutate(value_api = ifelse(is.na(value_api), 0, value_api),
                variance = value_api/value_msd,
                variance = ifelse(is.nan(variance), 1, variance)) %>%
  dplyr::arrange(variance)

glamr::prinf(df_combo)

df_combo %>%
  dplyr::filter(variance != 1) %>%
  glamr::prinf()
USAID-OHA-SI/Wavelength documentation built on March 24, 2023, 10:07 a.m.