# Subnational example data
my.sube0.file <- file.path(find.package("bayesLife"), 'extdata', 'subnational_e0_template.txt')
sube0 <- read.delim(my.sube0.file, check.names = FALSE)
countries <- unique(sube0[, c("country_code", "country_name")])
# Directory with national projections (contains 30 trajectories for each country)
nat.dir <- file.path(find.package("bayesLife"), "ex-data", "bayesLife.output")
# Subnational projections for all three countries,
# including male projections where female
# data is used only for demonstration purposes
# (my.e0M.file should contain male e0).
subnat.dir <- tempfile()
e0.predict.subnat(countries$country_code, my.e0.file = my.sube0.file,
sim.dir = nat.dir, output.dir = subnat.dir, start.year = 2013,
predict.jmale = TRUE, my.e0M.file = my.sube0.file)
# Retrieve results for all countries
preds <- get.rege0.prediction(subnat.dir)
names(preds)
# View tables of subregions for each country
for(i in 1:nrow(countries)) {
cat("\n\n", countries$country_name[i], "\n")
print(get.countries.table(preds[[as.character(countries$country_code[i])]]))
}
# Quantiles for individual subregions for female
e0.trajectories.table(preds[["36"]], "Victoria")
# Retrieve results for one country (Canada)
pred <- get.rege0.prediction(subnat.dir, 124)
e0.trajectories.plot(pred, "Quebec", both.sexes = TRUE)
# Retrieve only male results
predM <- get.rege0.prediction(subnat.dir, 124, joint.male = TRUE)
e0.trajectories.table(predM, "Quebec")
# cleanup
unlink(subnat.dir)
# See more examples in ?e0.predict.subnat
Run the code above in your browser using DataLab