r - Adding time varying covariates to survival data using 'tmerge' in 'survival' package -


i'm trying add several time dependent covariates dataset survival analysis using tmerge survival package. mean add each sequentially, recommended in vignette on subject, output first addition not work intended.

more specifically, have 1 simple data.frame ids of individual (organizations) , number of days (age) until organization ceases activities. second data.frame has ids , number of days until organization experiences "transition" event. not organizations experience transition, not organizations present in second data.frame.

in first call tmerge format first data.frame in format package uses. in second try add variable counts number of transitions organization has experienced. organizations, result expect, small number result not make sense , there no obvious reason me why fails.

the data.frames small, post them along code below.

ages <- structure(list(id = c(1l, 2l, 5l, 6l, 9l, 10l, 12l, 13l, 14l, 15l, 16l, 17l, 18l, 20l, 21l, 24l, 26l, 27l, 28l, 29l, 30l, 31l, 34l, 35l, 36l, 37l, 38l, 39l, 40l, 42l, 45l, 46l, 43l, 48l, 49l, 50l, 51l, 52l, 54l, 55l, 57l, 58l, 59l, 60l, 61l, 62l, 63l, 64l, 65l, 66l, 68l, 69l, 70l, 71l, 72l, 73l, 74l, 75l, 8l, 19l, 22l, 23l, 33l, 41l), age = c(13668, 21550, 15249, 21550, 16045, 21550, 14976, 14976, 6574, 21550, 4463, 16927, 16927, 15706, 4567, 21306, 17235, 22158, 19692, 17632, 17597, 4383, 5811, 7704, 5063, 17351, 17015, 16801, 4383, 5080, 13185, 12604, 19784, 5310, 15369, 13239, 1638, 21323, 10914, 21262, 7297, 17214, 17508, 14199, 14062, 2227, 8434, 4593, 14429, 21323, 4782, 10813, 2667, 2853, 5709, 3140, 12237, 7882, 21550, 15553, 16466, 16621, 19534, 21842)), .names = c("id", "age"), row.names = c(na, 64l), class = "data.frame") ages1 <- tmerge(ages, ages, id=id, tstop=age) transitions <- structure(list(id = c(2l, 2l, 6l, 8l, 10l, 19l, 22l, 23l, 24l, 31l, 33l, 41l, 43l, 43l, 52l, 55l, 66l), transition = structure(c(18993, 13668, 15249, 15706, 15887, 11609, 4023, 9316, 16193, 1461, 4584, 17824, 3713, 11261, 16818, 10670, 15479), class = "difftime", units = "days")), .names = c("id", "transition"), row.names = c(3l, 4l, 7l, 8l, 11l, 20l, 25l, 27l, 28l, 35l, 38l, 47l, 49l, 51l, 59l, 61l, 73l), class = "data.frame") newdata <- tmerge(ages1, transitions, id=id, transition=cumtdc(transition)) 

as example of 1 fails, consider id=22. experiences 1 transition after 4023 days. so, tmerge should create 2 new rows id=22: 1 0 4023 , 1 4023 16466 (the age organization 'dies'). both of these created, third unnecessary row id=22 start of 0 , stop of 16466.

there 17 transitions spread across 64 organizations , count 3 errors 1 above , cannot figure out sets these 3 apart remaining (successful) cases. fix these 3 other tvcs added, time cost of detecting , fixing such errors rise exponentially. ideas i'm missing?

the problem solved simple sort id. ages1 <- ages1[order(ages1$id),]. package creator provided solution.


Comments