etm: Computation of the empirical transition matrix

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/etm.R

Description

This function computes the empirical transition matrix, also called Aalen-Johansen estimator, of the transition probability matrix of any multistate model. The covariance matrix is also computed.

Usage

1
2
3
4
## S3 method for class 'data.frame'
etm(data, state.names, tra, cens.name, s, t = "last",
    covariance = TRUE, delta.na = TRUE, modif = FALSE,
    c = 1, alpha = NULL, strata, ...)

Arguments

data

data.frame of the form data.frame(id,from,to,time) or (id,from,to,entry,exit)

id:

patient id

from:

the state from where the transition occurs

to:

the state to which a transition occurs

time:

time when a transition occurs

entry:

entry time in a state

exit:

exit time from a state

This data.frame is transition-oriented, i.e. it contains one row per transition, and possibly several rows per patient. Specifying an entry and exit time permits to take into account left-truncation.

state.names

A vector of characters giving the states names.

tra

A quadratic matrix of logical values describing the possible transitions within the multistate model.

cens.name

A character giving the code for censored observations in the column 'to' of data. If there is no censored observations in your data, put 'NULL'.

s

Starting value for computing the transition probabilities.

t

Ending value. Default is "last", meaning that the transition probabilities are computed over (s, t], t being the last time in the data set.

covariance

Logical. Decide whether or not computing the covariance matrix. May be useful for, say, simulations, as the variance computation is a bit long. Default is TRUE.

delta.na

Logical. Whether to export the array containing the increments of the Nelson-Aalen estimator. Default is TRUE.

modif

Logical. Whether to apply the modification of Lai and Ying for small risk sets

c

Constant for the Lai and Ying modification. Either c contains only one value that will be used for all the states, otherwise c should be the same length as state.names.

alpha

Constant for the Lai and Ying modification. If NULL (the default) then only c is used and the Lai and Ying modification discards the event times for which Y(t) >= t. Otherwise cn^alpha is used. It is recommanded to let alpha equal NULL for multistate models.

strata

Character vector giving variables on which to stratify the analysis.

...

Not used

Details

Data are considered to arise from a time-inhomogeneous Markovian multistate model with finite state space, and possibly subject to independent right-censoring and left-truncation.

The matrix of the transition probabilities is estimated by the Aalen-Johansen estimator / empirical transition matrix (Andersen et al., 1993), which is the product integral over the time period (s, t] of I + the matrix of the increments of the Nelson-Aalen estimates of the cumulative transition hazards. The (i, j)-th entry of the empirical transition matrix estimates the transition probability of being in state j at time t given that one has been in state j at time s.

The covariance matrix is computed using the recursion formula (4.4.19) in Anderson et al. (1993, p. 295). This estimator of the covariance matrix is an estimator of the Greenwood type.

If the multistate model is not Markov, but censorship is entirely random, the Aalen-Johansen estimator still consistently estimates the state occupation probabilities of being in state i at time t (Datta & Satten, 2001; Glidden, 2002)

Recent versions of R have changed the data.frame function, where the default for the stringsAsFactors argument from TRUE to FALSE. etm currently depends on the states being factors, so that the user should use data.frame(..., stringsAsFactors=TRUE).

Value

est

Transition probability estimates. This is a 3 dimension array with the first dimension being the state from where transitions occur, the second the state to which transitions occur, and the last one being the event times.

cov

Estimated covariance matrix. Each cell of the matrix gives the covariance between the transition probabilities given by the rownames and the colnames, respectively.

time

Event times at which the transition probabilities are computed. That is all the observed times between (s, t].

s

Start of the time interval.

t

End of the time interval.

trans

A data.frame giving the possible transitions.

state.names

A vector of character giving the state names.

cens.name

How the censored observation are coded in the data set.

n.risk

Matrix indicating the number of individuals at risk just before an event

n.event

Array containing the number of transitions at each times

delta.na

A 3d array containing the increments of the Nelson-Aalen estimator.

ind.n.risk

When modif is true, risk set size for which the indicator function is 1

If the analysis is stratified, a list of etm objects is returned.

Note

Transitions into a same state, mathematically superfluous, are not allowed. If transitions into the same state are detected in the data, the function will stop. Equally, diag(tra) must be set to FALSE, see the example below.

Author(s)

