#The example takes more than 5 seconds because it includes
#several fitting and forecasting process and hence all
#the process is included in donttest
# \donttest{
#First, we present the data that we are going to use
SpainRegions
ages <- c(0, 1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90)
#Charge some libraries needed for executing the function
library(gnm)
library(forecast)
#There are some model that we can fit using this function:
#1. ADDITIVE MULTI-POPULATION MORTALITY MODEL
#In the case, the user wants to fit the additive multi-population mortality model
additive_Spainmales <- fitLCmulti(model = "additive",
qxt = SpainRegions$qx_male,
periods = c(1991:2020),
ages = c(ages),
nPop = 18,
lxt = SpainRegions$lx_male)
additive_Spainmales
#If the user does not provide the model inside the function fitLCmult()
#the multi-population mortality model applied will be additive one.
#Once, we have fit the data, it is possible to see the ax, bx, kt, and Ii
#provided parameters for the fitting.
plot(additive_Spainmales)
#2. MULTIPLICATIVE MULTI-POPULATION MORTALITY MODEL
#In the case, the user wants to fit the multiplicative multi-population mortality model
multiplicative_Spainmales <- fitLCmulti(model = "multiplicative",
qxt = SpainRegions$qx_male,
periods = c(1991:2020),
ages = c(ages),
nPop = 18,
lxt = SpainRegions$lx_male)
multiplicative_Spainmales
#Once, we have fit the data, it is possible to see the ax, bx, kt, and It
#provided parameters for the fitting.
plot(multiplicative_Spainmales)
#3. COMMON-FACTOR MULTI-POPULATION MORTALITY MODEL
#In the case, the user wants to fit the common-factor multi-population mortality model
cfm_Spainmales <- fitLCmulti(model = "CFM",
qxt = SpainRegions$qx_male,
periods = c(1991:2020),
ages = c(ages),
nPop = 18,
lxt = SpainRegions$lx_male)
cfm_Spainmales
#Once, we have fit the data, it is possible to see the ax, bx, kt, and It
#provided parameters for the fitting.
plot(cfm_Spainmales)
#4. JOINT-K MULTI-POPULATION MORTALITY MODEL
#In the case, the user wants to fit the augmented-common-factor multi-population mortality model
jointk_Spainmales <- fitLCmulti(model = "joint-K",
qxt = SpainRegions$qx_male,
periods = c(1991:2020),
ages = c(ages),
nPop = 18,
lxt = SpainRegions$lx_male)
jointk_Spainmales
#Once, we have fit the data, it is possible to see the ax, bx, kt, and It
#provided parameters for the fitting.
plot(jointk_Spainmales)
#5. AUGMENTED-COMMON-FACTOR MULTI-POPULATION MORTALITY MODEL
#In the case, the user wants to fit the augmented-common-factor multi-population mortality model
acfm_Spainmales <- fitLCmulti(model = "ACFM",
qxt = SpainRegions$qx_male,
periods = c(1991:2020),
ages = c(ages),
nPop = 18,
lxt = SpainRegions$lx_male)
acfm_Spainmales
#Once, we have fit the data, it is possible to see the ax, bx, kt, and It
#provided parameters for the fitting.
plot(acfm_Spainmales)
#6. LEE-CARTER FOR SINGLE-POPULATION
#As we mentioned in the details of the function, if we only provide the data
#from one-population the function fitLCmulti()
#will fit the Lee-Carter model for single populations.
LC_Spainmales <- fitLCmulti(qxt = SpainNat$qx_male,
periods = c(1991:2020),
ages = ages,
model = "additive",
nPop = 1)
LC_Spainmales
#Once, we have fit the data, it is possible to see the ax, bx, and kt
#parameters provided for the single version of the LC.
plot(LC_Spainmales)
# }
Run the code above in your browser using DataLab