Skip to contents

multi_state() estimates the probability of being in each state of a multi-state process over time with the Aalen-Johansen estimator. At each distinct time \(t\), the transition from state \(j\) to state \(k\) has the estimated increment \(d_{jk}(t) / Y_j(t)\), the number of such transitions over the number in state \(j\) at risk. The transition probability matrix is the product of the matrices \(I + dA(t)\) over the times up to \(t\), and the occupancy probabilities are the starting distribution times that product. They add up to 1 at every time.

Usage

multi_state(formula, data, istate, subset, na.action = stats::na.omit)

Arguments

formula

A formula with a multi-state Surv() response on the left and either 1 or the grouping variables on the right. The response is Surv(start, stop, event), or Surv(time, event) for competing risks, with event a factor whose first level means censored and whose other levels are the states entered.

data

A data frame holding the variables in formula and istate.

istate

The state each row's interval is spent in, a column of data or a vector. The default puts every row in the state "(s0)".

subset

An optional expression selecting the rows of data to use.

na.action

What to do with rows that have missing values. The default drops them.

Value

A multi_state object. as.data.frame() gives the occupancy probabilities with one row per group, state, and distinct stop time: strata, the grouping variables, state, time, and estimate. predict() reads them at given times.

Details

The data are intervals (start, stop], one row per stretch of time a subject spends in one state. istate gives that state, and the event of the Surv() response the state entered at stop (or censoring). A subject who moves through several states has one row per state. The starting distribution is the proportion of the rows that begin at the earliest start time in each state.

Competing risks are the special case with one starting state and one absorbing state per cause. Then istate can be left out: every subject starts in the state "(s0)", its occupancy is the Kaplan-Meier estimate of being free of any event, and the occupancy of each other state is the cumulative incidence of aalen_johansen().

Examples

# An illness-death process: healthy -> ill -> dead, or healthy -> dead
intervals <- data.frame(
  id = c(1, 1, 2, 3, 3, 4, 5, 6, 6, 7, 8),
  start = c(0, 20, 0, 0, 35, 0, 0, 0, 50, 0, 0),
  stop = c(20, 60, 45, 35, 90, 70, 30, 50, 80, 100, 65),
  from = c("healthy", "ill", "healthy", "healthy", "ill", "healthy", "healthy", "healthy",
    "ill", "healthy", "healthy"),
  to = c("ill", "dead", "dead", "ill", "censor", "censor", "dead", "ill", "dead", "censor",
    "dead")
)
intervals$to <- factor(intervals$to, levels = c("censor", "ill", "dead"))

fit <- multi_state(Surv(start, stop, to) ~ 1, data = intervals, istate = from)
fit
#> <multi_state> Surv(start, stop, to) ~ 1
#> States: healthy, ill, dead. n = 11
#> 
#> Occupancy at the last time:
#>    state time estimate
#>  healthy  100    0.250
#>      ill  100    0.125
#>     dead  100    0.625
predict(fit, times = c(25, 50, 75))
#>   strata   state time estimate
#> 1    all healthy   25    0.875
#> 2    all healthy   50    0.375
#> 3    all healthy   75    0.250
#> 4    all     ill   25    0.125
#> 5    all     ill   50    0.375
#> 6    all     ill   75    0.250
#> 7    all    dead   25    0.000
#> 8    all    dead   50    0.250
#> 9    all    dead   75    0.500