Uganda contains model survey data provided by DHS. Note that this data is fake, and does not represent any real country’s data. Data similar to the Uganda data used in this vignette can be obtained by using getBirths. UgandaMap contains geographic data from the 1995 Uganda Admin 1 regions defined by DHS. Data similar to the UgandaMap data used in this vignette can be obtained by using read_shape.
First, we load the package and load the necessary data. INLA is not in a standard repository, so we check if it is available and install it if it is not.
library(SUMMER)
if (!isTRUE(requireNamespace("INLA", quietly = TRUE))) {
install.packages('INLA', repos = 'https://www.math.ntnu.no/inla/R/stable')
}
data(Uganda)
data(UgandaMap)Next, we obtain Horvitz-Thompson estimators using countrySummary_mult.
years <- levels(Uganda[[1]]$time)
data <- countrySummary_mult(births = Uganda, years = years, idVar = "id", regionVar = "region",
timeVar = "time", clusterVar = "~clustid+id", ageVar = "age",
weightsVar = "weights", geo.recode = NULL)In this step, we separate the output from read_shape to use as function arguments.
geo <- UgandaMap$geo
mat <- UgandaMap$AmatUsing our adjacency matrix, we simulate hyperpriors using simhyper.
priors <- simhyper(R = 2, nsamp = 1e+05, nsamp.check = 5000, Amat = mat)Uganda includes an “All” region for reference. We are not interested in this region for our Admin 1 estimates, so we remove it. We can then fit our smoothing model using fitINLA.
data <- data[data$region %in% c("central","eastern","northern","western"),]
inla_model <- fitINLA(data = data, geo = geo, Amat = mat, year_names = years, priors = priors)With our model fit, we can now get our smoothed output and project into a future period with projINLA.
surveylabel <- paste0("DHS ", unique(data$surveyYears))
results_rw2 <- projINLA(data = data, inla_mod = inla_model, years = years, geo = geo,
newyear = "15-19", quantiles = c(0.025,0.5,0.975))We now have everything necessary to make plots. We first map our estimates at the Admin1 level using mapPlot.
mapPlot(countryname = "Uganda", results = results_rw2, geo = geo,
countrysum = data, inlamod = inla_model)We now map our the median estimates over time by region with a spaghetti plot using spagPlot.
spagPlot(countryname = "Uganda", results = results_rw2, geo = geo,
countrysum = data, inlamod = inla_model)