pop.aggregate(pop.pred, regions, input.type = c('country', 'region'), name = input.type, inputs = list(e0F.sim.dir = NULL, e0M.sim.dir = "joint_", tfr.sim.dir = NULL), my.location.file = NULL, verbose = FALSE, ...)
get.pop.aggregation(sim.dir = NULL, pop.pred = NULL, name = NULL, write.to.cache = TRUE)bayesPop.prediction containing country-specific population projections.UNlocations dataset or in my.location.file (see below).run.e0.mcmc.extra, e0.predict.extra). If it is not given, the same e0 directory is taken which was used for generating the pop.pred object, in which case the e0 projections are re-loaded from disk.
NULL or joint_) the function assumes a joint female-male projections of life expectancy and thus tries to load the male projections from the female projection object created using the e0F.sim.dir argument.
run.tfr.mcmc.extra, tfr.predict.extra). If it is not given, the same TFR directory is taken which was used for generating the pop.pred object, in which case the TFR projections are re-loaded from disk.UNlocations dataset, see below.pop.pred object. Alternatively, pop.pred can be used. Either sim.dir or pop.pred must be given.get.pop.prediction).bayesPop.prediction containing the aggregated results. In addition it contains elements aggregation.method giving the input.type used, and aggregated.countries which is a list of countries aggregated for each region.
UNlocations or my.location.file is used to determine countries to be aggregated, in particular the field location_type of the entries with country_code given in the regions argument. One can aggregate over the following location types: Type 0 means aggregating all countries of the world (or in the file), type 2 is aggregating over continents, type 3 is aggregating over regions within continents, and any other integer (except 4) correponds to user-defined aggregations. Note that type 4 is reserved as a location type of countries and thus, all aggregations are performed over entries of this type. For type 2, countries are matched using the area_code column; for type 3 the matching is done using the reg_code column of the UNlocations dataset. E.g., if regions=908 (Europe) which has location type 2 in the default UNlocations dataset, all countries are aggregated for which values of 908 are found in the area_code column. If the location type is other than 0, 2, 3 and 4, there must be a column in the file called agcode_$x$ with $x$ being the location type. This column is then used to match the countries to be aggregated. Consider the following example. Say we want to pair four countries (Germany [DE], France [FR], Netherlands [NL], Italy [IT]) in two different ways, so we have two overlapping grouppings, each of which has two groups (A,B):
Then, my.location.file should have the following entries:
| country_code | name | location_type | agcode_98 |
| agcode_99 | 1001 | groupping1_groupA | 98 |
| -1 | -1 | 1002 | groupping1_groupB |
| 98 | -1 | -1 | 1003 |
| groupping2_groupA | 99 | -1 | -1 |
| 1004 | groupping2_groupB | 99 | -1 |
| -1 | 276 | Germany | 4 |
| 1001 | 1003 | 250 | France |
| 4 | 1001 | 1004 | 258 |
| Netherlands | 4 | 1002 | 1003 |
| 380 | Italy | 4 | 1002 |
| 1004 | country_code | name | location_type |
regions=1001:1004. Having location_type being 98 and 99, it is expected the file to have columns agcode_98 and agcode_99 containing assignements to each of the two grouppings. Values in this columns corresponding to groups are not used and thus can have any value. For aggregating over all four countries, set regions=1005 which has location_type equal 0 and thus, it is aggregated over all entries with location_type equals 4.There are two methods available for generating aggregations of population projection:
pop.predict), but it operates on aggregated input components. These are created as follows. Here $c$ denotes countries over which we aggregate a region $R$, $s in {m,f}$, $a$, and $t$ denote sex, age category and time, respectively. $t=P$ denotes the present year of the prediction. $N_{s,a,t}^c$ and $M_{s,a,t}^c$, respectively, denotes the historical population count and the Bayesian predictive median of population, respectively, of sex $s$, in age category $a$ at time $t$ for country $c$ (refer to the links in parentheses for description of the data):
run.e0.mcmc.extra and e0.predict.extra functions of the bayesLife package.
run.tfr.mcmc.extra and tfr.predict.extra functions of the bayesTFR package.
Results of the aggregations are stored in the same top directory as the pop.pred object, in a sudirectory called aggregations_name. They can be accessed using the function get.pop.aggregation. Note that multiple runs of this function with the same name will overwrite previous aggregations results of the same name.
pop.predict, tfr.predict.extra, e0.predict.extra
## Not run:
# sim.dir <- tempfile()
# pred <- pop.predict(countries=c(528,218,450), output.dir=sim.dir)
# aggr <- pop.aggregate(pred, 900) # aggregating World (i.e. all countries available in pred)
# pop.trajectories.plot(aggr, 900, sum.over.ages=TRUE)
# # countries over which we aggregated:
# UNlocations[UNlocations[,'country_code']
# unlink(sim.dir, recursive=TRUE)## End(Not run)
Run the code above in your browser using DataLab