Title: | Empirical Transition Matrix |
---|---|
Description: | The etm (empirical transition matrix) package permits to estimate the matrix of transition probabilities for any time-inhomogeneous multi-state model with finite state space using the Aalen-Johansen estimator. Functions for data preparation and for displaying are also included (Allignol et al., 2011 <doi:10.18637/jss.v038.i04>). Functionals of the Aalen-Johansen estimator, e.g., excess length-of-stay in an intermediate state, can also be computed (Allignol et al. 2011 <doi:10.1007/s00180-010-0200-x>). |
Authors: | Arthur Allignol [aut], Mark Clements [cre, aut] |
Maintainer: | Arthur Allignol <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.1.2 |
Built: | 2024-11-06 04:57:31 UTC |
Source: | https://github.com/mclements/etm |
Outcomes of pregnancies exposed to coumarin derivatives. The aim is to investigate whether exposition to coumarin derivatives increases the probability of spontaneous abortions. Apart from spontaneous abortion, pregnancy may end in induced abortion or live birth, leading to a competing risks situation. Moreover, data are left-truncated as women usually enter the study several weeks after conception.
data(abortion)
data(abortion)
A data frame with 1186 observations on the following 5 variables.
id
Identification number
entry
Entry times into the cohort
exit
Event times
group
Group. 0: control, 1: exposed to coumarin derivatives
cause
Cause of failure. 1: induced abortion, 2: life birth, 3: spontaneous abortion
Meiester, R. and Schaefer, C (2008). Statistical methods for estimating the probability of spontaneous abortion in observational studies – Analyzing pregnancies exposed to coumarin derivatives. Reproductive Toxicology, 26, 31–35
data(abortion)
data(abortion)
The function estimates the expected change in length of stay (LOS) associated with an intermediate event.
clos(x, aw, ratio, ...) ## S3 method for class 'etm' clos(x, aw = FALSE, ratio = FALSE, ...) ## S3 method for class 'msfit' clos(x, aw = FALSE, ratio = FALSE, cox_model, ...)
clos(x, aw, ratio, ...) ## S3 method for class 'etm' clos(x, aw = FALSE, ratio = FALSE, ...) ## S3 method for class 'msfit' clos(x, aw = FALSE, ratio = FALSE, cox_model, ...)
x |
An object of class |
aw |
Logical. Whether to compute the expected change of LOS using
alternative weighting. Default is |
ratio |
Logical. Compute the ratio of the expected length-of-stay
given instermediate event status instead of a difference. Default
value is |
cox_model |
TODO |
... |
Further arguments |
The approach for evaluating the impact of an intermediate event on the expected change in length of stay is based on Schulgen and Schumacher (1996). They suggested to consider the difference of the expected subsequent stay given infectious status at time s.
Extensions to the methods of Schulgen and Schumacher and the earlier implementation in the changeLOS include the possibility to compute the extra length of stay both for competing endpoints and the more simple case of one absorbing state, as well as the possibility to compute this quantity for left-truncated data.
An object of class clos.etm
with the following components:
e.phi |
Change in length of stay |
phi.case |
Estimates of |
phi.control |
Estimates of |
e.phi2 |
Weighted average of the difference between
|
phi2.case |
Estimates of |
phi2.control |
|
e.phi3 |
Weighted average of the difference between
|
phi3.case |
Estimates of |
phi3.control |
|
weights |
Weights used to compute the weighted averages. |
w.time |
Times at which the weights are computed. |
time |
All transition times. |
e.phi.weights.1 |
Expected change in LOS using |
e.phi.weights.other |
Expected change in LOS using
|
weights.1 |
Weights corresponding to the conditional waiting time in the intial state given one experiences the intermediate event. |
weights.other |
Weights corresponding to the conditional waiting time given one does not experience the intermediate event. |
Arthur Allignol [email protected], Matthias Wangler, Jan Beyersmann
G Schulgen and M Schumacher (1996). Estimation of prolongation of hospital stay attributable to nosocomial infections. Lifetime Data Analysis 2, 219-240.
J Beyersmann, P Gastmeier, H Grundmann, S Baerwolf, C Geffers, M Behnke, H Rueden, and M Schumacher (2006). Use of Multistate Models to Assess Prolongation of Intensive Care Unit Stay Due to Nosocomial Infection. Infection Control and Hospital Epidemiology 27, 493-499.
Allignol A, Schumacher M, Beyersmann J: Estimating summary functionals in multistate models with an application to hospital infection data. Computation Stat, 2011; 26: 181-197.
M Wrangler, J Beyersmann and M Schumacher (2006). changeLOS: An R-package for change in length of hospital stay based on the Aalen-Johansen estimator. R News 6(2), 31–35.
data(los.data) ## putting los.data in the long format my.observ <- prepare.los.data(x=los.data) tra <- matrix(FALSE, 4, 4) tra[1, 2:4] <- TRUE tra[2, 3:4] <- TRUE tr.prob <- etm(my.observ, c("0","1","2","3"), tra, NULL, 0) cLOS <- etm::clos(tr.prob) plot(cLOS) ### Compute bootstrapped SE ## function that performs the bootstrap ## nboot: number of bootstrap samples. Other arguments are as in etm() boot.clos <- function(data, state.names, tra, cens.name, s = 0, nboot) { res <- double(nboot) for (i in seq_len(nboot)) { index <- sample(unique(data$id), replace = TRUE) inds <- new.id <- NULL for (j in seq_along(index)){ ind <- which(data$id == index[j]) new.id <- c(new.id, rep(j, length(ind))) inds <- c(inds, ind) } dboot <- cbind(data[inds, ], new.id) dboot[, which(names(dboot) == "id")] dboot$id <- dboot$new.id tr.prob <- etm(dboot, state.names, tra, cens.name, s, cova = FALSE) res[i] <- etm::clos(tr.prob)$e.phi } res } ## bootstrap se <- sqrt(var(boot.clos(my.observ, c("0","1","2","3"), tra, NULL, 0, nboot = 10)))
data(los.data) ## putting los.data in the long format my.observ <- prepare.los.data(x=los.data) tra <- matrix(FALSE, 4, 4) tra[1, 2:4] <- TRUE tra[2, 3:4] <- TRUE tr.prob <- etm(my.observ, c("0","1","2","3"), tra, NULL, 0) cLOS <- etm::clos(tr.prob) plot(cLOS) ### Compute bootstrapped SE ## function that performs the bootstrap ## nboot: number of bootstrap samples. Other arguments are as in etm() boot.clos <- function(data, state.names, tra, cens.name, s = 0, nboot) { res <- double(nboot) for (i in seq_len(nboot)) { index <- sample(unique(data$id), replace = TRUE) inds <- new.id <- NULL for (j in seq_along(index)){ ind <- which(data$id == index[j]) new.id <- c(new.id, rep(j, length(ind))) inds <- c(inds, ind) } dboot <- cbind(data[inds, ], new.id) dboot[, which(names(dboot) == "id")] dboot$id <- dboot$new.id tr.prob <- etm(dboot, state.names, tra, cens.name, s, cova = FALSE) res[i] <- etm::clos(tr.prob)$e.phi } res } ## bootstrap se <- sqrt(var(boot.clos(my.observ, c("0","1","2","3"), tra, NULL, 0, nboot = 10)))
Pseudo Value Regression for the Extra Length-of-Stay
closPseudo(data, state.names, tra, cens.name, s = 0, formula, na.action, aw = FALSE, ratio = FALSE, ncores = 1, trick_ties = FALSE)
closPseudo(data, state.names, tra, cens.name, s = 0, formula, na.action, aw = FALSE, ratio = FALSE, ncores = 1, trick_ties = FALSE)
data |
data.frame of the form data.frame(id,from,to,time) or (id,from,to,entry,exit)
|
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 |
s |
Starting value for computing the transition probabilities. |
formula |
A formula with the covariates at the right of a
|
na.action |
A function which indicates what should happen when the data contain 'NA's. The default is set by the 'na.action' setting of 'options', and is 'na.fail' if that is unset. The 'factory-fresh' default is 'na.omit'. |
aw |
Logical. Whether to compute the expected change of LOS using
alternative weighting. Default is |
ratio |
Logical. Compute the ratio of the expected length-of-stay
given instermediate event status instead of a difference. Default
value is |
ncores |
Number of cores used if doing parallel computation using the parallel package |
trick_ties |
If |
The function calculates the pseudo-observations for the extra length-of-stay for each individual. These pseudo-observations can then be used to fit a direct regression model using generalized estimating equation (e.g., package geepack).
Computation of the pseudo-observations can be parallelised using the
mclapply
function of the parallel package. See argument
ncores
.
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)
.
An object of class closPseudo
with the following components:
pseudoData |
a data.frame containing |
theta |
Estimates of excess LoS in the whole sample |
aw |
like in the function call |
call |
Function call |
Arthur Allignol [email protected]
Andersen, P.K, Klein, J.P, Rosthoj, S. (2003). Generalised linear models for correlated pseudo-observations, with applications to multi-state models. Biometrika, 90(1):15–27.
if(require("kmi", quietly = TRUE)) { ## data in kmi package data(icu.pneu) my.icu.pneu <- icu.pneu my.icu.pneu <- my.icu.pneu[order(my.icu.pneu$id, my.icu.pneu$start), ] masque <- diff(my.icu.pneu$id) my.icu.pneu$from <- 0 my.icu.pneu$from[c(1, masque) == 0] <- 1 my.icu.pneu$to2 <- my.icu.pneu$event my.icu.pneu$to2[my.icu.pneu$status == 0] <- "cens" my.icu.pneu$to2[c(masque, 1) == 0] <- 1 my.icu.pneu$to <- ifelse(my.icu.pneu$to2 %in% c(2, 3), 2, my.icu.pneu$to2) my.icu.pneu <- my.icu.pneu[, c("id", "start", "stop", "from", "to", "to2", "age", "sex")] names(my.icu.pneu)[c(2, 3)] <- c("entry", "exit") ## computation of the pseudo-observations ## Not run: ps.icu.pneu <- closPseudo(my.icu.pneu, c("0", "1", "2"), tra_ill(), "cens", formula = ~ sex + age) ## regression model using geepack require(geepack) fit <- geeglm(ps.e.phi ~ sex + age, id = id, data = ps.icu.pneu$pseudoData, family = gaussian) summary(fit) ## End(Not run) } else { print("This example requires the kmi package") }
if(require("kmi", quietly = TRUE)) { ## data in kmi package data(icu.pneu) my.icu.pneu <- icu.pneu my.icu.pneu <- my.icu.pneu[order(my.icu.pneu$id, my.icu.pneu$start), ] masque <- diff(my.icu.pneu$id) my.icu.pneu$from <- 0 my.icu.pneu$from[c(1, masque) == 0] <- 1 my.icu.pneu$to2 <- my.icu.pneu$event my.icu.pneu$to2[my.icu.pneu$status == 0] <- "cens" my.icu.pneu$to2[c(masque, 1) == 0] <- 1 my.icu.pneu$to <- ifelse(my.icu.pneu$to2 %in% c(2, 3), 2, my.icu.pneu$to2) my.icu.pneu <- my.icu.pneu[, c("id", "start", "stop", "from", "to", "to2", "age", "sex")] names(my.icu.pneu)[c(2, 3)] <- c("entry", "exit") ## computation of the pseudo-observations ## Not run: ps.icu.pneu <- closPseudo(my.icu.pneu, c("0", "1", "2"), tra_ill(), "cens", formula = ~ sex + age) ## regression model using geepack require(geepack) fit <- geeglm(ps.e.phi ~ sex + age, id = id, data = ps.icu.pneu$pseudoData, family = gaussian) summary(fit) ## End(Not run) } else { print("This example requires the kmi package") }
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.
## 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, ...)
## 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, ...)
data |
data.frame of the form data.frame(id,from,to,time) or (id,from,to,entry,exit)
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 |
s |
Starting value for computing the transition probabilities. |
t |
Ending value. Default is "last", meaning that the transition
probabilities are computed over |
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 |
modif |
Logical. Whether to apply the modification of Lai and Ying for small risk sets |
c |
Constant for the Lai and Ying modification. Either |
alpha |
Constant for the Lai and Ying modification. If NULL (the
default) then only |
strata |
Character vector giving variables on which to stratify the analysis. |
... |
Not used |
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
of I + the matrix of the increments of the
Nelson-Aalen estimates of the cumulative transition hazards. The
entry of the empirical transition matrix
estimates the transition probability of being in state
at
time
given that one has been in state j at time
.
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 at time
(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)
.
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 |
Start of the time interval. |
t |
End of the time interval. |
trans |
A |
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 |
If the analysis is stratified, a list of etm
objects is
returned.
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.
Arthur Allignol, [email protected]
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.
print.etm
, summary.etm
, sir.cont
,
xyplot.etm
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")))
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")))
etmCIF
is a wrapper around the etm
function for
facilitating the computation of the cumulative incidence functions in
the competing risks framework.
etmCIF(formula, data, etype, subset, na.action, failcode = 1)
etmCIF(formula, data, etype, subset, na.action, failcode = 1)
formula |
A |
data |
A data.frame in which to interpret the terms of the formula |
etype |
Competing risks event indicator. When the status
indicator is 1 (or TRUE) in the formula, |
subset |
Expression saying that only a subset of the data should be used. |
na.action |
Missing-data filter function. Default is
|
failcode |
Indicates the failure type of interest. Default is
one. This option is only relevant for some options of the
|
This function computes the cumulative incidence functions in a
competing risks setting using the etm
machinery, without having
to specify the matrix of possible transitions and using the more usual
formula specification with Surv
Returns a list of etm
objects (1 per covariate level) plus
additional informations:
failcode |
As in function call |
call |
Function call |
X |
A matrix giving the name of the covariate (if present) and the levels of this covariate. |
Arthur Allignol [email protected]
etm
, print.etmCIF
,
summary.etmCIF
, plot.etmCIF
data(abortion) cif.ab <- etmCIF(survival::Surv(entry, exit, cause != 0) ~ group, abortion, etype = cause, failcode = 3) cif.ab plot(cif.ab, ci.type = "bars", pos.ci = 24, col = c(1, 2), lty = 1, curvlab = c("Control", "Exposed"))
data(abortion) cif.ab <- etmCIF(survival::Surv(entry, exit, cause != 0) ~ group, abortion, etype = cause, failcode = 3) cif.ab plot(cif.ab, ci.type = "bars", pos.ci = 24, col = c(1, 2), lty = 1, curvlab = c("Control", "Exposed"))
The function transforms a data set in the wide format (i.e., one raw
per subject) into the long format (i.e., one raw per transition, and
possibly several raws per subjects) in a suitable way for using the
etm
function
etmprep(time, status, data, tra, state.names, cens.name = NULL, start = NULL, id = NULL, keep)
etmprep(time, status, data, tra, state.names, cens.name = NULL, start = NULL, id = NULL, keep)
time |
A character vector giving the name of the columns
containing the transition times or last follow-up times. The
length of |
status |
A character vector giving the name of the columns indicating whether a state has been visited (0 if not, 1 otherwise). |
data |
A data frame in which to look for the columns specified in
|
tra |
A quadratic matrix of logical values describing the
possible transitions within the multistate model. The |
state.names |
A vector of characters giving the states names. If missing, state names are set to be 0:(number of states). |
cens.name |
A character string specifying how censored observations will be indicated in the new data set. Default is NULL, i.e., no censored observation. |
start |
A list containing two elements, |
id |
A character string specifying in which column of |
keep |
A character vector indicating the column names of the covariate one might want to keep in the new data.frame. |
This function only works for irreversible acyclic Markov processes.
Therefore, the multistate model will have initial
states, into which no transition are possible. For these, NAs are
allowed in time
and status
.
The function returns a data.frame suitable for using the etm
function. The data frame contains the following components:
id |
Individual id number |
entry |
Entry time into a state |
exit |
Exit time from a state |
from |
State from which a transition occurs |
to |
State into which a transition occurs |
... |
Further columns specified in |
Arthur Allignol, [email protected]
### creation of fake data in the wild format, following an illness-death model ## transition times tdisease <- c(3, 4, 3, 6, 8, 9) tdeath <- c(6, 9, 8, 6, 8, 9) ## transition status stat.disease <- c(1, 1, 1, 0, 0, 0) stat.death <- c(1, 1, 1, 1, 1, 0) ## a covariate that we want to keep in the new data cova <- rbinom(6, 1, 0.5) dat <- data.frame(tdisease, tdeath, stat.disease, stat.death, cova, stringsAsFactors = TRUE) ## Possible transitions tra <- matrix(FALSE, 3, 3) tra[1, 2:3] <- TRUE tra[2, 3] <- TRUE ## data preparation newdat <- etmprep(c(NA, "tdisease", "tdeath"), c(NA, "stat.disease", "stat.death"), data = dat, tra = tra, cens.name = "cens")
### creation of fake data in the wild format, following an illness-death model ## transition times tdisease <- c(3, 4, 3, 6, 8, 9) tdeath <- c(6, 9, 8, 6, 8, 9) ## transition status stat.disease <- c(1, 1, 1, 0, 0, 0) stat.death <- c(1, 1, 1, 1, 1, 0) ## a covariate that we want to keep in the new data cova <- rbinom(6, 1, 0.5) dat <- data.frame(tdisease, tdeath, stat.disease, stat.death, cova, stringsAsFactors = TRUE) ## Possible transitions tra <- matrix(FALSE, 3, 3) tra[1, 2:3] <- TRUE tra[2, 3] <- TRUE ## data preparation newdat <- etmprep(c(NA, "tdisease", "tdeath"), c(NA, "stat.disease", "stat.death"), data = dat, tra = tra, cens.name = "cens")
Data from the placebo group of the 4D study. This study aimed at comparing atorvastatin to placebo for patients with type 2 diabetes and receiving hemodialysis in terms of cariovascular events. The primary endpoint was a composite of death from cardiac causes, stroke and non-fatal myocardial infarction. Competing event was death from other causes.
data(fourD)
data(fourD)
A data frame with 636 observations on the following 7 variables.
id
Patients' id number
sex
Patients' gender
age
Patients' age
medication
Character vector indicating treatment
affiliation. Here only equal to "Placebo"
status
Status at the end of the follow-up. 1 for the event of interest, 2 for death from other causes and 0 for censored observations
time
Survival time
treated
Numeric vector indicated whether patients are treated or not. Here always equal to zero
Wanner, C., Krane, V., Maerz, W., Olschewski, M., Mann, J., Ruf, G., Ritz, E (2005). Atorvastatin in patients with type 2 diabetes mellitus undergoing hemodialysis. New England Journal of Medicine, 353(3), 238–248.
Allignol, A., Schumacher, M., Wanner, C., Dreschler, C. and Beyersmann, J. (2010). Understanding competing risks: a simulation point of view. Research report.
data(fourD)
data(fourD)
Lines method for etm
objects
## S3 method for class 'etm' lines(x, tr.choice, col = 1, lty, conf.int = FALSE, level = 0.95, ci.fun = "linear", ci.col = col, ci.lty = 3, ...)
## S3 method for class 'etm' lines(x, tr.choice, col = 1, lty, conf.int = FALSE, level = 0.95, ci.fun = "linear", ci.col = col, ci.lty = 3, ...)
x |
An object of class |
tr.choice |
character vector of the form |
col |
Vector of colours. Default is black. |
lty |
Vector of line type. Default is 1:number of transitions |
conf.int |
Logical specifying whether to plot confidence intervals. Default is FALSE. |
level |
Level of the confidence interval. Default is 0.95. |
ci.fun |
Transformation applied to the confidence intervals. It
could be different for all transition probabilities, though if
|
ci.col |
Colours of the confidence intervals. Default value is
the same as |
ci.lty |
Line types for the confidence intervals. Default is 3. |
... |
Further arguments for |
No value returned.
Arthur Allignol, [email protected]
The los.data
data frame has 756 rows, one row for
each patient, and 7 columns.
data(los.data)
data(los.data)
A data frame with the following columns:
admision id of the patient
observed time for jump from 0 (initial state) to 1 (intermediate state)
observed time for jump from 0 to 2 (discharge)
observed time for jump from 0 to 3 (death)
observed time for jump from 1 to 2
observed time for jump from 1 to 3
censoring time (either in initial or intermediate state)
data(los.data) my.data <- prepare.los.data(los.data)
data(los.data) my.data <- prepare.los.data(los.data)
Plot method for objects of class clos.etm
.
## S3 method for class 'clos.etm' plot(x, xlab = "Time", ylab.e = "Expected LOS", ylab.w = "Weights", xlim, ylim.e, ylim.w, col.e = c(1, 2), col.w = 1, lty.e = c(1, 1), lty.w = 1, legend = TRUE, legend.pos, curvlab, legend.bty = "n", ...)
## S3 method for class 'clos.etm' plot(x, xlab = "Time", ylab.e = "Expected LOS", ylab.w = "Weights", xlim, ylim.e, ylim.w, col.e = c(1, 2), col.w = 1, lty.e = c(1, 1), lty.w = 1, legend = TRUE, legend.pos, curvlab, legend.bty = "n", ...)
x |
An object of class |
xlab |
Label for the x-axis |
ylab.e |
Label for the y-axis in the plot of the expected LOS |
ylab.w |
Label for the y-axis in the plot of the weights |
xlim |
Limits of x-axis for the plots |
ylim.e |
Limits of the y-axis for the expected LOS plot |
ylim.w |
Limits of the y-axis for the weights plot |
col.e |
Vector of colours for the plot of expected LOS |
col.w |
Vector of colours for the plot of the weights |
lty.e |
Vector of line type for the plot of expected LOS |
lty.w |
Vector of line type for the plot of the weights |
legend |
Logical. Whether to draw a legend for the plot of expected LOS |
legend.pos |
A vector giving the legend's position. See
|
curvlab |
Character or expression vector to appear in the
legend. Default is |
legend.bty |
Box type for the legend |
... |
Further arguments for plot |
Two graphs are drawn. The lower graph displays the expected LOS for patients who have experienced the intermediate event and for those who have not. The upper graph displays the weights used to compute the weighted average.
No value returned
Arthur Allignol [email protected], Matthias Wangler
Plot method for an object of class 'etm'. It draws the estimated transition probabilities in a basic scatterplot.
## S3 method for class 'etm' plot(x, tr.choice, xlab = "Time", ylab = "Transition Probability", col = 1, lty, xlim, ylim, conf.int = FALSE, level = 0.95, ci.fun = "linear", ci.col = col, ci.lty = 3, legend = TRUE, legend.pos, curvlab, legend.bty = "n", ...)
## S3 method for class 'etm' plot(x, tr.choice, xlab = "Time", ylab = "Transition Probability", col = 1, lty, xlim, ylim, conf.int = FALSE, level = 0.95, ci.fun = "linear", ci.col = col, ci.lty = 3, legend = TRUE, legend.pos, curvlab, legend.bty = "n", ...)
x |
An object of class 'etm' |
tr.choice |
character vector of the form 'c("from to","from to")' specifying which transitions should be plotted. Default, all the transition probabilities are plotted |
xlab |
x-axis label. Default is "Time" |
ylab |
y-axis label. Default is "Transition Probability" |
col |
Vector of colour. Default is black |
lty |
Vector of line type. Default is 1:number of transitions |
xlim |
Limits of x-axis for the plot |
ylim |
Limits of y-axis for the plot |
conf.int |
Logical. Whether to display pointwise confidence intervals. Default is FALSE. |
level |
Level of the conficence intervals. Default is 0.95. |
ci.fun |
Transformation applied to the confidence intervals. It
could be different for all transition probabilities, though if
|
ci.col |
Colour of the confidence intervals. Default is
|
ci.lty |
Line type of the confidence intervals. Default is 3. |
legend |
A logical specifying if a legend should be added |
legend.pos |
A vector giving the legend's position. See
|
curvlab |
A character or expression vector to appear in the legend. Default is the name of the transitions |
legend.bty |
Box type for the legend |
... |
Further arguments for plot |
By default, if the argument strata
was used for creating the etm
object, the first transition probability for all strata will be
plotted. If there is no strata, all transition probabilities are
plotted by default.
In any case, a legend with be created by the labels are likely to be
ugly. Please use the curvlab
argument to control the test or
use legend = FALSE
and build your own legend.
No value returned
Arthur Allignol, [email protected]
data(sir.cont) # Modification for patients entering and leaving a state # at the same date 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 } } } tra <- matrix(ncol=3,nrow=3,FALSE) tra[1, 2:3] <- TRUE tra[2, c(1, 3)] <- TRUE my.etm <- etm(sir.cont,c("0","1","2"),tra,"cens", s = 0) plot(my.etm, tr.choice = c("0 0"))
data(sir.cont) # Modification for patients entering and leaving a state # at the same date 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 } } } tra <- matrix(ncol=3,nrow=3,FALSE) tra[1, 2:3] <- TRUE tra[2, c(1, 3)] <- TRUE my.etm <- etm(sir.cont,c("0","1","2"),tra,"cens", s = 0) plot(my.etm, tr.choice = c("0 0"))
Plot function for etmCIF
objects. The function plots cumulative
incidence curves, possibly with pointwise confidence intervals.
## S3 method for class 'etmCIF' plot(x, which.cif, xlim, ylim, ylab = "Cumulative Incidence", xlab = "Time", col = 1, lty, lwd = 1, ci.type = c("none", "bars", "pointwise"), ci.fun = "cloglog", ci.col = col, ci.lty = 3, legend = TRUE, legend.pos, curvlab, legend.bty = "n", pos.ci = 27, ci.lwd = 3, ...)
## S3 method for class 'etmCIF' plot(x, which.cif, xlim, ylim, ylab = "Cumulative Incidence", xlab = "Time", col = 1, lty, lwd = 1, ci.type = c("none", "bars", "pointwise"), ci.fun = "cloglog", ci.col = col, ci.lty = 3, legend = TRUE, legend.pos, curvlab, legend.bty = "n", pos.ci = 27, ci.lwd = 3, ...)
x |
A |
which.cif |
A numeric vector indicating which CIFs should be
plotted. When missing, only the CIF of interest is plotted
(determined through the |
xlim |
x-axis limits for the plot. By default, |
ylim |
y-axis limits. Default is |
ylab |
Label for y-axis. Default is |
xlab |
Label for x-axis. Default is "Time" |
col |
Vector describing colours used for the CIF curves. Default is black |
lty |
Vector of line type |
lwd |
Thickness of the lines |
ci.type |
One of |
ci.fun |
Transformation used for the confidence intervals. Default is "clolog", and is a better choice for cumulative incidences. Other choices are "log" and "log-log" |
ci.col |
Colour for the pointwise confidence interval curves. Default is same as the CIF curves |
ci.lty |
Line type for the confidence intervals. Default is 3 |
legend |
Logical. Whether to draw a legend. Default is |
legend.pos |
A vector giving the legend's position. See
|
curvlab |
A character or expression vector to appear in the legend. Default is CIF + event label |
legend.bty |
Box type for the legend. Default is none ("n") |
pos.ci |
If |
ci.lwd |
Thickness of the confidence interval segment (for
|
... |
Further graphical arguments |
The function relies on plot.etm
and lines.etm
with more
or less the same options. Exception is the drawing of the confidence
intervals, for which several displays are possible.
No value returned
Arthur Allignol [email protected]
data(abortion) cif.ab <- etmCIF(survival::Surv(entry, exit, cause != 0) ~ group, abortion, etype = cause, failcode = 3) cif.ab plot(cif.ab, ci.type = "bars", pos.ci = 24, col = c(1, 2), lty = 1, curvlab = c("Control", "Exposed")) plot(cif.ab, which = c(1, 2))
data(abortion) cif.ab <- etmCIF(survival::Surv(entry, exit, cause != 0) ~ group, abortion, etype = cause, failcode = 3) cif.ab plot(cif.ab, ci.type = "bars", pos.ci = 24, col = c(1, 2), lty = 1, curvlab = c("Control", "Exposed")) plot(cif.ab, which = c(1, 2))
Prepare data to be passed to clos() in package etm.
prepare.los.data(x)
prepare.los.data(x)
x |
data.frame of the form data.frame(id, j.01, j.02, j.03, j.12, j.13, cens):
|
a data.frame of the form data.frame(id, from, to, time, oid):
id: |
id (patient id, admision id) |
from: |
the state from where a transition occurs |
to: |
the state to which a transition occurs |
time: |
time of the transition |
oid: |
the observation id |
Matthias Wangler
data(los.data) my.observ <- prepare.los.data(x=los.data)
data(los.data) my.observ <- prepare.los.data(x=los.data)
Print method for object of class clos.etm
## S3 method for class 'clos.etm' print(x, ...)
## S3 method for class 'clos.etm' print(x, ...)
x |
An object of class |
... |
Further arguments |
No value returned
Arthur Allignol, [email protected]
Print method for objects of class etm
.
## S3 method for class 'etm' print(x, covariance = FALSE, whole = TRUE, ...)
## S3 method for class 'etm' print(x, covariance = FALSE, whole = TRUE, ...)
x |
An object of class |
covariance |
Whether print the covariance matrix. Default is TRUE |
whole |
Whether to plot the entire covariance matrix. If set to FALSE, rows and columns containing only 0 will be removed for printing. |
... |
Further arguments for print or summary. |
The function prints a matrix giving the possible transitions, along
with the estimates of and
.
No value returned
Arthur Allignol, [email protected]
cifETM
objects
Print method for cifETM
objects
## S3 method for class 'etmCIF' print(x, ...)
## S3 method for class 'etmCIF' print(x, ...)
x |
An object of class |
... |
Further arguments |
No value returned
Arthur Allignol [email protected]
Time-dependent ventilation status for intensive care unit (ICU) patients, a random sample from the SIR-3 study.
data(sir.cont)
data(sir.cont)
A data frame with 1141 rows and 6 columns:
Randomly generated patient id
State from which a transition occurs
State to which a transition occurs
Time when a transition occurs
Age at inclusion
Sex. F
for female and M
for male
The possible states are:
0: No ventilation
1: Ventilation
2: End of stay
And cens
stands for censored observations.
This data frame consists in a random sample of the SIR-3 cohort data. It focuses on the effect of ventilation on the length of stay (combined endpoint discharge/death). Ventilation status is considered as a transcient state in an illness-death model.
The data frame is directly formated to be used with the etm
function, i.e. it is transition-oriented with one row per transition.
Beyersmann, J., Gastmeier, P., Grundmann, H., Baerwolff, S., Geffers, C., Behnke, M., Rueden, H., and Schumacher, M. Use of multistate models to assess prolongation of intensive care unit stay due to nosocomial infection. Infection Control and Hospital Epidemiology, 27:493-499, 2006.
data(sir.cont)
data(sir.cont)
Summary method for objects of class etm
## S3 method for class 'etm' summary(object, tr.choice, ci.fun = "linear", level = 0.95, times, ...) ## S3 method for class 'summary.etm' print(x, ...)
## S3 method for class 'etm' summary(object, tr.choice, ci.fun = "linear", level = 0.95, times, ...) ## S3 method for class 'summary.etm' print(x, ...)
object |
An object of class |
tr.choice |
Character vector of the form 'c("from to","from to")' specifying which transitions should be summarized. Default to all the transition probabilities |
ci.fun |
A character vector specifying the transformation to be
applied to the pointwise confidence intervals. It could be different
for each transition probability, though if |
level |
Level of the two-sided confidence intervals. Default is 0.95. |
x |
A |
times |
Time points for which estimates should be returned. Default to all transition times. |
... |
Further arguments |
A list of data.frames giving the transition probability and stage occupation probability estimates. List items are named after the possible transition.
P |
Transition probability estimates |
var |
Variance estimates |
lower |
Lower confidence limit |
upper |
Upper confidence limit |
time |
Transition times |
n.risk |
Number of individuals at risk of experiencing a transition
just before time |
n.event |
Number of events at time |
Arthur Allignol [email protected]
Summary function for objects of class cifETM
## S3 method for class 'etmCIF' summary(object, ci.fun = "cloglog", level = 0.95, ...) ## S3 method for class 'summary.etmCIF' print(x, ...)
## S3 method for class 'etmCIF' summary(object, ci.fun = "cloglog", level = 0.95, ...) ## S3 method for class 'summary.etmCIF' print(x, ...)
object |
An object of class |
ci.fun |
Transformation applied to the pointwise confidence
intervals. On of |
level |
Level of the confidence intervals. Default is 0.95. |
x |
An object of class |
... |
Further arguments |
A data.frame per covariate level and competing event
P |
Transition probability estimates |
var |
Variance estimates |
lower |
Lower confidence limit |
upper |
Upper confidence limit |
time |
Transition times |
n.risk |
Number of individuals at risk of experiencing a transition
just before time |
n.event |
Number of events at time |
Arthur Allignol [email protected]
Miscellaneous functions that compute the matrix of possible
transitions used as argument in the etm
function.
tra_ill(state.names = c("0", "1", "2")) tra_ill_comp(nComp = 2, state.names = as.character(seq(0, nComp + 1, 1))) tra_comp(nComp = 2, state.names = as.character(seq(0, nComp))) tra_surv(state.names = c("0", "1"))
tra_ill(state.names = c("0", "1", "2")) tra_ill_comp(nComp = 2, state.names = as.character(seq(0, nComp + 1, 1))) tra_comp(nComp = 2, state.names = as.character(seq(0, nComp))) tra_surv(state.names = c("0", "1"))
state.names |
A vector of characters giving the states names |
nComp |
For the competing risks models, the number of competing events |
These functions compute the matrix of possible transitions that is
used as argument in, e.g., the etm
function. tra_surv
is
for the usual survival model, tra_comp
for the competing risks
model, tra_ill
for the illness-death model and
tra_ill_comp
for the illness-death model with competing
terminal events. By default, state names are from 0 to ...
A quadratic matrix with TRUE
if a transition is possible,
FALSE
otherwise.
Arthur Allignol [email protected]
tra_ill() ## competing risks model with 4 competing events non-default state names tra_comp(4, state.names = c("healthy", "Cardiac problems", "Cancer", "Rhenal failure", "Other"))
tra_ill() ## competing risks model with 4 competing events non-default state names tra_comp(4, state.names = c("healthy", "Cardiac problems", "Cancer", "Rhenal failure", "Other"))
The trprob
method is used to extract transition probabilities,
while trcov
is used to obtain the (co)variance.
## S3 method for class 'etm' trprob(x, tr.choice, timepoints, ...) ## S3 method for class 'etm' trcov(x, tr.choice, timepoints, ...)
## S3 method for class 'etm' trprob(x, tr.choice, timepoints, ...) ## S3 method for class 'etm' trcov(x, tr.choice, timepoints, ...)
x |
An object of class |
tr.choice |
A character vector of the form "from to" describing
for which transition one wishes to obtain the transition probabilities
or covariance estimates. For |
timepoints |
Time points at which one want the estimates. When missing, estimates are obtained for all event times. |
... |
Further arguments. |
A vector containing the transition probabilities or covariance
estimates either at the time specified in timepoints
or at all
transition times.
Arthur Allignol, [email protected]
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 fit.etm <- etm(sir.cont, c("0", "1", "2"), tra, "cens", 0) ## extract P_01(0, t) and variance p01 <- trprob(fit.etm, "0 1") var.p01 <- trcov(fit.etm, "0 1") ## covariance between P_00 and P_01 cov.00.01 <- trcov(fit.etm, c("0 0", "0 1")) ## P_01 at some time points trprob(fit.etm, "0 1", c(0, 15, 50, 100))
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 fit.etm <- etm(sir.cont, c("0", "1", "2"), tra, "cens", 0) ## extract P_01(0, t) and variance p01 <- trprob(fit.etm, "0 1") var.p01 <- trcov(fit.etm, "0 1") ## covariance between P_00 and P_01 cov.00.01 <- trcov(fit.etm, c("0 0", "0 1")) ## P_01 at some time points trprob(fit.etm, "0 1", c(0, 15, 50, 100))
xyplot function for objects of class etm
. Estimates of the
transition probabilities are plotted as a function of time for all the
transitions specified by the user.
## S3 method for class 'etm' xyplot(x, data = NULL, tr.choice, col = c(1, 1, 1), lty = c(1, 3, 3), xlab = "Time", ylab = "Transition probability", conf.int = TRUE, ci.fun = "linear", level = 0.95, ...)
## S3 method for class 'etm' xyplot(x, data = NULL, tr.choice, col = c(1, 1, 1), lty = c(1, 3, 3), xlab = "Time", ylab = "Transition probability", conf.int = TRUE, ci.fun = "linear", level = 0.95, ...)
x |
An object of class |
data |
Useless. |
tr.choice |
A character vector of the form c("from to", "from to", ...) specifying the transition probabilities to be plotted. By default, all the direct transition probabilities are displayed. |
col |
Vector of colours for the curves. |
lty |
Vector of line types. |
xlab |
x-axis label. Default is "Time". |
ylab |
y-axis label. Default is "Estimated transition probability". |
conf.int |
Logical. Whether to draw pointwise confidence intervals. Default is TRUE. |
ci.fun |
A character vector specifying the transformation to be
applied to the pointwise confidence intervals. It could be different
for each transition probability, though if |
level |
Level of the two-sided confidence intervals. Default is 0.95. |
... |
Further arguments for |
An object of class trellis
.
Arthur Allignol, [email protected]