将数据转换为生命表时的“ Inf”数据

时间:2018-09-09 14:23:25

标签: r demographics

我是新手程序员,所以请耐心一点。我从“人类死亡率数据库”(HMD)下载了一些死亡率数据。

需要的包裹:

Packages <- c("StMoMo", "lifecontingencies", "fda", "demography")
invisible(lapply(Packages, library, character.only = TRUE))
remove(Packages)

下载数据集:

# mortality
Germany_M <- hmd.mx("DEUTNP", "USERNAME", "PASSWORD", "Germany")
# life expectancy at birth
Germany_E <- hmd.e0("DEUTNP", "USERNAME", "PASSWORD")

数据集信息:

> dput(Germany_M$year[1:25])
1990:2014

> dput(Germany_M$age)
c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ..., 108, 109, 110)

接下来我将向您解释的错误发生在1991年的数据之内,所以我仅向您显示1990-1991-1992年的数据(仅针对总人口,不包括男性和女性)

# amount of population in 1990,1991,1992
> dput(Germany_M$pop$total[,1:3])
structure(c(896913.64, 896875.32, 898207.72, 879287.22, 850054.15, 
839359.64, 835409.03, 857772.58, 863924.38, 868836.24, 845586.95, 
812876.68, 812902.07, 798796.39, 782007.23, 783589.61, 801720.01, 
847608.69, 977237.46, 1062028.44, 1133724.83, 1235571.04, 1300948.78, 
1347307.2, 1379973.91, 1403661.77, 1421445.54, 1399885.26, 1365206.32, 
1336701.04, 1300938.62, 1258303.96, 1211491.66, 1190653.48, 1163796.6, 
1142818.59, 1123727.65, 1116924.22, 1114520.8, 1110869.09, 1109656.64, 
1060850.28, 974871.83, 945218.06, 778546.33, 894046.67, 1036240.34, 
1033737.34, 1131248.17, 1279443.67, 1309442.5, 1260110.5, 1183538.33, 
1137830.5, 1114928.5, 1068930.5, 939304.33, 844730.67, 856880.5, 
895016.5, 909947.33, 898300.83, 865206.67, 825870.17, 815721.83, 
782561.83, 745536.33, 755017, 784991.33, 788563.33, 677506.67, 
471913.83, 359179.17, 362213.17, 428866.67, 539703, 589021.67, 
570643.16, 528446.5, 486068.83, 459015.43, 420121.6, 373631.07, 
327781.69, 279963.02, 236851.03, 197042.15, 162373.22, 132051.91, 
101656.46, 76674.86, 57747.07, 42098.56, 30077.66, 20894.71, 
13971.05, 9212.02, 5833.84, 3748.51, 2420, 1247, 631.67, 332.67, 
188.33, 105.83, 53.5, 24.17, 12.17, 8.17, 12, 0.67, 878166.7, 
903652.22, 906643.96, 908339.03, 889577.67, 859791.16, 848243.07, 
844237.3, 866647.03, 873190.11, 877873.56, 854677.7, 821620.09, 
821373.15, 807857.66, 792207.99, 793725.15, 810755.79, 861172.96, 
993605.42, 1079892.35, 1150944.61, 1254152.18, 1318950.79, 1363418.17, 
1395209.56, 1418141.74, 1434127.06, 1412051.42, 1376656.39, 1348414.96, 
1312142.02, 1268380.13, 1221039.99, 1199684.17, 1172311.52, 1150503.25, 
1130011.9, 1122993.64, 1120285.07, 1115514.34, 1113711.39, 1063604.51, 
977238.3, 945861.27, 780180.11, 893915.17, 1034896.67, 1033592.33, 
1129190.83, 1277177.5, 1306247.17, 1257165, 1179783, 1133570.83, 
1109991.83, 1062374.67, 933873.67, 839141, 850556.67, 886601.67, 
900670.67, 888103.33, 854665.33, 814967.33, 803662.5, 769712.67, 
732528.17, 740167, 767443.83, 769106.33, 657860, 458371, 347102.5, 
348705.33, 411406.67, 514879.17, 559087.83, 538073.67, 494522.33, 
450771.23, 421943.82, 382135.14, 336218.29, 291370.9, 245419.75, 
204568.59, 167526.38, 135807.46, 108396.5, 81806.9, 60515.31, 
44586.85, 31746.87, 22125.63, 14957.19, 9717.87, 6271.02, 3890, 
2502.17, 1414.33, 748, 352.33, 178.17, 102.17, 59.5, 27.83, 13.5, 
7.67, 4.83, 1.5, 819166.01, 884885.18, 912927.66, 916670.95, 
918548.98, 899701.15, 868811.6, 856905.08, 853167.18, 875518.85, 
882093.24, 886644.95, 863148.37, 830115.3, 830202.15, 817822.28, 
802868.4, 804501.45, 825853.31, 879978.54, 1016710.9, 1102191.16, 
1175521.91, 1277677.14, 1341265.76, 1383512.77, 1413815.23, 1435263.4, 
1449903.7, 1426655.43, 1390845.92, 1361316.33, 1325004.75, 1279849.66, 
1231674.43, 1209391.04, 1181560.17, 1158992.2, 1137668.22, 1129746.64, 
1126258.25, 1120579.75, 1118148.52, 1066975.05, 979179.59, 947586.78, 
779828.85, 892880.17, 1033473.5, 1031123.67, 1126768, 1273645.33, 
1302395.33, 1252700.5, 1175046.17, 1128229.33, 1103574.83, 1055905.83, 
926832.5, 832059.17, 842035.83, 876989.5, 890203.33, 876978.17, 
842838.5, 802872, 790588.33, 756321.83, 718271.5, 724024.33, 
748737, 748023.33, 639067, 443302.33, 334242.83, 334350, 392509.83, 
489339.5, 528428.33, 504987, 459708.14, 415829.23, 385123.65, 
345240.98, 300198.95, 256778.57, 213202.91, 174806.42, 140850.72, 
112219.3, 87897.33, 64885.23, 47084.48, 33881.35, 23571.03, 15983.97, 
10565.02, 6748.53, 4228.51, 2574.33, 1475.67, 853.33, 443.33, 
204.67, 104, 60.83, 32.5, 12.5, 6.5, 3.83, 2.17), .Dim = c(111L, 
3L), .Dimnames = list(c("0", "1", "2", "3", "4", "5", "6", "7", 
"8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", 
"19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", 
"30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", 
"41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", 
"52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", 
"63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", 
"74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", 
"85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", 
"96", "97", "98", "99", "100", "101", "102", "103", "104", "105", 
"106", "107", "108", "109", "110+"), c("1990", "1991", "1992"
)))

