replicRows: Function to replicate the rows so that each patients'...

Description Usage Arguments Value References See Also Examples

Description

Function to replicate the rows so that each patients' follow-up is split according to all event times (death for both arms and treatment censoring according to the trt arm) up to each patient's end time

Usage

1
replicRows(data, tstart, tstop, event, cens, times1, times2, arm)

Arguments

data

a dataframe containing the following variables

tstart

the date of the beginning of the follow-up (in numeric format, with the first being equal at 0)

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)

cens

the indicator of treatment censoring (denoted by 1 at the end of the follow-up)

times1

a vector of times (in numeric format) indicating the times according to which the rows have to be split for patients in the first arm

times2

a vector of times (in numeric format) indicating the times according to which the rows have to be split for patients in the second arm

arm

the randomized treatment (2-levels factor)

Value

a formatted dataframe with the rows replicated according to the provided times parameter

References

Graffeo, N., Latouche, A., Le Tourneau C., Chevret, S. "An R Package for IPCW: Application to switches in clinical trials" (submitted)

See Also

cens.ipw, SHIdat, timesTokeep, wideToLongTDC

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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")
# We collect all event times 
# (death for both arms and treatment censoring according to the trt arm)
rep.times1 <- unique(c(toy.long2$tstop[toy.long2$cens==1 & toy.long2$arm == "A"],
                       toy.long2$tstop[toy.long2$event==1]))
rep.times2 <- unique(c(toy.long2$tstop[toy.long2$cens==1 & toy.long2$arm == "B"],
                       toy.long2$tstop[toy.long2$event==1]))
# to put times in same order as arms levels
levels(toy.long2[, "arm"])
# Now, we can replicate the rows
toy.rep   <- replicRows(toy.long2, tstart = "tstart", tstop = "tstop",
                        event = "event", cens = "cens", 
                        times1 = rep.times1, times2 = rep.times2,
                        arm = "arm")
(toy.rep  <- toy.rep[order(toy.rep$id), ])

ipcwswitch documentation built on May 16, 2019, 1:12 a.m.