popReconstruct_fit: Implement the Bayesian hierarchical PopReconstruct model

Description Usage Arguments Optional popReconstruct Settings Data popReconstruct_fit Value popReconstruct_posterior_draws and popReconstruct_prior_draws Value popReconstruct_count_space_parameters Value popReconstruct_summarize_draws Value Settings Inputs References See Also Examples

View source: R/popReconstruct_fit.R

Description

The popReconstruct model embeds the cohort component method of population projection (ccmpp) in a Bayesian hierarchical model. It reconciles ccmpp input preliminary estimates of sex-ratio at birth, fertility, mortality, migration, and a baseline population with population data while accounting for measurement error in these initial estimates.

popReconstruct_fit() fits the model using Stan or TMB.

popReconstruct_posterior_draws() produces draws from the posterior distribution.

popReconstruct_prior_draws() produces draws from the prior distribution.

popReconstruct_count_space_parameters() uses draws from the popReconstruct model to derive count space parameters. For most of the parameters this is calculated as count = rate * population. Maternal age-specific live births are also split into child sex-specific live births using the sex ratio at birth. male_proportion = srb / (srb + 1) & female_proportion = 1 / (srb + 1).

popReconstruct_summarize_draws() produces summary statistics of draws from the popReconstruct model using demUtils::summarize_dt(). The summarize_cols parameter should include 'chain', 'chain_draw' and 'draw' when the model was fit with stan and just 'draw' when the model was fit with tmb.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
popReconstruct_fit(
  inputs,
  data,
  hyperparameters,
  settings,
  value_col,
  software,
  ...
)

popReconstruct_posterior_draws(
  fit,
  inputs,
  settings,
  value_col,
  software,
  method_name
)

popReconstruct_count_space_parameters(
  draws,
  settings,
  parameters = c("live_births", "deaths", "net_migrants"),
  value_col = "value",
  quiet = FALSE
)

popReconstruct_prior_draws(
  inputs,
  hyperparameters,
  settings,
  value_col,
  method_name,
  chunk_size = 100
)

popReconstruct_summarize_draws(
  draws,
  summarize_cols = c("chain", "chain_draw", "draw"),
  value_col = "value",
  ...
)

Arguments

inputs

[list()]
[data.table()] for each ccmpp input. Requires 'srb', 'asfr', 'baseline'; mortality estimates provided as just 'survival' or two of 'mx', 'ax', and 'qx'; and migration estimates provided as just 'net_migration' or both 'immigration' and 'emigration'. See Section: Inputs for more information on each of the required inputs.

data

[list()]
[data.table()] for each type of data input for the model (currently only 'population'). See Section: Data for more information.

hyperparameters

[list()]
List for each model component ('srb', 'asfr', ...) that itself contains a list specifying the alpha (shape) and beta (scale) hyperparameters for the variance of each model component.

settings

[list()]
Named list of settings for running the popReconstruct model with. The required settings are the same as those required for demCore::ccmpp(), see Section: Settings for these. The optional settings specific to popReconstruct are described in Section: Optional popReconstruct Settings

value_col

[character(1)]
Name of the column containing the value of interest in each of the inputs. Default is 'value'.

software

[character()]
Statistical modeling software to fit popReconstruct with. Either 'stan' or 'tmb' are available.

...

For popReconstruct_fit() additional arguments to pass to rstan::sampling() if fitting the model with 'stan' or optimx::optimx() if fitting the model with 'tmb'. For popReconstruct_summarize_draws() additional arguments to pass to demUtils::summarize_dt().

fit

[stanfit(1)] or [sdreport(1)]
Model fit object returned by popReconstruct_fit().

method_name

[character(1)]
Description to assign to column 'method' in each returned data.table.

draws

[list()] of [data.table()]
Draws from the posterior distribution of the popReconstruct model as returned by popReconstruct_posterior_draws().

parameters

[character()]
Count space parameters to derive. Can be a combination of 'live_births', 'deaths', 'net_migrants', 'immigrants', 'emigrants'. Default is 'live_births', 'deaths', & 'net_migrants'.

quiet

[logical(1)]
Should progress messages be suppressed as the function is run? Default is False.

chunk_size

[integer(1)]
number of draws to sample from the prior at once.

summarize_cols

[character()]
The id_cols that should be collapsed and to calculate summary statistics over.

Optional popReconstruct Settings

Data

population: [data.table()]

popReconstruct_fit Value

If fit using 'stan' an object of class stanfit and if fit using 'tmb' an object of class sdreport. Either represents the fitted results that can be extracted using popReconstruct_posterior_draws(). Stan has helper packages that can be used to explore the model fit through shinystan, bayesplot, etc.

popReconstruct_posterior_draws and popReconstruct_prior_draws Value