接下来有死亡率数据:

# mortality rate in 1990,1991,1992
> dput(Germany_M$rate$total[,1:3])
structure(c(0.007119, 0.000647, 0.00041, 0.000373, 0.000258, 
0.000251, 0.000218, 0.000245, 0.000225, 0.000165, 0.000175, 0.000187, 
0.000165, 0.000222, 0.00029, 0.000323, 0.000422, 0.000501, 0.000755, 
0.000782, 0.000766, 8e-04, 0.000763, 0.00077, 7e-04, 0.000782, 
0.000742, 0.000758, 0.000784, 0.000908, 0.00096, 0.000936, 0.001049, 
0.001146, 0.001228, 0.00133, 0.001402, 0.001577, 0.001624, 0.001782, 
0.001914, 0.001958, 0.002243, 0.002402, 0.002562, 0.003018, 0.003358, 
0.003487, 0.003914, 0.004087, 0.004717, 0.004996, 0.005402, 0.00617, 
0.006752, 0.007807, 0.008125, 0.009093, 0.009913, 0.011079, 0.012176, 
0.013241, 0.01393, 0.014956, 0.016064, 0.017474, 0.019039, 0.020692, 
0.02329, 0.025322, 0.031231, 0.028207, 0.03351, 0.037694, 0.03925, 
0.047793, 0.051304, 0.058191, 0.065135, 0.072105, 0.081741, 0.091005, 
0.101488, 0.113726, 0.126628, 0.141132, 0.157617, 0.172622, 0.191835, 
0.20896, 0.233755, 0.253642, 0.275071, 0.301754, 0.322428, 0.35452, 
0.380592, 0.393055, 0.395891, 0.428926, 0.55814, 0.573087, 0.643287, 
0.562832, 0.48189, 0.542056, 0.62069, 0.328767, 0.489796, 2.083333, 
6, 0.006503, 0.000614, 0.000386, 0.000334, 0.000273, 0.000238, 
0.000196, 0.000174, 0.000204, 0.000165, 0.000152, 0.000183, 0.000189, 
0.000173, 0.000213, 0.000294, 0.000454, 0.000577, 0.000756, 0.000828, 
0.000774, 0.000772, 0.000755, 0.000754, 0.000755, 0.000776, 0.000799, 
0.000826, 0.000846, 0.000923, 0.000951, 0.00103, 0.001122, 0.001152, 
0.001254, 0.001331, 0.001471, 0.001621, 0.001709, 0.001742, 0.001993, 
0.002116, 0.002215, 0.002409, 0.002662, 0.002966, 0.003305, 0.00356, 
0.003888, 0.004232, 0.00457, 0.00519, 0.005419, 0.006043, 0.006642, 
0.00711, 0.008186, 0.008741, 0.009777, 0.010714, 0.012058, 0.013017, 
0.014265, 0.015324, 0.016133, 0.017241, 0.018997, 0.02025, 0.02216, 
0.024794, 0.027147, 0.033103, 0.030128, 0.03639, 0.040891, 0.042846, 
0.05234, 0.055007, 0.06299, 0.070424, 0.07798, 0.087417, 0.099381, 
0.110708, 0.123358, 0.137141, 0.152633, 0.168511, 0.186389, 0.204628, 
0.221839, 0.245905, 0.265056, 0.29058, 0.31633, 0.341642, 0.362837, 
0.387338, 0.403856, 0.470392, 0.547961, 0.514706, 0.596026, 0.623012, 
0.626427, 0.605042, 0.57485, 0.592593, 0.652174, 0.206897, 0, 
0.006094, 0.000542, 0.000345, 0.000274, 0.000238, 0.000215, 0.000198, 
0.00017, 0.000163, 0.00014, 0.000164, 0.000162, 0.000162, 0.000164, 
0.000201, 0.000287, 0.00037, 0.000481, 0.000729, 0.000848, 0.000755, 
0.000756, 0.000776, 0.000735, 0.000703, 0.00075, 0.000778, 0.000749, 
0.000821, 0.00088, 0.00093, 0.000968, 0.001007, 0.001126, 0.001254, 
0.00134, 0.001389, 0.001491, 0.001646, 0.001793, 0.001907, 0.002147, 
0.002198, 0.002486, 0.002592, 0.002808, 0.00312, 0.003517, 0.003869, 
0.004032, 0.004632, 0.004681, 0.005419, 0.005692, 0.006297, 0.00699, 
0.007661, 0.008712, 0.009417, 0.010527, 0.011497, 0.012631, 0.013793, 
0.014925, 0.016234, 0.016933, 0.018151, 0.01982, 0.021382, 0.023815, 
0.026136, 0.029014, 0.035225, 0.032335, 0.038708, 0.044316, 0.046203, 
0.055532, 0.059261, 0.065984, 0.074739, 0.08383, 0.09276, 0.104582, 
0.116116, 0.130622, 0.143239, 0.161167, 0.17838, 0.192685, 0.2178, 
0.23634, 0.257813, 0.281541, 0.303635, 0.328079, 0.347846, 0.363042, 
0.395411, 0.44128, 0.499435, 0.485156, 0.509774, 0.478827, 0.375, 
0.575342, 0.615385, 0.88, 0.923077, 1.565217, 1.384615), .Dim = c(111L, 
3L), .Dimnames = ...))