Arthur Allignol, arthur.allignol@gmail.com

References

Beyersmann J, Allignol A, Schumacher M: Competing Risks and Multistate Models with R (Use R!), Springer Verlag, 2012 (Use R!)

Allignol, A., Schumacher, M. and Beyersmann, J. (2011). Empirical Transition Matrix of Multi-State Models: The etm Package. Journal of Statistical Software, 38.

Andersen, P.K., Borgan, O., Gill, R.D. and Keiding, N. (1993). Statistical models based on counting processes. Springer Series in Statistics. New York, NY: Springer.

Aalen, O. and Johansen, S. (1978). An empirical transition matrix for non-homogeneous Markov chains based on censored observations. Scandinavian Journal of Statistics, 5: 141-150.

Gill, R.D. and Johansen, S. (1990). A survey of product-integration with a view towards application in survival analysis. Annals of statistics, 18(4): 1501-1555.

Datta, S. and Satten G.A. (2001). Validity of the Aalen-Johansen estimators of stage occupation probabilities and Nelson-Aalen estimators of integrated transition hazards for non-Markov models. Statistics and Probability Letters, 55(4): 403-411.

Glidden, D. (2002). Robust inference for event probabilities with non-Markov data. Biometrics, 58: 361-368.

See Also

print.etm, summary.etm, sir.cont, xyplot.etm

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
data(sir.cont)

# Modification for patients entering and leaving a state
# at the same date
# Change on ventilation status is considered
# to happen before end of hospital stay
sir.cont <- sir.cont[order(sir.cont$id, sir.cont$time), ]
for (i in 2:nrow(sir.cont)) {
  if (sir.cont$id[i]==sir.cont$id[i-1]) {
    if (sir.cont$time[i]==sir.cont$time[i-1]) {
      sir.cont$time[i-1] <- sir.cont$time[i-1] - 0.5
    }
  }
}

### Computation of the transition probabilities
# Possible transitions.
tra <- matrix(ncol=3,nrow=3,FALSE)
tra[1, 2:3] <- TRUE
tra[2, c(1, 3)] <- TRUE

# etm
tr.prob <- etm(sir.cont, c("0", "1", "2"), tra, "cens", 1)

tr.prob
summary(tr.prob)

# plotting
if (require("lattice")) {
xyplot(tr.prob, tr.choice=c("0 0", "1 1", "0 1", "0 2", "1 0", "1 2"),
       layout=c(2, 3), strip=strip.custom(bg="white",
         factor.levels=
     c("0 to 0", "1 to 1", "0 to 1", "0 to 2", "1 to 0", "1 to 2")))
}

### example with left-truncation

data(abortion)

# Data set modification in order to be used by etm
names(abortion) <- c("id", "entry", "exit", "from", "to")
abortion$to <- abortion$to + 1

## computation of the matrix giving the possible transitions
tra <- matrix(FALSE, nrow = 5, ncol = 5)
tra[1:2, 3:5] <- TRUE

## etm
fit <- etm(abortion, as.character(0:4), tra, NULL, s = 0)

