0
$\begingroup$

I'm just getting started with survival analysis and I'm having trouble finding something in R that will do what I'm looking for.

Most of the packages use survival objects that have an individual record for each patient being looked at (so, patient $1$ at time $0$ was alive, patient $2$ at time $0$ was alive, etc.).

My data however is grouped because of the larger numbers. For example, at time $0$, $1000$ patients were alive and $0$ were dead, at time $1$, $975$ patients were alive and $25$ were dead.

(d1 <- data.frame(TIME=10:5, DEAD=c(0, 0, 1195, 1237, 1251, 1257),
                  ALIVE=c(1398, 1398, 203, 161, 147, 141)))
  TIME DEAD ALIVE
1   10    0  1398
2    9    0  1398
3    8 1195   203
4    7 1237   161
5    6 1251   147
6    5 1257   141

Is there a package or something in R or a specific model or something that allows me to perform a survival analysis on data formatted this way? I know this question may not be specifically statistical in nature, but I figured people here would know the most about R.

$\endgroup$

1 Answer 1

0
$\begingroup$

As time normally increases, I would rewrite this as:

(d1 <- data.frame(t1=seq(5),
                  de1=c(0, 1195, 1237, 1251, 1257)))
  t1  de1
1  1    0
2  2 1195
3  3 1237
4  4 1251
5  5 1257

There is no censoring until the final time point.

We can ignore the first time point as there was no death or censoring there.

For the last four time points we can get the number that died as

(diff(d1$de1))
[1] 1195   42   14    6

We also know from the data you provide that there were $141$ or 1398 - sum(diff(d1$de1)) still alive and so censored at the final time.

Thus:

library(survival)
s1 <- Surv(c(rep(2, 1195), rep(3, 42), rep(4, 14), rep(5, 6), rep(5, 141)),
           c(rep(1, 1195), rep(1, 42), rep(1, 14), rep(1, 6), rep(0, 141))
           )

which we can use as normal e.g.

(survfit(s1 ~ 1))
Call: survfit(formula = s1 ~ 1)

records   n.max n.start  events  median 0.95LCL 0.95UCL 
   1398    1398    1398    1257       2       2       2 

Given the example, this is a rather 'concrete' solution and could if it needs to be generalized further then paste/apply should be helpful.

$\endgroup$

Your Answer

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

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