The function generates a fan plot representing the forecast death rates based on the ggplot2 and ggfan R packages.

forecasting_plot(stan_fit, ages, years, death, exposure, ages.plot)

Arguments

stan_fit

stanfit object

ages

range of ages

years

range of years

death

matrix of observed deaths

exposure

matrix of observed exposures

ages.plot

ages to be plotted

Value

A ggplot object that can be further customized using the ggplot2 package.

Examples


# \donttest{
years <- 1980:2017
ages <- 50:90
death <- FRMaleData$Dxt[formatC(ages),formatC(years)]
exposure <- FRMaleData$Ext[formatC(ages),formatC(years)]
iterations<-1000 # Toy example, consider at least 2000 iterations
fitLC<-lc_stan(death = death,exposure=exposure, forecast = 10,
family = "poisson",chains=1,cores=1,iter=iterations)
#> 
#> SAMPLING FOR MODEL 'leecarter' 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: Iteration:   1 / 1000 [  0%]  (Warmup)
#> Chain 1: Iteration: 100 / 1000 [ 10%]  (Warmup)
#> Chain 1: Iteration: 200 / 1000 [ 20%]  (Warmup)
#> Chain 1: Iteration: 300 / 1000 [ 30%]  (Warmup)
#> Chain 1: Iteration: 400 / 1000 [ 40%]  (Warmup)
#> Chain 1: Iteration: 500 / 1000 [ 50%]  (Warmup)
#> Chain 1: Iteration: 501 / 1000 [ 50%]  (Sampling)
#> Chain 1: Iteration: 600 / 1000 [ 60%]  (Sampling)
#> Chain 1: Iteration: 700 / 1000 [ 70%]  (Sampling)
#> Chain 1: Iteration: 800 / 1000 [ 80%]  (Sampling)
#> Chain 1: Iteration: 900 / 1000 [ 90%]  (Sampling)
#> Chain 1: Iteration: 1000 / 1000 [100%]  (Sampling)
#> Chain 1: 
#> Chain 1:  Elapsed Time: 18.603 seconds (Warm-up)
#> Chain 1:                4.938 seconds (Sampling)
#> Chain 1:                23.541 seconds (Total)
#> Chain 1: 
forecasting_plot(fitLC,ages,years,death,exposure,c(65,75,85))

# }