# Which model to use for survival analysis when there are different times of entry into the sample?

I have a data set containing the trades executed by many traders as follows:

ID       Buy(1)/Sell(0)    StartTime    EndTime      PnL
1              1               1           1          7
1              1               2           3          5
1              0               2           5          6
1              1               3           5         -4
2              1               1           3          8
2              0               2           2         -9
2              0               3           5          3


where ID is the trader's identification number, Buy(1)/Sell(0) indicates whether the trade was a buy or sell, for simplicity StartTime and EndTime are the day on which the trade was opened and closed, and PnL is the profit or loss from that trade.

My goal here is to study whether a trader closes his position earlier (i.e. duration of a trade) based on whether he has made a gain or a loss.

I am very new to the concept of hazard models. I understand the main idea behind them, but I am not sure what is the correct model to apply in my case where I have several traders, each with multiple trades that have different entry times (StartTime).

I would greatly appreciate any help you can provide me, with as much detail as possible.

UPDATE: How would the model specification differ if the transactions in my data are considered to be correlated? I am using R.

Thank you.

• Are you interested in what individual traders do (eg, 'does trader 1 close his position earlier...?'), or what traders on average do? – gung - Reinstate Monica Mar 12 '15 at 3:10
• I am interested in the average, but Now that you mention it, I would also like to see how individuals do. So I would like to conduct both analyses. – finstats Mar 12 '15 at 3:17
• You will need a model w/ a random effect of trader. You can get the predicted REs for the traders to compare them, but that doesn't entail a significance test of 1 trader vs another. – gung - Reinstate Monica Mar 12 '15 at 3:19

I would have modelled this as a plain Cox model, or perhaps a Cox Frailty model.

• You do not need to worry about the timing of entry into your study when using Cox regression (unless there is time bias, which I do not notice in your description).

• You don't need the extended Cox model with start and stop intervals, just calculate the observation time (EndTime - StartTime) and enter it into Surv(observation_time, event).

• You should account for the repeated measurements on the same individual by either using: (i) mixed effects cox models, (ii) the cluster function in coxph.

• I agree with Adam that it's easier if we assume that what we are studying is stationary in time. – wsw Jun 28 '16 at 17:31

The Cox Proportional Hazards model in R allows for late entry into the sample.

One can enter the parameters as follows:

cox.model <- coxph(Surv(startTime, endTime, event) ~ X + frailty(ID), data)