Skip to content
Prev 244700 / 398513 Next

R Plots for Recurrent Events - Suggestions are needed

Hi Haoda,

I couldn't find a package that implements this, although I'm not
familiar with the field so there could be something but using
different terminology.

However, looking at the the Google preview of Nelson (2003) which is
cited by the page that you linked to, the calculations seem very
simple (see page 46).  Here is a function which I think does what is
described there (warning: untested !)...

mcf <- function(events) {
# events a data.frame or matrix where:
#   col 1 is unitID
#   col 2 is event time (integer)
#   col 3 is event type coded as:
#      0: recurrence
#      1: first appearance (left censoring time)
#      2: last appearance (right censoring time)
#
    # Order events data by time, unit id, event type
    events <- events[ order(events[,2], events[,1], events[,3]), ]

    m <- matrix(0, nrow=nrow(events), ncol=4)
    colnames(m) <- c("time", "Nrisk", "incr", "mcf")

    # copy event times
    m[, 1] <- events[, 2]

    # number of units observed at each time
    m[, 2] <- cumsum(ifelse(events[, 3] == 2, -1, events[, 3]))

    # incremental risk
    irecurrence <- events[,3] == 0
    m[irecurrence, 3] <- 1 / m[irecurrence, 2]

    # cumulative risk (MCF estimate)
    m[, 4] <- cumsum(m[, 3])

    # return results (matrix rows with recurrent events)
    m[events[,3] == 0, ]
}

Hope this helps.

Michael
On 13 December 2010 03:47, Haoda Fu <fuhds at yahoo.com.cn> wrote: