LOSboot.plot.wide: Length of stay bootstrap plot with envelope bounds for "old"...

Usage Arguments Author(s) See Also Examples

View source: R/LOSbootplotfn.R

Usage

1
LOSboot.plot.wide(data.wide, rlstns = 20, est = "mean")

Arguments

data.wide

wide format of time to event data

rlstns

number of bootstrap realisations

est

estimator type, either mean or median

Author(s)

N Green

See Also

LOSboot.plot

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (data.wide, rlstns = 20, est = "mean") 
{
    cases.inf <- data.wide$j.01 != Inf
    cases.mix <- data.wide$j.01 == Inf
    ninf <- sum(cases.inf)
    nmix <- sum(cases.mix)
    tra <- matrix(FALSE, 3, 3, dimnames = list(as.character(0:2), 
        as.character(0:2)))
    tra[1, 2:3] <- TRUE
    tra[2, 3] <- TRUE
    cLOS <- NULL
    datalist.inf <- datalist.mix <- list()
    clos.data.orig <- cLOS(my.data = data.wide)
    for (k in 1:rlstns) {
        sample.mix.new <- data.wide[cases.mix, ][sample(nmix, 
            replace = T), ]
        sample.inf.new <- data.wide[cases.inf, ][sample(ninf, 
            replace = T), ]
        data.wide.new <- rbind(sample.mix.new, sample.inf.new)
        clos.data <- cLOS(my.data = data.wide.new)
        names(clos.data) <- c("e.phi", "e.phi.med", "times", 
            "phi.case", "phi.control", "phi.case.med", "phi.control.med", 
            "weights", "matrices")
        if (est == "median") {
            cLOS[k] <- clos.data$e.phi.med
            datalist.inf[[k]] <- cbind(time = clos.data$time, 
                phi = clos.data$phi.case.med, infstatus = 1)
            datalist.mix[[k]] <- cbind(time = clos.data$time, 
                phi = clos.data$phi.control.med, infstatus = 0)
        }
        if (est == "mean") {
            cLOS[k] <- clos.data$e.phi
            datalist.inf[[k]] <- cbind(time = clos.data$time, 
                phi = clos.data$phi.case, infstatus = 1)
            datalist.mix[[k]] <- cbind(time = clos.data$time, 
                phi = clos.data$phi.control, infstatus = 0)
        }
    }
    data.inf <- Reduce(function(x, y) merge(x, y, by = c("time", 
        "infstatus")), datalist.inf)
    data.mix <- Reduce(function(x, y) merge(x, y, by = c("time", 
        "infstatus")), datalist.mix)
    data.inf <- data.inf[order(data.inf$time), ]
    data.mix <- data.mix[order(data.mix$time), ]
    data <- rbind(data.inf, data.mix)
    cols <- 2 + (1:rlstns)
    maxtime <- 500
    data.all <- cbind(data[data$time < maxtime, c(1, 2)], LOS = apply(data[data$time < 
        maxtime, cols], 1, mean), LOS.lo = apply(data[data$time < 
        maxtime, cols], 1, mean) - 1.96 * apply(data[data$time < 
        maxtime, cols], 1, sd), LOS.hi = apply(data[data$time < 
        maxtime, cols], 1, mean) + 1.96 * apply(data[data$time < 
        maxtime, cols], 1, sd))
    data.all <- cbind(data.all, Status = as.factor(data.all$infstatus))
    x11()
    ggplot(data = data.all, aes(x = time, y = LOS, ymin = LOS.lo, 
        ymax = LOS.hi, fill = Status, linetype = Status)) + geom_line() + 
        geom_ribbon(alpha = 0.4) + ylim(0, 75)
  }

n8thangreen/HESmanip documentation built on March 21, 2020, 12:20 a.m.