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)
}
Run the code above in your browser using DataLab