Wrapper function to fit and forecast mortality models

fit_mo_mo(
  mortality_model = "lc",
  death,
  exposure,
  ages = 50:90,
  validation = 0,
  forecast = 1,
  family = "nb",
  chains = 1,
  cores = 4,
  log_marg = FALSE,
  iter = 2000
)

Arguments

mortality_model

name of the mortality model

death

death matrix

exposure

exposure matrix

ages

vector of ages

validation

size of the validation set

forecast

number of calendar years to be forecast

family

underlying count distribution

chains

number of Markov chains

cores

number of cores used

log_marg

Do we compute the marginal likelihood or not?

iter

Length of the Markov chain trajectory

Value

a stanfit object

Examples



years <- 1990:2017
ages <- 50:90
cohorts <- sort(unique(as.vector(sapply(years, function(year) year - ages))))
death <- FRMaleData$Dxt[formatC(ages),formatC(years)]
exposure <- FRMaleData$Ext[formatC(ages),formatC(years)]
stan_fit <- fit_mo_mo("m6", death , exposure, ages, 0, 5, "nb", 1, 4,
log_marg = FALSE,iter=50)
#> 
#> SAMPLING FOR MODEL 'M6model' NOW (CHAIN 1).
#> Chain 1: 
#> Chain 1: Gradient evaluation took 0 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
#> Chain 1: Adjust your expectations accordingly!
#> Chain 1: 
#> Chain 1: 
#> Chain 1: WARNING: There aren't enough warmup iterations to fit the
#> Chain 1:          three stages of adaptation as currently configured.
#> Chain 1:          Reducing each adaptation stage to 15%/75%/10% of
#> Chain 1:          the given number of warmup iterations:
#> Chain 1:            init_buffer = 3
#> Chain 1:            adapt_window = 20
#> Chain 1:            term_buffer = 2
#> Chain 1: 
#> Chain 1: Iteration:  1 / 50 [  2%]  (Warmup)
#> Chain 1: Iteration:  5 / 50 [ 10%]  (Warmup)
#> Chain 1: Iteration: 10 / 50 [ 20%]  (Warmup)
#> Chain 1: Iteration: 15 / 50 [ 30%]  (Warmup)
#> Chain 1: Iteration: 20 / 50 [ 40%]  (Warmup)
#> Chain 1: Iteration: 25 / 50 [ 50%]  (Warmup)
#> Chain 1: Iteration: 26 / 50 [ 52%]  (Sampling)
#> Chain 1: Iteration: 30 / 50 [ 60%]  (Sampling)
#> Chain 1: Iteration: 35 / 50 [ 70%]  (Sampling)
#> Chain 1: Iteration: 40 / 50 [ 80%]  (Sampling)
#> Chain 1: Iteration: 45 / 50 [ 90%]  (Sampling)
#> Chain 1: Iteration: 50 / 50 [100%]  (Sampling)
#> Chain 1: 
#> Chain 1:  Elapsed Time: 0.812 seconds (Warm-up)
#> Chain 1:                0.048 seconds (Sampling)
#> Chain 1:                0.86 seconds (Total)
#> Chain 1: 
boxplot_post_dist(stan_fit, "k", ages, years)

boxplot_post_dist(stan_fit, "g", ages, years)