Description Usage Arguments Value References See Also Examples
Censoring patient initiating the other arm treatment and building a treatment censoring indicator cens
1 2 3 4 5 6 7 8 9 10 11 12 |
data |
a dataframe containing the following variables |
id |
the patient's id |
tstart |
the date of the beginning of the follow-up (in numeric format) |
tstop |
the date of the end of the follow-up (in numeric format) |
event |
the indicator of failure (a death is denoted by 1 at the end of the follow-up) |
censTime |
the chosen time to censor the patients (in numeric format) |
arm |
the randomized treatment (2-levels factor) |
realtrt |
the randomized treatment (2-levels factor) |
trt.start |
the time of initiation of the randomized treatment (NULL by default) |
trt.stop |
the time of termination of the randomized treatment (NULL by default) |
a dataframe in the long format, with the data being censored according to the input date, censTime. a treatment censoring indicator, cens, is thus added to the previous dataset to indicate such a switch. Note that this function provides the option to include in the data the treatment really taken with the corresponding dates. Then, the treatment really taken is a 3-levels factor, i.e., the two from the randomized arms and a third indicating the no-treatment case (None).
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"
SHIdat
, timesTokeep
, wideToLongTDC
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 | # 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]])
# Put dates in numeric format with tstart at 0
toy.long$tstart <- as.numeric(toy.long$tstart)
toy.long$tstop <- as.numeric(toy.long$tstop)
toy.long$swtrtdt <- as.numeric(toy.long$swtrtdt)
tabi <- split(toy.long, toy.long$id)
L.tabi <- length(tabi)
tablist <- lapply(1:L.tabi, function(i){
refstart <- tabi[[i]]$tstart[1]
tabi[[i]]$tstart <- tabi[[i]]$tstart - refstart
tabi[[i]]$tstop <- tabi[[i]]$tstop - refstart
tabi[[i]]$swtrtdt <- tabi[[i]]$swtrtdt - refstart
return(tabi[[i]])
})
toy.long <- do.call( rbind, tablist )
# Patients are censored when initiating the other arm treatment, that is, at time swtrtdt
toy.long2 <- cens.ipw(toy.long, id = "id", tstart = "tstart", tstop = "tstop",
event = "event", arm = "arm",
realtrt = FALSE, censTime ="swtrtdt")
# Before censoring:
toy.long
# Ater censoring:
toy.long2
|
Loading required package: survival
id tstart tstop event age arm swtrtdt TDconf
1 1 0 49 1 20 A 48 0
2 2 0 38 0 50 B NA 1
3 2 38 41 1 50 B NA 2
4 3 0 227 0 40 A NA 0
5 3 227 229 0 40 A NA 1
id tstart tstop event age arm swtrtdt TDconf cens
1 1 0 48 0 20 A 48 0 1
2 2 0 38 0 50 B NA 1 0
3 2 38 41 1 50 B NA 2 0
4 3 0 227 0 40 A NA 0 0
5 3 227 229 0 40 A NA 1 0
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.