get.rege0.prediction {bayesLife}R Documentation

Accessing Subnational Prediction Objects

Description

Retrieve subnational (regional) prediction results produced by e0.predict.subnat, either for one country or for all available countries.

Usage

get.rege0.prediction(sim.dir, country = NULL, method = "ar1", joint.male = FALSE)

Arguments

sim.dir

Simulation directory of the subnational predictions. It corresponds to the argument output.dir in e0.predict.subnat.

country

Numerical country code. If it is not given, all available subnational predictions are retrieved.

method

Method used for generating the projections. It corresponds to the method argument in e0.predict.subnat.

joint.male

Logical. If TRUE, the function is applied to a male prediction that was generated using the joint female-male gap model implemented in the function e0.jmale.predict.subnat.

Details

Predictions for country x are assumed to be stored in “sim.dir/subnat_method/cx”.

Value

If argument country is given, the function returns an object of class bayesLife.prediction. If it is NULL, it returns a list of such objects. Names of the list items are the country codes.

See Also

e0.predict.subnat

Examples

# 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

[Package bayesLife version 5.2-0 Index]