0
$\begingroup$

How do you model panel data in a survival model?

I am unsure how to model repeated cases (or id) in coxph, since the common form is:

fit <- coxph(Surv(time, event) ~ x1, data=df)

Here is a slice of the data:

> head(d)
  year month id demmonth demend      dev      gro
1 2002     7  1        1      0 8.308352 6.869293
2 2002     8  1        2      0 8.308352 6.869293
3 2002     9  1        3      0 8.308352 6.869293
4 2002    10  1        4      0 8.308352 6.869293
5 2002    11  1        5      0 8.308352 6.869293
6 2002    12  1        6      0 8.308352 6.869293

The time variable is demmonth.

The event variable is demend.

The predictors are dev + gro.

A common survival model would look like:

fit <- coxph(Surv(demmonth, demend) ~ dev + gro, data=df)

But, since my dataset is comprised of repeated observations of many different ids over time, how can I model panel data via survival?

Full data can be found here: https://raw.githubusercontent.com/rocketfish88/democ/master/MaedaCSV2.csv

$\endgroup$

closed as off-topic by gung Jan 8 at 21:30

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – gung
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Questions that are only about software (e.g. error messages, code or packages, etc.) are generally off topic here. If you have a substantive machine learning or statistical question, please edit to clarify. $\endgroup$ – gung Jan 8 at 21:30
  • $\begingroup$ Please do not repost questions that have been closed as off topic. $\endgroup$ – gung Jan 8 at 21:31
2
$\begingroup$

Make sure to add another time column. Each row should have initial and end time of each spell so that the end time of row i equals the start time of row i+1. Sort the data by id and time, and the model will do the rest. This way the model will understand that when t0==0, a new id has started.

Thus, your data should have the following structure:

  year month id demmonth t0  t2      dev      gro
1 2002  8     1    1      0   1      8.308352 6.869293
2 2002  9     1    2      1   2      8.308352 6.869293
3 2002  10    1    3      2   3      8.308352 6.869293
etc...

The model will be:

fit <- coxph(Surv(t0, t1, demend) ~ dev + gro, data=df)

See Using Time Dependent Covariates for more detailed information.

$\endgroup$
  • $\begingroup$ I really appreciate your time and help! $\endgroup$ – John Stud Jan 8 at 21:41

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