## plot
xyplot(fit, tr.choice = c("0 0", "1 1", "0 4", "1 4"),
       ci.fun = c("log-log", "log-log", "cloglog", "cloglog"),
       strip = strip.custom(factor.levels = c("P(T > t) -- control",
                                              "P(T > t) -- exposed",
                                 "CIF spontaneous abortion -- control",
                                 "CIF spontaneous abortion --
exposed")))

Example output

Loading required package: survival
Multistate model with 2 transient state(s)
 and 1 absorbing state(s)

Possible transitions:
 from to
    0  1
    0  2
    1  0
    1  2

Estimate of P(1, 183)
  0 1 2
0 0 0 1
1 0 0 1
2 0 0 1

Estimate of cov(P(1, 183))
    0 0 1 0 2 0 0 1 1 1 2 1           0 2           1 2 2 2
0 0   0   0   0   0   0   0  0.000000e+00  0.000000e+00   0
1 0   0   0   0   0   0   0  0.000000e+00  0.000000e+00   0
2 0   0   0   0   0   0   0  0.000000e+00  0.000000e+00   0
0 1   0   0   0   0   0   0  0.000000e+00  0.000000e+00   0
1 1   0   0   0   0   0   0  0.000000e+00  0.000000e+00   0
2 1   0   0   0   0   0   0  0.000000e+00  0.000000e+00   0
0 2   0   0   0   0   0   0 -2.864030e-20 -1.126554e-19   0
1 2   0   0   0   0   0   0 -4.785736e-20  2.710505e-19   0
2 2   0   0   0   0   0   0  0.000000e+00  0.000000e+00   0
Transition 0 1 
           P  time          var        lower       upper n.risk n.event
 0.000000000   1.5 0.000000e+00 0.0000000000 0.000000000    394       0
 0.043085855  16.0 4.123726e-05 0.0304997025 0.055672007     93       1
 0.015684429  35.0 9.264084e-06 0.0097188944 0.021649963     28       0
 0.006327055  56.0 3.191352e-06 0.0028257059 0.009828405      6       0
 0.002432694  90.0 1.202073e-06 0.0002838081 0.004581581      1       0
 0.000000000 183.0 0.000000e+00 0.0000000000 0.000000000      1       0

Transition 0 2 
         P  time           var     lower     upper n.risk n.event
 0.0000000   1.5  0.000000e+00 0.0000000 0.0000000    394       0
 0.8722513  16.0  1.522153e-04 0.8480701 0.8964324     93       9
 0.9696628  35.0  2.251767e-05 0.9603622 0.9789633     28       2
 0.9912678  56.0  4.666932e-06 0.9870337 0.9955020      6       1
 0.9965950  90.0  1.695084e-06 0.9940432 0.9991468      1       0
 1.0000000 183.0 -2.864030e-20       NaN       NaN      1       1

Transition 1 0 
           P  time          var       lower      upper n.risk n.event
 0.005665722   1.5 1.595927e-05 0.000000000 0.01349559    353       2
 0.152623746  16.0 2.459821e-04 0.121884031 0.18336346    122       3
 0.061280765  35.0 1.357199e-04 0.038447406 0.08411412     38       0
 0.012543433  56.0 3.101462e-05 0.001628242 0.02345862     14       0
 0.005714466  90.0 1.601938e-05 0.000000000 0.01355907      6       1
 0.000000000 183.0 0.000000e+00 0.000000000 0.00000000      0       0

Transition 1 2 
         P  time          var     lower     upper n.risk n.event
 0.0000000   1.5 0.000000e+00 0.0000000 0.0000000    353       0
 0.5539943  16.0 5.407195e-04 0.5084185 0.5995700    122       2
 0.8404230  35.0 3.234473e-04 0.8051738 0.8756723     38       0
 0.9498246  56.0 1.211918e-04 0.9282479 0.9714013     14       1
 0.9798653  90.0 5.376707e-05 0.9654937 0.9942370      6       0
 1.0000000 183.0 2.710505e-19 1.0000000 1.0000000      0       0

Transition 0 0 
            P  time          var        lower       upper n.risk n.event
 1.0000000000   1.5 0.000000e+00 1.0000000000 1.000000000    394       0
 0.0846628663  16.0 9.820209e-05 0.0652402177 0.104085515     93       0
 0.0146528083  35.0 9.980045e-06 0.0084610451 0.020844571     28       0
 0.0024050995  56.0 1.208795e-06 0.0002502133 0.004559986      6       0
 0.0009722893  90.0 4.763549e-07 0.0000000000 0.002325026      1       0
 0.0000000000 183.0 0.000000e+00 0.0000000000 0.000000000      1       0

Transition 1 1 
          P  time          var      lower      upper n.risk n.event
 0.99433428   1.5 1.595927e-05 0.98650441 1.00000000    353       0
 0.29338199  16.0 5.134419e-04 0.24897066 0.33779332    122       0
 0.09829622  35.0 2.218748e-04 0.06910165 0.12749079     38       0
 0.03763200  56.0 9.350774e-05 0.01867926 0.05658473     14       0
 0.01442022  90.0 3.940212e-05 0.00211731 0.02672313      6       0
 0.00000000 183.0 0.000000e+00 0.00000000 0.00000000      0       0

Warning messages:
1: In sqrt(var) : NaNs produced
2: In sqrt(var) : NaNs produced
Loading required package: lattice
Warning messages:
1: In sqrt(var) : NaNs produced
2: In sqrt(var) : NaNs produced

etm documentation built on Sept. 8, 2020, 5:06 p.m.