Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.57 KB | None | 0 0
  1. #The same scale/shape of data given here in 1d form fits just fine in Mort2DSmooth() if
  2. #I have a matrix of it.
  3.  
  4. library(MortalitySmooth)
  5.  
  6. ages <- 0:109
  7. Dx <- structure(c(287.426914898574, 19.2292654333553, 4.04826640702217,
  8. 4.04826640702217, 4.04826640702217, 0, 0, 1.01206660175554, 2.02413320351109,
  9. 1.01206660175554, 1.01206660175554, 3.03619980526663, 0, 0, 0,
  10. 1.01206660175554, 1.01206660175554, 4.04826640702217, 0, 0, 2.02413320351109,
  11. 0, 2.02413320351109, 0, 1.01206660175554, 2.02413320351109, 0,
  12. 0, 2.02413320351109, 2.02413320351109, 0, 1.01206660175554, 0,
  13. 2.02413320351109, 0, 4.04826640702217, 2.02413320351109, 4.04826640702217,
  14. 1.01206660175554, 0, 2.02413320351109, 0, 2.02413320351109, 0,
  15. 1.01206660175554, 2.02413320351109, 1.01206660175554, 3.03619980526663,
  16. 2.02413320351109, 0, 3.03619980526663, 0, 1.01206660175554, 1.01206660175554,
  17. 5.06033300877772, 2.02413320351109, 4.04826640702217, 1.01206660175554,
  18. 4.04826640702217, 6.07239961053326, 4.04826640702217, 5.06033300877772,
  19. 5.06033300877772, 5.06033300877772, 2.02413320351109, 7.0844662122888,
  20. 6.07239961053326, 11.132732619311, 7.0844662122888, 7.0844662122888,
  21. 8.09653281404435, 10.1206660175554, 12.1447992210665, 7.0844662122888,
  22. 8.09653281404435, 6.07239961053326, 15.1809990263332, 11.132732619311,
  23. 18.2171988315998, 7.0844662122888, 10.1206660175554, 5.06033300877772,
  24. 17.2051322298442, 7.0844662122888, 14.1689324245776, 12.1447992210665,
  25. 12.1447992210665, 13.1568658228221, 10.1206660175554, 17.2051322298442,
  26. 10.1206660175554, 2.02413320351109, 5.06033300877772, 0, 2.02413320351109,
  27. 4.04826640702217, 1.01206660175554, 1.01206660175554, 0, 0, 1.01206660175554,
  28. 0, 0, 0, 0, 0, 0, 0, 0, 0), .Names = c("0", "1", "2", "3", "4",
  29. "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
  30. "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26",
  31. "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37",
  32. "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48",
  33. "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
  34. "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70",
  35. "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81",
  36. "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92",
  37. "93", "94", "95", "96", "97", "98", "99", "100", "101", "102",
  38. "103", "104", "105", "106", "107", "108", "109"))
  39. expo <- structure(c(11130, 10830, 10601, 10413, 10220, 10095, 10015,
  40. 9954, 9891, 9821, 9742, 9661, 9582, 9499, 9393, 9239, 9029, 8759,
  41. 8441, 8093, 7736, 7383, 7042, 6718, 6419, 6144, 5891, 5657, 5440,
  42. 5234, 5035, 4837, 4641, 4445, 4252, 4063, 3880, 3705, 3539, 3384,
  43. 3234, 3092, 2956, 2828, 2704, 2587, 2477, 2373, 2274, 2181, 2091,
  44. 2007, 1929, 1853, 1777, 1701, 1630, 1576, 1526, 1470, 1416, 1367,
  45. 1323, 1278, 1237, 1195, 1150, 1104, 1052, 1002, 951, 901, 854,
  46. 813, 773, 736, 701, 667, 633, 597, 560, 520, 480, 440, 398, 356,
  47. 315, 275, 238, 202, 168, 136, 108, 82, 61, 43, 30, 19, 12, 7,
  48. 4, 2, 0, 0, 0, 0, 0, 0, 0, 0), .Names = c("0", "1", "2", "3",
  49. "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
  50. "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26",
  51. "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37",
  52. "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48",
  53. "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
  54. "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70",
  55. "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81",
  56. "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92",
  57. "93", "94", "95", "96", "97", "98", "99", "100", "101", "102",
  58. "103", "104", "105", "106", "107", "108", "109"))
  59. # w = 0 if expo = 0, .3 if expo >0, but Dx = 0, 1 otherwise.
  60. w <- structure(c(1, 1, 1, 1, 1, 0.3, 0.3, 1, 1, 1, 1, 1, 0.3, 0.3,
  61. 0.3, 1, 1, 1, 0.3, 0.3, 1, 0.3, 1, 0.3, 1, 1, 0.3, 0.3, 1, 1,
  62. 0.3, 1, 0.3, 1, 0.3, 1, 1, 1, 1, 0.3, 1, 0.3, 1, 0.3, 1, 1, 1,
  63. 1, 1, 0.3, 1, 0.3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  64. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  65. 1, 1, 1, 1, 1, 1, 0.3, 1, 1, 1, 1, 0.3, 0.3, 1, 0.3, 0, 0, 0,
  66. 0, 0, 0, 0, 0), .Names = c("0", "1", "2", "3", "4", "5", "6",
  67. "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17",
  68. "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28",
  69. "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39",
  70. "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50",
  71. "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61",
  72. "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72",
  73. "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83",
  74. "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94",
  75. "95", "96", "97", "98", "99", "100", "101", "102", "103", "104",
  76. "105", "106", "107", "108", "109"))
  77. # check, opintless?
  78. all(log(expo)[w>0] > 0)
  79.  
  80. Mort1Dsmooth(x = ages,
  81. y = Dx,
  82. offset = log(expo),
  83. w = w
  84. )
  85. # Error in while (tol > TOL1 && i < MAX.IT) { :
  86. # missing value where TRUE/FALSE needed
  87. Mort1Dsmooth(x = ages,
  88. y = Dx,
  89. offset = log(expo),
  90. w = w,
  91. control = list(MAX.IT = 500)
  92. )
  93. # Error in while (tol > TOL1 && i < MAX.IT) { :
  94. # missing value where TRUE/FALSE needed
  95.  
  96. # fits, but not well:
  97. fit <- exp(Mort1Dsmooth(x = ages,
  98. y = Dx,
  99. offset = log(expo),
  100. w = w,
  101. method=3,
  102. lambda=1e3)$logmortality)
  103.  
  104. plot(ages, Dx/expo, log = 'y')
  105. lines(ages, fit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement