## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  eval = identical(Sys.getenv("IN_PKGDOWN"), "true") && identical(Sys.getenv("GITHUB_ACTIONS"), "true")
)
data.table::setDTthreads(2)

## ----setup--------------------------------------------------------------------
# library(SEQTaRget)

## -----------------------------------------------------------------------------
# options <- SEQopts(end_of_fup = TRUE,
#                    # evaluate the outcome 12 follow-up periods after enrollment
#                    end_of_fup.time = 12,
#                    # "binary" reports a proportion, "continuous" a mean
#                    end_of_fup.type = "binary",
#                    bootstrap = TRUE,
#                    # fixes the bootstrap resamples, so the intervals below are
#                    # reproducible; without it each run draws a fresh seed
#                    seed = 1636,
#                    bootstrap.nboot = 20)
# 
# model <- SEQuential(SEQdata, id.col = "ID",
#                              time.col = "time",
#                              eligible.col = "eligible",
#                              treatment.col = "tx_init",
#                              outcome.col = "outcome",
#                              time_varying.cols = c("N", "L", "P"),
#                              fixed.cols = "sex",
#                              method = "ITT",
#                              options = options)
# 
# end_of_fup(model)

## -----------------------------------------------------------------------------
# options <- SEQopts(end_of_fup = TRUE,
#                    end_of_fup.time = 12,
#                    # accept a measurement anywhere in [9, 15] when there is none at 12
#                    end_of_fup.window = 3,
#                    bootstrap = TRUE,
#                    seed = 1636,
#                    bootstrap.nboot = 20)
# 
# windowed <- SEQuential(SEQdata, id.col = "ID",
#                                 time.col = "time",
#                                 eligible.col = "eligible",
#                                 treatment.col = "tx_init",
#                                 outcome.col = "outcome",
#                                 time_varying.cols = c("N", "L", "P"),
#                                 fixed.cols = "sex",
#                                 method = "ITT",
#                                 options = options)
# 
# end_of_fup(windowed)[[1]]$estimates
# end_of_fup(windowed)[[1]]$comparison

## -----------------------------------------------------------------------------
# diagnostics(windowed)$eof.nonunique

## -----------------------------------------------------------------------------
# data <- data.table::copy(SEQdata)
# set.seed(42)
# data[, biomarker := 10 + 2 * as.numeric(as.character(tx_init)) + N + rnorm(.N)]
# 
# continuous <- SEQuential(data, id.col = "ID",
#                                time.col = "time",
#                                eligible.col = "eligible",
#                                treatment.col = "tx_init",
#                                outcome.col = "biomarker",
#                                time_varying.cols = c("N", "L", "P"),
#                                fixed.cols = "sex",
#                                method = "ITT",
#                                options = SEQopts(end_of_fup = TRUE,
#                                                  end_of_fup.time = 12,
#                                                  end_of_fup.type = "continuous",
#                                                  end_of_fup.window = 3,
#                                                  bootstrap = TRUE,
#                                                  seed = 1636,
#                                                  bootstrap.nboot = 20))
# 
# end_of_fup(continuous)[[1]]$estimates
# end_of_fup(continuous)[[1]]$comparison

## -----------------------------------------------------------------------------
# diagnostics(continuous)$eof.summary

## -----------------------------------------------------------------------------
# perprotocol <- SEQuential(SEQdata, id.col = "ID",
#                                    time.col = "time",
#                                    eligible.col = "eligible",
#                                    treatment.col = "tx_init",
#                                    outcome.col = "outcome",
#                                    time_varying.cols = c("N", "L", "P"),
#                                    fixed.cols = "sex",
#                                    method = "censoring",
#                                    options = SEQopts(weighted = TRUE,
#                                                      numerator = "sex",
#                                                      denominator = "N + L + P + sex",
#                                                      end_of_fup = TRUE,
#                                                      end_of_fup.time = 12,
#                                                      end_of_fup.window = 3,
#                                                      bootstrap = TRUE,
#                                                      seed = 1636,
#                                                      bootstrap.nboot = 20))
# 
# end_of_fup(perprotocol)[[1]]$estimates
# end_of_fup(perprotocol)[[1]]$comparison

