Cox model for recurrent events (with estimation of residuals / of an individual effect) Consider some individuals that are followed during a period $T = 1$ (the same for all individuals). The individual indexed by $i$ have $n_i \ge 0$ events, at times $t_{i1}, t_{i2}, \dots, t_{in_i}$. There is a vector $X_{i}$ of covariates that influence the probability of event occurrence.
A simple model is a Poisson regression: $n_i \sim \mathcal P(\lambda_i)$ with $E(n_i) = \lambda_i = \lambda_0 e^{X_i \beta}$. 
If after estimating the coefficients, I want some kind of individual effect, I could consider for example response residuals $n_i - \widehat{\lambda_i} = n_i - \widehat{\lambda_0} e^{X_i \widehat{\beta}}$.
Now, what's happening is that $X_i$ depends on $t$, and moreover the baseline risk $\lambda_0$ might as well depend on $t$. I can consider a counting process with intensity $\lambda_i(t) = \lambda_0(t) e^{X_i(t) \beta}$. 
Do you think it’s the way to go? Can I fit this model (and, if possible, obtain response residuals or anything that can serve as a proxy of an individual effect) with a classical R package like survival?
All your thoughts are welcome. 
 A: What you mean by individual effect are actually the martingale residuals, that is $n_i - E(n_i)$. There is a whole theory on this and they are commonly used to assess model fit in Cox-type models. I am not sure about the interpretation of individual effect. They do have nice asymptotic properties, and you can find a chapter about them in most serious survival analysis books (I can give some references if you want to).
If you want to fit a semi-parametric model time-dependent model, that is possible with coxph(), as long as you have the data in the correct format. That is, one row should be (tstart, tstop, status, x) where
status == 1 at event time points, and 0 for the end of follow-up, i.e. tstop == 1, or time points where x changes value. A data set that is in this format that I can think of is readmission in the frailtypack package.
To think about an individual effect, I would suggest to use an individual indicator as a factor and look at the interaction between this and $X$. However, I think that you need a lot of data to get something useful out of something like this. 
