if (FALSE) {
# ----------------------------------------------------------------------#
# Here we consider the example of computing urban/rural fraction for
# Zambia 2018 DHS for the sub-population of children under 1 years old.
# This survey is based on sampling frame from the 2010 Zambia Census.
# ----------------------------------------------------------------------#
#
# From Table A1 of Zambia 2013-2014 DHS final report, we can obtain the fraction of
# urban population by Admin 1 areas in the 2010 survey.
# Notice that in the appendix of the 2018 DHS final report,
# only distribution of household is reported and not population size by urbanicity.
# When the table is not provided in the DHS report, you need to find it from
# the census website directly.
# Please note that the admin1 column needs to match the admin 1 names in the
# Admin 1 spatial polygon file exactly.
# For example, here we change "Northwestern" to "North-Western"
urban.frac <- data.frame(
admin1 = c('Central', 'Copperbelt', 'Eastern',
'Luapula', 'Lusaka', 'Muchinga',
'North-Western', 'Northern', 'Southern','Western'),
frac = c(0.2513, 0.809, 0.1252,
0.1963, 0.8456, 0.1714,
0.2172, 0.1826, 0.2448, 0.1474))
# The corresponding census year population tiff can be found at:
# https://data.worldpop.org/GIS/Population/Global_2000_2020_1km_UNadj/
# The code below downloads the file from the internet directly
# You can also download the file directly and read into R
link1="https://data.worldpop.org/GIS/Population/Global_2000_2020_1km_UNadj/"
file1="2010/ZMB/zmb_ppp_2010_1km_Aggregated_UNadj.tif"
tempfile1 = tempfile()
download.file(paste0(link1, file1), destfile = tempfile1,
method = "libcurl", mode="wb")
library(raster)
tiff1 <- raster(tempfile1)
# https://hub.worldpop.org/geodata/summary?id=16429
# Here we compute population fractions for 0-1 year old population.
# The from the same link below
link2="https://data.worldpop.org/GIS/AgeSex_structures/Global_2000_2020/"
# The two files are for female and male population respectively,
file2f="2018/ZMB/zmb_f_0_2018.tif"
file2m="2018/ZMB/zmb_f_0_2018.tif"
# Since the two files are very large, we recommend downloading them
# mannually and then load them into R.
tiff2f <- raster("zmb_f_0_2018.tif")
tiff2m <- raster("zmb_m_0_2018.tif")
tiff2 <- tiff2f + tiff2m
frac <- getUR(tiff.census = tiff1, tiff.survey = tiff2,
prop.census = urban.frac, fact = 10,
poly.adm1 = ZambiaAdm1, poly.adm2 = ZambiaAdm2,
varname1 = "NAME_1", varname2 = "NAME_2")
library(SUMMER)
mapPlot(frac$admin1.ur, geo = ZambiaAdm1,
by.data = "admin1.name", by.geo = "NAME_1", variable = "urban")
mapPlot(frac$admin2.ur, geo = ZambiaAdm2,
by.data = "admin2.name", by.geo = "NAME_2", variable = "urban")
# Compare with the proportion of Women 14-49 years old in the built-in data
# These two plots should be similar but not identical
# since the population is different
mapPlot(ZambiaPopWomen$admin2_urban, geo = ZambiaAdm2,
by.data = "admin2.name", by.geo = "NAME_2", variable = "urban")
}
Run the code above in your browser using DataLab