get.regtfr.prediction function

Accessing Subnational Prediction Objects

Accessing Subnational Prediction Objects

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

get.regtfr.prediction(sim.dir, country = NULL)

Arguments

  • sim.dir: Simulation directory of the subnational predictions. It corresponds to the argument output.dir in tfr.predict.subnat.
  • country: Numerical country code. If it is not given, all available subnational predictions are retrieved.

Details

Predictions for country xx are assumed to be stored in ‘sim.dir’/subnat/cx .

Returns

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

See Also

tfr.predict.subnat

Examples

# Subnational example data my.subtfr.file <- file.path(find.package("bayesTFR"), 'extdata', 'subnational_tfr_template.txt') subtfr <- read.delim(my.subtfr.file, check.names=FALSE, stringsAsFactor=FALSE) countries <- unique(subtfr[, c("country_code", "country")]) # Directory with national projections (contains 30 trajectories for each country) nat.dir <- file.path(find.package("bayesTFR"), "ex-data", "bayesTFR.output") # Subnational projections for all three countries () subnat.dir <- tempfile() tfr.predict.subnat(countries$country_code, my.tfr.file=my.subtfr.file, sim.dir=nat.dir, output.dir=subnat.dir, start.year=2013) # Retrieve results for all countries preds <- get.regtfr.prediction(subnat.dir) names(preds) # View tables of subregions for each country for(i in 1:nrow(countries)) { cat("\n\n", countries$country[i], "\n") print(get.countries.table(preds[[as.character(countries$country_code[i])]])) } # Quantiles for individual subregions tfr.trajectories.table(preds[["218"]], "Bolivar") # Retrieve results for one country pred <- get.regtfr.prediction(subnat.dir, 218) tfr.trajectories.plot(pred, "Loja") # cleanup unlink(subnat.dir) # See more examples in ?tfr.predict.subnat