dear StackExchange users,
I'm struggling with a survival analysis problem. I have longitudinal data, so with multiple observations per individual (about 8 months per person). Each row represents one month. My dataset contains both time-varying variables and time-constant variables. Since the proportionality assumption does no hold on my data, I want to use the piecewise constant hazard model. I figured out how to do this for a binary survival problem (alive/death), but I would like to expand it to a competing risk problem (e.g. sick is the current state, person can move to death or to being healthy again). The only thing this will change in my dataset is that the event column can also have '2' instead of only 1 and 0. I added the code I used for the binary problem below. I'm really hoping someone can help me out!
and the code I used to fit the piecewise poisson:
fit <- glm(event~offset(log(time))+interval+year, data=pw.heart, fam="poisson")
lambda <- exp(predict(fit, new=predict.data))
surv.pois <- exp(-cumsum(lambda))