'''
Load Data --------------------------------------------------------------------
dhs_all_df <- readRDS(file.path(dhs_dir, "FinalData", "Individual Datasets",
-
"survey_socioeconomic_hhlevel.Rds"))
dhs_all_df_coll <- readRDS(file.path(dhs_dir, "FinalData", "Individual Datasets",
-
"survey_socioeconomic_varconstructed_tmp.Rds"))
c_dhs <- unique(dhs_all_df_coll$country_code) %>% sort()
Within Country Folds ---------------------------------------------------------
dhs_gadm_cw <- bind_rows(
- data.frame(code_dhs = "AO", code_gadm = "AGO"),
- data.frame(code_dhs = "BF", code_gadm = "BFA"),
- data.frame(code_dhs = "BJ", code_gadm = "BEN"),
- data.frame(code_dhs = "CD", code_gadm = "COD"),
- data.frame(code_dhs = "CF", code_gadm = "CAF"),
- data.frame(code_dhs = "CG", code_gadm = "COG"),
- data.frame(code_dhs = "CI", code_gadm = "CIV"),
- data.frame(code_dhs = "CM", code_gadm = "CMR"),
- data.frame(code_dhs = "EG", code_gadm = "EGY"),
- data.frame(code_dhs = "ET", code_gadm = "ETH"),
- data.frame(code_dhs = "GA", code_gadm = "GAB"),
- data.frame(code_dhs = "GH", code_gadm = "GHA"),
- data.frame(code_dhs = "GM", code_gadm = "GMB"),
- data.frame(code_dhs = "GN", code_gadm = "GIN"),
- data.frame(code_dhs = "KE", code_gadm = "KEN"),
- data.frame(code_dhs = "KM", code_gadm = "COM"),
- data.frame(code_dhs = "LS", code_gadm = "LSO"),
- data.frame(code_dhs = "MA", code_gadm = "MAR"),
- data.frame(code_dhs = "ML", code_gadm = "MLI"),
- data.frame(code_dhs = "MR", code_gadm = "MRT"),
- data.frame(code_dhs = "MW", code_gadm = "MWI"),
- data.frame(code_dhs = "MZ", code_gadm = "MOZ"),
- data.frame(code_dhs = "NG", code_gadm = "NGA"),
- data.frame(code_dhs = "RW", code_gadm = "RWA"),
- data.frame(code_dhs = "SL", code_gadm = "SLE"),
- data.frame(code_dhs = "SN", code_gadm = "SEN"),
- data.frame(code_dhs = "SZ", code_gadm = "SWZ"),
- data.frame(code_dhs = "TD", code_gadm = "TCD"),
- data.frame(code_dhs = "TG", code_gadm = "TGO"),
- data.frame(code_dhs = "TZ", code_gadm = "TZA"),
- data.frame(code_dhs = "UG", code_gadm = "UGA"),
- data.frame(code_dhs = "ZA", code_gadm = "ZAF"),
- data.frame(code_dhs = "ZM", code_gadm = "ZMB"),
- data.frame(code_dhs = "ZW", code_gadm = "ZWE")
- ) %>%
- mutate(code_dhs = code_dhs %>% as.character,
-
code_gadm = code_gadm %>% as.character)
cc_dhs <- unique(dhs_gadm_cw$code_gadm) %>% sort()
print(cc_dhs)
[1] "AGO" "BEN" "BFA" "CAF" "CIV" "CMR" "COD" "COG" "COM" "EGY" "ETH" "GAB"
[13] "GHA" "GIN" "GMB" "KEN" "LSO" "MAR" "MLI" "MOZ" "MRT" "MWI" "NGA" "RWA"
[25] "SEN" "SLE" "SWZ" "TCD" "TGO" "TZA" "UGA" "ZAF" "ZMB" "ZWE"dhs_all_df_coll_folds <- map_df(unique(dhs_all_df$country_code), function(cc_dhs){
- print(cc_dhs)
- cc_gadm <- dhs_gadm_cw$code_gadm[dhs_gadm_cw$code_gadm %in% cc_dhs]
- df_i <- dhs_all_df_coll[dhs_all_df_coll$country_code %in% cc_dhs,]
- gadm_i <- readRDS(file.path(data_dir, "GADM", "FinalData", "adm2", paste0("gadm36_",cc_gadm,"_2_sp.Rds")))
- gadm_i[,c("GID_0", "GID_1", "GID_2",
-
"NAME_0", "NAME_1", "NAME_2")]
-
Random fold
- within_country_fold <- rep_len(1:5, length.out = nrow(gadm_i)) %>% sample()
- gadm_i$within_country_fold <- paste0(cc_dhs, "_", within_country_fold)
- sp_i <- df_i
- coordinates(sp_i) <- ~longitude+latitude
- crs(sp_i) <- CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
- df_out <- over_nearest(sp_i, gadm_i)
- return(df_out)
- })
'''
'''
print(cc_dhs)
[1] "AGO" "BEN" "BFA" "CAF" "CIV" "CMR" "COD" "COG" "COM" "EGY" "ETH" "GAB"
[13] "GHA" "GIN" "GMB" "KEN" "LSO" "MAR" "MLI" "MOZ" "MRT" "MWI" "NGA" "RWA"
[25] "SEN" "SLE" "SWZ" "TCD" "TGO" "TZA" "UGA" "ZAF" "ZMB" "ZWE"
gadm_i <- readRDS(file.path(data_dir, "GADM", "FinalData", "adm2", paste0("gadm36_",cc_dhs,"_2_sp.Rds")))
'''
This command is getting problem and the output of this command is that
Warning message:
In gzfile(file, "rb") :
cannot open compressed file 'E:/Big Data Poverty Estimation/Data/GADM/FinalData/adm2/gadm36_AO_2_sp.Rds', probable reason 'No such file or directory'
we need to have three digits code please like AGO , BEN etc , if we print print(cc_dhs)
we get the three digit codes but in the program code we get gadm36_AO_2_sp.Rds, two digit code please
how to solve this please
Thanks