Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #The same scale/shape of data given here in 1d form fits just fine in Mort2DSmooth() if
- #I have a matrix of it.
- library(MortalitySmooth)
- ages <- 0:109
- Dx <- structure(c(287.426914898574, 19.2292654333553, 4.04826640702217,
- 4.04826640702217, 4.04826640702217, 0, 0, 1.01206660175554, 2.02413320351109,
- 1.01206660175554, 1.01206660175554, 3.03619980526663, 0, 0, 0,
- 1.01206660175554, 1.01206660175554, 4.04826640702217, 0, 0, 2.02413320351109,
- 0, 2.02413320351109, 0, 1.01206660175554, 2.02413320351109, 0,
- 0, 2.02413320351109, 2.02413320351109, 0, 1.01206660175554, 0,
- 2.02413320351109, 0, 4.04826640702217, 2.02413320351109, 4.04826640702217,
- 1.01206660175554, 0, 2.02413320351109, 0, 2.02413320351109, 0,
- 1.01206660175554, 2.02413320351109, 1.01206660175554, 3.03619980526663,
- 2.02413320351109, 0, 3.03619980526663, 0, 1.01206660175554, 1.01206660175554,
- 5.06033300877772, 2.02413320351109, 4.04826640702217, 1.01206660175554,
- 4.04826640702217, 6.07239961053326, 4.04826640702217, 5.06033300877772,
- 5.06033300877772, 5.06033300877772, 2.02413320351109, 7.0844662122888,
- 6.07239961053326, 11.132732619311, 7.0844662122888, 7.0844662122888,
- 8.09653281404435, 10.1206660175554, 12.1447992210665, 7.0844662122888,
- 8.09653281404435, 6.07239961053326, 15.1809990263332, 11.132732619311,
- 18.2171988315998, 7.0844662122888, 10.1206660175554, 5.06033300877772,
- 17.2051322298442, 7.0844662122888, 14.1689324245776, 12.1447992210665,
- 12.1447992210665, 13.1568658228221, 10.1206660175554, 17.2051322298442,
- 10.1206660175554, 2.02413320351109, 5.06033300877772, 0, 2.02413320351109,
- 4.04826640702217, 1.01206660175554, 1.01206660175554, 0, 0, 1.01206660175554,
- 0, 0, 0, 0, 0, 0, 0, 0, 0), .Names = 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"))
- expo <- structure(c(11130, 10830, 10601, 10413, 10220, 10095, 10015,
- 9954, 9891, 9821, 9742, 9661, 9582, 9499, 9393, 9239, 9029, 8759,
- 8441, 8093, 7736, 7383, 7042, 6718, 6419, 6144, 5891, 5657, 5440,
- 5234, 5035, 4837, 4641, 4445, 4252, 4063, 3880, 3705, 3539, 3384,
- 3234, 3092, 2956, 2828, 2704, 2587, 2477, 2373, 2274, 2181, 2091,
- 2007, 1929, 1853, 1777, 1701, 1630, 1576, 1526, 1470, 1416, 1367,
- 1323, 1278, 1237, 1195, 1150, 1104, 1052, 1002, 951, 901, 854,
- 813, 773, 736, 701, 667, 633, 597, 560, 520, 480, 440, 398, 356,
- 315, 275, 238, 202, 168, 136, 108, 82, 61, 43, 30, 19, 12, 7,
- 4, 2, 0, 0, 0, 0, 0, 0, 0, 0), .Names = 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"))
- # w = 0 if expo = 0, .3 if expo >0, but Dx = 0, 1 otherwise.
- w <- structure(c(1, 1, 1, 1, 1, 0.3, 0.3, 1, 1, 1, 1, 1, 0.3, 0.3,
- 0.3, 1, 1, 1, 0.3, 0.3, 1, 0.3, 1, 0.3, 1, 1, 0.3, 0.3, 1, 1,
- 0.3, 1, 0.3, 1, 0.3, 1, 1, 1, 1, 0.3, 1, 0.3, 1, 0.3, 1, 1, 1,
- 1, 1, 0.3, 1, 0.3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 0.3, 1, 1, 1, 1, 0.3, 0.3, 1, 0.3, 0, 0, 0,
- 0, 0, 0, 0, 0), .Names = 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"))
- # check, opintless?
- all(log(expo)[w>0] > 0)
- Mort1Dsmooth(x = ages,
- y = Dx,
- offset = log(expo),
- w = w
- )
- # Error in while (tol > TOL1 && i < MAX.IT) { :
- # missing value where TRUE/FALSE needed
- Mort1Dsmooth(x = ages,
- y = Dx,
- offset = log(expo),
- w = w,
- control = list(MAX.IT = 500)
- )
- # Error in while (tol > TOL1 && i < MAX.IT) { :
- # missing value where TRUE/FALSE needed
- # fits, but not well:
- fit <- exp(Mort1Dsmooth(x = ages,
- y = Dx,
- offset = log(expo),
- w = w,
- method=3,
- lambda=1e3)$logmortality)
- plot(ages, Dx/expo, log = 'y')
- lines(ages, fit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement