#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{
#To show how the function works, we need to provide fitted or forecasted data and the real data.
#In this case, we employ the following data of the library:
SpainRegions
library(gnm)
library(forecast)
ages <- c(0, 1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90)
#In this case, we fit for males providing the lxt
multiplicative_Spainmales <- fitLCmulti(model = "multiplicative",
qxt = SpainRegions$qx_male,
periods = c(1991:2020),
ages = c(ages),
nPop = 18,
lxt = SpainRegions$lx_male)
multiplicative_Spainmales
plot(multiplicative_Spainmales)
#Once, we have the fitted data, we will obtain different measures of accuracy
#for the first population.
#We need to obtain wxt (weight of the mortality rates or data provided) using a
library(StMoMo)
wxt_1pop <- genWeightMat(ages = ages, years = c(1991:2020), clip = 0)
##########################
#SSE#
##########################
SSE_multSpmales <- MeasureAccuracy(measure = "SSE",
qxt_crude = multiplicative_Spainmales$qxt.crude$pop1,
qxt_aju = multiplicative_Spainmales$qxt.fitted$pop1,
wxt = wxt_1pop)
SSE_multSpmales
##########################
#MSE#
##########################
MSE_multSpmales <- MeasureAccuracy(measure = "MSE",
qxt_crude = multiplicative_Spainmales$qxt.crude$pop1,
qxt_aju = multiplicative_Spainmales$qxt.fitted$pop1,
wxt = wxt_1pop)
MSE_multSpmales
##########################
#MAE#
##########################
MAE_multSpmales <- MeasureAccuracy(measure = "MSE",
qxt_crude = multiplicative_Spainmales$qxt.crude$pop1,
qxt_aju = multiplicative_Spainmales$qxt.fitted$pop1,
wxt = wxt_1pop)
MAE_multSpmales
##########################
#MAPE#
##########################
MAPE_multSpmales <- MeasureAccuracy(measure = "MSE",
qxt_crude = multiplicative_Spainmales$qxt.crude$pop1,
qxt_aju = multiplicative_Spainmales$qxt.fitted$pop1,
wxt = wxt_1pop)
MAPE_multSpmales
# }
Run the code above in your browser using DataLab