wideToLongTDC {ipcwswitch} | R Documentation |
Function from wide to long format
Description
Function from wide to long format
Usage
wideToLongTDC(
data,
id,
tstart,
tstop,
event,
bas.cov,
mes.cov,
time.cov,
times
)
Arguments
data |
a dataframe containing the variables id, tstart, tstop, mes.cov and time.cov |
id |
the patient's id |
tstart |
date of the beginning of the follow-up (in Date format) |
tstop |
date of the end of the follow-up (in Date format) |
event |
the indicator of failure (a death is denoted by 1 at the end of the follow-up) |
bas.cov |
a vector containing the names (in character format) of the baseline covariates |
mes.cov |
a list of vectors, each of them must contain the names (in character format) of the repeated measurements related to one time-dependent covariate |
time.cov |
a list of vectors, each of them must contain the times (in Date format) of the date when the abovementioned measurements were done |
times |
a list of vectors. Each of them must contain, for each patient, the event time and the times of changes in time-varying covariates |
Value
the long format version of the initial dataframe data. The repeated values included in each vector of the list mes.cov are aggregated in a variable named aas the name of the corresponding list member.
References
Graffeo, N., Latouche, A., Le Tourneau C., Chevret, S. (2019) "ipcwswitch: an R package for inverse probability of censoring weighting with an application to switches in clinical trials". Computers in biology and medicine, 111, 103339. doi : "10.1016/j.compbiomed.2019.103339"
See Also
Examples
# To obtain the times parameter, we can apply the timesTokeep function on the same
# dataframe in the wide format
kept.t <- timesTokeep(toydata, id = "id",
tstart = "randt", tstop = "lastdt",
mes.cov = list(c("ps1", "ps2", "ps3")),
time.cov = list(c("randt", "dt2", "dt3")))
# Now, we can build the long format
toy.long <- wideToLongTDC(data = toydata, id = "id",
tstart = "randt", tstop = "lastdt", event = "status",
bas.cov = c("age", "arm", "swtrtdt"),
mes.cov = list(TDconf = c("ps1", "ps2", "ps3")),
time.cov = list(c("randt", "dt2", "dt3")),
times = kept.t[[1]])
toy.long