似乎没有数据丢失(但是死亡率有些异常)。但是,当我计算lifetable()命令以从HMD数据生成寿命表(总人口寿命表)时,会出现一些问题:

# total population lifetable
 GER_t <- lifetable(Germany_M, series=names(Germany_M$rate)[3], years=Germany_M$year[1:25], ages=Germany_M$age,
                                          max.age=min(110, max(Germany_M$age)), type=c("period"))

现在生成的生命表具有一些“ inf”数据,我不明白为什么

# Tx (total years lived by survivors at age x until age 110) in year 1991
> dput(GER_t$Tx[,2])
structure(c(Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, 
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, 
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, 
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, 
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, 
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, 
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, 
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, 
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf), .Names = c("0", 
"1", "2", "3", ...))

预期寿命数据的显示方式也相同:

# life expectancy for individuals at age x in 1991
> dput(GER_t$ex[,2])
structure(c(Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, 
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, 
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, 
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, 
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, 
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, 
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, 
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, 
Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf, Inf), .Names = c("0", 
"1", "2", "3", ...))

我的目标之一是生成一个图(X =年,Y =预期寿命e_x),该图表示数据集中包括的所有年份中每个年龄段的预期寿命曲线。为了做到这一点,我应该正确地制作上述的寿命表。该图应如图所示: Life expectancy plot

所以我的问题是: 1)为什么会这样? 2)如何解决此问题?

感谢您的帮助

0 个答案:

没有答案