etmprep {etm} | R Documentation |
Data transformation function for using etm
Description
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
Usage
etmprep(time, status, data, tra, state.names, cens.name = NULL,
start = NULL, id = NULL, keep)
Arguments
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. |
Details
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
.
Value
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 |
Author(s)
Arthur Allignol, arthur.allignol@gmail.com
See Also
Examples
### 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")