| generate_population | R Documentation |
Simulate future age-specific population given a starting population and
models for fertility, mortality, and migration. If any model is NULL, it is
assumed there are no future births, deaths or net migrants, respectively.
This is an experimental function and has not been thoroughly tested.
The simulation follows demography::pop.sim(), as described in Hyndman and Booth (2008).
generate_population(
starting_population,
mortality_model = NULL,
fertility_model = NULL,
migration_model = NULL,
h = 10,
n_reps = 1000,
female = NULL
)
starting_population |
A |
mortality_model |
A |
fertility_model |
A |
migration_model |
A |
h |
The forecast horizon equal to the number of years to simulate into the future. |
n_reps |
The number of replicates to simulate. |
female |
A character string giving the name used for females in the sex
variable of the |
A vital object containing the simulated future population.
Hyndman and Booth (2008) Stochastic population forecasts using functional data models for mortality, fertility and migration. International Journal of Forecasting, 24(3), 323-342.
# Norwegian data, with ages above 100 combined
nor <- norway_mortality |>
dplyr::filter(Sex != "Total") |>
collapse_ages(max_age = 100)
# Models trained on data up to the year of the starting population
mortality <- nor |>
dplyr::filter(Year > 2010) |>
model(fmean = FMEAN(log(Mortality)))
fertility <- norway_fertility |>
dplyr::filter(Year > 2010) |>
model(fmean = FMEAN(Fertility))
migration <- net_migration(nor, norway_births) |>
dplyr::filter(Year > 2010) |>
model(fmean = FMEAN(NetMigration))
# Simulate 5 future populations for 3 years, starting from the final year of data
generate_population(
starting_population = nor |> dplyr::filter(Year == max(Year)),
mortality_model = mortality,
fertility_model = fertility,
migration_model = migration,
h = 3,
n_reps = 5
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.