12
$\begingroup$

I'm trying to fit a discrete-time model in R, but I'm not sure how to do it.

I've read that you can organize the dependent variable in different rows, one for each time-observation, and the use the glm function with a logit or cloglog link. In this sense, I have three columns: ID, Event (1 or 0, in each time-obs) and Time Elapsed (since the beginning of the observation), plus the other covariates.

How do I write the code to fit the model? Which is the dependent variable? I guess I could use Event as the dependent variable, and include the Time Elapsed in the covariates. But what happens with the ID? Do I need it?

Thanks.

$\endgroup$
3
  • $\begingroup$ When you say "I'm trying to fit a discrete time model" ... what model do you want to fit? (If this is for some subject, please add the self-study tag.) $\endgroup$
    – Glen_b
    Commented Apr 25, 2013 at 10:03
  • $\begingroup$ I want to fit a logit discrete-time survival model. $\endgroup$ Commented Apr 25, 2013 at 10:10
  • 1
    $\begingroup$ It seems unlikely that ID is relevant, but it depends on what, exactly it represents and whether that's something you want to model. $\endgroup$
    – Glen_b
    Commented Apr 25, 2013 at 13:18

3 Answers 3

7
$\begingroup$

Singer and Willett have been published a lot on this subject. I highly recommend that you read some of their papers. You also might want to get their book "Applied Longitudinal Data Analysis: Modeling Change and Event Occurrence". Clearly one of the best textbooks in this field.

For most book chapters there is R sample code (see chapters 11ff) available that demonstrates how your data has to be structured ("person-period format") and how to analyze that kind of data. For a standard discrete-time model you do not need the ID variable and you also do not need to estimate a mixed-effects model as suggested by @ndoogan. A simple glm(event ~ time + ..., family = "binomial") works just fine. Singer and Willett also discuss many issues how to model the time variable (linear, quadratic, ...)

To cite two more references that I highly recommend:

$\endgroup$
1
$\begingroup$

You can break time time into intervals and perform a multiperiode logit model as in Shumway (2001). E.g., you time intervals are $(0, 1], (1, 2], \dots$. I have implemented this in dynamichazard::static_glm in R which is directly applicable if you have initial data in a typical stop-event setup used in survival analysis. Do notice that the t-stats from the resulting model does not have the correction mentioned in Shumway (2001).

This method differs from the one @ndoogan with time dummies as you only get one common intercept in all time periods with dynamichazard::static_glm. You can, however, get a dummy for each period by calling dynamichazard::get_survival_case_weights_and_data with argument use_weights = FALSE, add the time dummy indicator yourself to the returned data.frame and then call e.g. glm.

$\endgroup$
1
0
$\begingroup$

This is called "counting process" data. Survival package has a very nice tmerge() function. It's very useful to insert time dependent or cumulative covariates and partition follow-up time accordingly. The process is very well explained in this vignette

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.