popReconstruct_posterior_draws() and popReconstruct_prior_draws() return a named [list()] of [data.table()] for draws from the posterior and prior distribution respectively for each ccmpp input component along with the associated offset and spline offset parameters. Draws for the 'variance' and projected 'population' are also included.

The returned [data.table()]s will include columns related to the draw number:

population: [data.table()]

variance: [data.table()]

For each ccmpp component ('srb', 'asfr', etc.) there will be three [data.table()] outputs included in the returned [list()]. These will each have the same columns as described in the Section: Inputs but with additional draw related columns as described above.

  1. The offset parameters representing the values of the piecewise linear function at the year- and age-specific knots. These are the estimated deviations from the initial ccmpp input estimates at the exact knots. The estimated values are in the transformed modeling space (log transformed for 'srb', logit transformed for 'survival', etc.).

  2. The spline offset values calculated by multiplying the fixed B-spline linear basis functions by the offset parameters. These are the estimated deviations from the initial ccmpp input estimates at all years and ages. The estimated values are in the transformed modeling space.

  3. The actual ccmpp input posterior draws after combining the spline offset values with the initial ccmpp input estimates and after applying the inverse of the transformation used to model each component.

popReconstruct_count_space_parameters Value

Returns the same named [list()] of [data.table()] returned by popReconstruct_posterior_draws() or popReconstruct_prior_draws() with additional list elements for each of the specified count space parameters requested.

popReconstruct_summarize_draws Value

Returns a named [list()] of [data.table()] for summary statistics of the input draws. Each data.table() will have the id_cols for each component (minus the summarize_cols) plus summary statistic columns. The summary statistic columns have the same name as each function specified in summary_fun and the quantiles are named like 'q_(probs * 100)'. See [demUtils::summarize_dt()] for more information.

Settings

Inputs

srb: [data.table()]

asfr: [data.table()]

baseline: [data.table()]

survival: [data.table()]

mx: [data.table()]

ax: [data.table()]

qx: [data.table()]

net_migration: [data.table()]

immigration: [data.table()]

emigration: [data.table()]

References

Wheldon, Mark C., Adrian E. Raftery, Samuel J. Clark, and Patrick Gerland. 2013. “Reconstructing Past Populations With Uncertainty From Fragmentary Data.” Journal of the American Statistical Association 108 (501): 96–110. https://doi.org/10.1080/01621459.2012.737729.

popReconstruct R Package

Wheldon, Mark C., Adrian E. Raftery, Samuel J. Clark, and Patrick Gerland. 2015. “Bayesian Reconstruction of Two-Sex Populations by Age: Estimating Sex Ratios at Birth and Sex Ratios of Mortality.” Journal of the Royal Statistical Society. Series A: Statistics in Society 178 (4): 977–1007. https://doi.org/10.1111/rssa.12104.

markalava/Bayesian-Reconstruction github repo

See Also

demCore::ccmpp()

demUtils::summarize_dt()

rbindlist_dts()

vignette("popReconstruct")

vignette("popReconstruct_options")

Other popReconstruct: popReconstruct_hyperparameters(), rbindlist_dts()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# specify settings for this example
settings = list(
  years = seq(1960, 2000, 5),
  sexes = c("female"),
  ages = seq(0, 80, 5),
  ages_mortality = seq(0, 85, 5),
  ages_asfr = seq(15, 45, 5),

  n_draws = 10
)

# hyperparameters for the variance prior distribution, represents measurement error
hyperparameters <- list(asfr = list(alpha = 1, beta = 0.0109),
                        population = list(alpha = 1, beta = 0.0109),
                        survival = list(alpha = 1, beta = 0.0109),
                        net_migration = list(alpha = 1, beta = 0.0436))

fit_stan <- popMethods::popReconstruct_fit(
  inputs = demCore::burkina_faso_initial_estimates,
  data = demCore::burkina_faso_data,
  hyperparameters = hyperparameters,
  settings = settings,
  value_col = "value",
  software = "stan",
  chains = 1,
  iter = 200,
  warmup = 100,
  thin = 2
)

draws_stan <- popMethods::popReconstruct_posterior_draws(
  fit = fit_stan,
  inputs = demCore::burkina_faso_initial_estimates,
  settings = settings,
  value_col = "value",
  software = "stan",
  method_name = "original"
)

draws_stan <- popMethods::popReconstruct_count_space_parameters(
  draws = draws_stan,
  settings = settings,
  parameters = c("live_births", "net_migrants"),
  value_col = "value",
)

summary_stan <- popMethods::popReconstruct_summarize_draws(
  draws = draws_stan
)

ihmeuw-demographics/popMethods documentation built on Jan. 29, 2021, 12:39 p.m.