library(demography)
USA <- hmd.mx("USA", "alkaid139@163.com", "19970618", "USA")#读取1*1的生命表,来自死亡率数据库,时间是 1933:2017,0:110岁的女性,男性,总的死亡率
USA1<-lca(USA,years=USA$year[18:80],ages =USA$age[1:100],adjust = "dt",restype = "logrates",scale = TRUE) #应用LC模型在 1950:2012,0:99岁
USA.fcast<-forecast(USA1,h=50,se="innovdrift",jumpchoice = "fit",level = 80) #预测,后面50期,2013:2062
a1<-USA.fcast$ax
b1<-USA.fcast$bx
k1<-USA.fcast$kt
plot(USA.fcast) #预测2013-2062年的死亡率(logrates)
plot(USA.fcast,'c')#画出 a,b,k
plot(residuals(USA1))
plot(USA.fcast$e0)#预测的在0岁时的预期寿命
summary(USA1)
Lee-Carter analysis
Call: lca(data = USA, years = USA$year[18:80], ages = USA$age[1:100],
Call: adjust = "dt", restype = "logrates")
Adjustment method: dt
Region: USA
Years in fit: 1950 - 2012
Ages in fit: 0 - 99
Percentage variation explained: 95.5%
ERROR MEASURES BASED ON MORTALITY RATES
Averages across ages:
ME MSE MPE MAPE
-0.00004 0.00002 0.00259 0.04819
Averages across years:
IE ISE IPE IAPE
-0.00370 0.00146 0.25565 4.70310
USA2<-lifetable(USA,years=1950:2012,age=0:99,type="period")#生命表
#period(male)
USA1.m<-lca(USA,series=names(USA$rate)[2],years=USA$year[18:80],ages =USA$age[1:100],adjust = "dt",restype = "logrates",scale = TRUE)
summary(USA1.m)
USAm.fcast<-forecast(USA1.m,h=50,se="innovdrift",jumpchoice = "fit",level = 95)
a1<-USAm.fcast$ax
b1<-USAm.fcast$bx
k1<-USAm.fcast$kt
plot(USAm.fcast) #预测2013-2062年的死亡率(logrates),
plot(USAm.fcast,'c')#画出 a,b,k
plot(residuals(USA1.m))
plot(fitted(USA1.m))
plot(fitted(USAm.fcast))
plot(USAm.fcast$e0)#预测的在0岁时的预期寿命