Given the following data from the Surv
function, and trying to fit a model using flexsurvreg
I'm getting an error stating:
Error in
[.default
(Y, , "time") : subscript out of bounds
I'm not sure why this error is occurring. I must be something to do with the data in my Surv
object Y
but I can't figure out what it is, or why it's occurring.
library(flexsurv)
Y <- structure(c(15.9474257914955, 92.8646984681524, 60.7937542591016,
39.0043051102707, 22.2735472359904, 278.426492884738, 23.248652819273,
4.17711769344757, 2.24005517260132, 274.773385211189, 21.3520961126228,
18.2518223950669, 125.312959877672, 85.3612084472231, 27.2734023160286,
36.3620638309367, 403.428793492735, 152.710509835273, 3.10392989813245,
127.28582946954, 63.2099882741064, 44.5655964009001, 2.78577709845033,
10.1090428767665, 102.198023729669, 343.099100197125, 17.2156423414208,
29.4150785094056, 32.4848806916993, 3.6542577596261, 6.95172956945501,
5.87113165766953, 56.8024939247263, 264.697690687394, 71.7590478868313,
14.6108577317073, 20.8013409027592, 70.8457539651151, 25.791752475344,
3.26064956790472, 57.7113479672798, 235.938105241419, 194.317991436403,
42.4436470057455, 257.834274067571, 102.290239804092, 10.100812340795,
34.5474927005247, 10.0337594860639, 383.575147185537, 391.74058499839,
9.47984328773105, 7.35426482323835, 67.7660799235721, 10.5793123247722,
389.128247057677, 58.5388316464529, 143.045014956796, 23.8206669979057,
6.13273314050339, 40.376519704907, 1.66133588374672, 100.825597177946,
11.5298575402338, 403.428793492735, 278.651209575017, 21.1528979520127,
125.560296291348, 16.9371425236829, 8.58662139224698, 39.1666176547387,
10.6516800452639, 54.6887503526312, 49.9744555673712, 8.29554464332079,
7.00761139711887, 28.7522035577908, 168.782824659952, 1.31802200518933,
25.852352792303, 102.306773590937, 250.435169558085, 14.4728494359721,
32.5760886362187, 45.4089016526169, 11.0372942507258, 68.5019135755667,
52.2303579024536, 403.428793492735, 403.428793492735, 141.801217464064,
7.40242943834269, 29.100557117208, 8.96866215119505, 12.4354900525681,
8.16703087179552, 58.1586028095045, 11.4000475582873, 25.4583340915452,
6.16028494710057, 403.428793492735, 84.4824268536514, 50.7414776998092,
18.8735292056578, 403.428793492735, 19.5885585047774, 11.4281913868452,
160.288238443443, 11.4617504201645, 18.2467841931974, 6.20805769909054,
5.66932843252971, 109.730417416886, 286.568917910547, 47.0260093039365,
23.5178655461873, 403.428793492735, 40.8042534601449, 19.3234743656241,
17.820853712635, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 0, 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, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1
), .Dim = c(120L, 2L), .Dimnames = list(NULL, c("", "status")), type = "right", inputAttributes = list(
time = list(dim = c(120L, 1L), dimnames = list(c("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", "111",
"112", "113", "114", "115", "116", "117", "118", "119", "120"
), NULL))), class = "Surv")
flexsurvreg(
Y ~ 1,
dist = "lnorm"
)
The Surv
object does not look right.
Try explicitly naming the time
dimension and re-running the regression:
attr(Y,'dimnames')[[2]][[1]] <- 'time'