if (FALSE) {
years <- levels(DemoData[[1]]$time)
data <- getDirectList(births = DemoData,
years = years,
regionVar = "region", timeVar = "time",
clusterVar = "~clustid+id",
ageVar = "age", weightsVar = "weights",
geo.recode = NULL)
# obtain direct estimates
data_multi <- getDirectList(births = DemoData, years = years,
regionVar = "region", timeVar = "time", clusterVar = "~clustid+id",
ageVar = "age", weightsVar = "weights", geo.recode = NULL)
data <- aggregateSurvey(data_multi)
# national model
years.all <- c(years, "15-19")
fit1 <- smoothDirect(data = data, geo = NULL, Amat = NULL,
year.label = years.all, year.range = c(1985, 2019),
rw = 2, m = 5)
## Plot marginal posterior densities over time
ridgePlot(fit1, year.plot = years.all,
ncol = 4, by.year = FALSE)
# subnational model
fit2 <- smoothDirect(data = data, geo = DemoMap$geo, Amat = DemoMap$Amat,
year.label = years.all, year.range = c(1985, 2019),
rw = 2, m = 5, type.st = 1)
# Plot marginal posterior densities over time (regions are ordered alphabetically)
ridgePlot(fit2, year.plot = years.all, ncol = 4)
# Re-order the regions and save the density to avoid re-compute later
density <- ridgePlot(fit2, year.plot = years.all,
ncol = 4, per1000 = TRUE, order = -1, save.density = TRUE)
density$g
# Show each region (instead of each year) in a panel
## Instead of recalculate the posteriors, we can use previously calculated densities as input
ridgePlot(results = density, year.plot = years.all,
ncol = 4, by.year=FALSE, per1000 = TRUE)
# Show more years
ridgePlot(results = density, year.plot = c(1990:2019),
ncol = 4, by.year=FALSE, per1000 = TRUE)
# Example using surveyPrev package output
library(surveyPrev)
dhsData <- getDHSdata(country = "Rwanda", indicator = "nmr", year = 2019)
data <- getDHSindicator(dhsData, indicator = "nmr")
geo <- getDHSgeo(country = "Rwanda", year = 2019)
poly.adm1 <- geodata::gadm(country="RWA", level=1, path=tempdir())
poly.adm1 <- sf::st_as_sf(poly.adm1)
poly.adm2 <- geodata::gadm(country="RWA", level=2, path=tempdir())
poly.adm2 <- sf::st_as_sf(poly.adm2)
cluster.info <- clusterInfo(geo = geo,
poly.adm1 = poly.adm1,
poly.adm2 = poly.adm2,
by.adm1 = "NAME_1",
by.adm2 = "NAME_2")
fit1 <- directEST(data = data, cluster.info = cluster.info, admin = 1)
fit2 <- directEST(data = data, cluster.info = cluster.info, admin = 2)
ridgePlot(fit1, direction = -1)
ridgePlot(fit2, direction = -1)
}
Run the code above in your browser using DataLab