(This is an edited version of a previously closed question)
I have a data.frame
(condensed to testdata) of several demographic variables in addition to one variable with three levels for three possible comorbidities.
dput(testdata)
structure(list(age = c(31L, 48L, 19L, 23L, 24L, 24L, 40L, 22L,
25L, 20L, 39L, 26L, 28L, 27L, 25L), gender = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("F",
"M"), class = "factor"), race = structure(c(NA, NA, 1L, NA, 1L,
NA, NA, NA, 2L, 1L, NA, 3L, NA, 1L, NA), .Label = c("C", "M",
"N", "R", "Z"), class = "factor"), Time1 = c(NA, NA, NA, 319,
NA, 133, NA, 121, NA, NA, 30, NA, NA, NA, NA), Time2 = c(NA,
109, NA, NA, NA, NA, NA, NA, NA, NA, NA, 108, 52, NA, NA), Time3 = c(NA,
73, NA, NA, 4, NA, NA, 121, NA, NA, 2, NA, NA, NA, NA), OutcomeTime = c(4380,
199, 4380, 4380, 4380, 4380, 4380, 4380, 4380, 4380, 196, 4380,
4380, 4380, 4380), CoMo1 = c(NA, NA, NA, 1, NA, 1, NA, 1, NA,
NA, 1, NA, NA, NA, NA), CoMo2 = c(NA, 2, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 2, 2, NA, NA), CoMo3 = c(NA, 3, NA, NA, 3, NA,
NA, 3, NA, NA, 3, NA, NA, NA, NA), Outcome = c(0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 0, 0, 0), ID = 1:15), class = "data.frame", row.names =
c("1",
"4", "6", "7", "8", "11", "14", "18", "19", "26", "27", "28",
"30", "31", "38"))
Time1, Time2, Time3 are the times at which the ID had the comorbidity, CoMo1, CoMo2, CoMo3 respectively. The Outcome variable is whether death occurred or not. The OutcomeTime is when death occurred or if they patient was followed to the end of the study with no death.
In trying to set this up using tmerge()
, I've had some difficulty with the commands (first time doing this!):
newdata<-tmerge(data1=testdata[,c(1:3,12)], data2=testdata, id=ID,
tstop=OutcomeTime, tstart=0)
newdata<-tmerge(newdata, testdata, id=ID, Comorbid=event(OutcomeTime))
newdata<-tmerge(newdata, testdata, id=ID, Comorbid=event(Time1))
newdata<-tmerge(newdata, testdata, id=ID, Comorbid=event(Time2))
newdata<-tmerge(newdata, testdata, id=ID, Comorbid=event(Time3))
newdata<-tmerge(newdata,newdata, ID, enum=cumevent(tstart))
I've tried several renditions with the above and I'm not getting quite what I want:
1) I would like a column specifying which comorbidity is occurring in the interval
2) I would like a column for the Outcome variable. As it is currently, it looks like maybe for IDs that have comorbities, it's adding another time interval for the Outcome but it's not being recorded anywhere. It really should be it's own variable.
3) Can someone explain the difference between when to use event, cumevent, tdc, and cumtdc?
Thank you!