## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>",
                      fig.width = 7, fig.height = 3.6)

## -----------------------------------------------------------------------------
library(BMeRL)

## -----------------------------------------------------------------------------
head(complete, 3)
head(censored, 3)
table(complete$disease)

## -----------------------------------------------------------------------------
BMeRL_Complete(x1 = c(0, 5, 10), x2 = c(0, 5, 5),
               dataset = complete, time1 = time1, time2 = time2,
               SCI = FALSE)

## -----------------------------------------------------------------------------
beyond <- subset(complete, time1 > 5 & time2 > 5)
N <- nrow(beyond)
N

## -----------------------------------------------------------------------------
Y <- sort(beyond$time1 - 5)
t_le <- Y[ceiling(N / 2)]
t_lt <- Y[floor(N / 2) + 1]
c(t_le = t_le, t_lt = t_lt, q1 = (t_le + t_lt) / 2)

## -----------------------------------------------------------------------------
c(q1 = median(beyond$time1) - 5, q2 = median(beyond$time2) - 5)

## -----------------------------------------------------------------------------
out <- BMeRL_Complete(c(0, 5), c(0, 5), complete, time1, time2,
                      B = 200, seed = 1, verbose = FALSE)
out

## -----------------------------------------------------------------------------
BMeRL_Censored(c(0, 5, 10), c(0, 5, 5), censored,
               time1, time2, status1, status2)

## -----------------------------------------------------------------------------
all_events <- transform(complete, status1 = 1, status2 = 1)
fit_cens <- BMeRL_Censored(c(0, 5, 10), c(0, 5, 5), all_events,
                           time1, time2, status1, status2)
fit_comp <- BMeRL_Complete(c(0, 5, 10), c(0, 5, 5), complete,
                           time1, time2, SCI = FALSE)
all.equal(fit_cens[, c("q1", "q2")], fit_comp[, c("q1", "q2")])

## -----------------------------------------------------------------------------
beyond_c <- subset(censored, time1 > 5 & time2 > 5)
c(naive_q1 = median(beyond_c$time1) - 5,
  naive_q2 = median(beyond_c$time2) - 5)

## -----------------------------------------------------------------------------
BMeRL_Censored(c(0, 5), c(0, 5), censored, time1, time2,
               status1, status2, SCI = TRUE, B = 200, seed = 1,
               verbose = FALSE)

## -----------------------------------------------------------------------------
est <- BMeRL_Complete_ordered(c(0, 5, 20), c(0, 5, 1), complete,
                              time1, time2, disease, smaller = "Yes",
                              SCI = FALSE)
est

## -----------------------------------------------------------------------------
attr(est, "unrestricted")

## -----------------------------------------------------------------------------
BMeRL_Censored_ordered(c(0, 5), c(0, 5), censored, time1, time2,
                       status1, status2, disease, smaller = "Yes",
                       B = 200, seed = 1, verbose = FALSE)

## -----------------------------------------------------------------------------
BMeRL_Surface_complete(complete, time1, time2,
                       x1.grid = 0:30, x2.grid = 0:30)

## -----------------------------------------------------------------------------
BMeRL_Surface_censored(censored, time1, time2, status1, status2,
                       x1.grid = 0:30, x2.grid = 0:30)

## ----fig.height = 7-----------------------------------------------------------
BMeRL_Surface_complete_ordered(complete, time1, time2, disease, "Yes",
                               x1.grid = 0:30, x2.grid = 0:30)

## ----fig.height = 7-----------------------------------------------------------
BMeRL_Surface_censored_ordered(censored, time1, time2, status1,
                               status2, disease, "Yes",
                               x1.grid = 0:30, x2.grid = 0:30)

