etmprep: Data transformation function for using etm

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

View source: R/transfoData.R

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

1
2
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 time have to be equal to the number of states, some elements may be NA. See Details.

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 time and status.

tra

A quadratic matrix of logical values describing the possible transitions within the multistate model. The (i, j)th element of tra is TRUE if a transition from state i to state j is possible, FALSE otherwise. The diagonal must be set to FALSE.

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, state and time, giving the starting states and times for all individuals. Default is NULL, in which case all individuals are considered to start in the initial state at time 0.

id

A character string specifying in which column of data the user ids are. Default is NULL, and the ids will be 1:n.

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 keep

Author(s)

Arthur Allignol, arthur.allignol@gmail.com

See Also

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
### 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")

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