I have a question: I am trying to build a proportional hazards model with a time-varying constant.
Effectively, the question is the occurrence of an illness following a traumatic event. The traumatic event can happen at any time during the follow-up, and I am interested in the increased risk that subjects with the trauma have of the illness compared to those without a trauma history.
The illness has to follow the trauma in time for it to count as a trauma-associated illness. I am planning on doing a washout period of 0, then 1 year, 3 years, and 5 years (as in, if the illness occurs within 1 year, etc it would not count as trauma-related)
I have a dataframe with
Columns: | ID | Age_at_recruitmen | Age_at_trauma | Age_at_illness | Status | Age_at_censoring_death_end_of_study |
I have been using tmerge function to try this, but although this splits the data, it makes all the events 0!
Example data:
Outcome_dataset <- data.frame(
id = c(1, 2, 3),
start = c(50, 55, 60),
stop = c(70, 80, 65),
event = c(0, 0, 1),
Age_at_injury = c(NA, 78, 61),
)
#EDITED With my code
baseline <- data.frame(
id = Simple$eid,
start = Simple$start,
stop = Simple$stop,
event = Simple$event
)
injury <- data.frame(
id = Simple$eid,
injury_time = Simple$Age_at_injury
)
# Use tmerge to create the time-varying data
df_tmerge <- tmerge(
data1 = baseline,
data2 = baseline,
id = id,
tstart = start,
tstop = stop,
event = event(event)
)
# Add the injury time-varying exposure
df_tmerge <- tmerge(
data1 = df_tmerge,
data2 = head_injury,
id = id,
injury = tdc(injury_time)
)
cox_model <- coxph(Surv(tstart, tstop, event) ~ injury, data = df_tmerge)
summary(cox_model)
The above code seems to separate at the time of the event, but not indicate whether the subject had the event.
Thanks