#

---
title: "Design of the DEFUSE3 Trial"
author: "Tze Leung Lai, Philip W. Lavori, Olivia Liao, Ka Wai Tsang
and Balasubramanian Narasimhan"
date: '`r Sys.Date()`'
bibliography: assistant.bib
output:
  html_document:
  theme: cerulean
  toc: yes
  toc_depth: 2
vignette: >
  %\VignetteIndexEntry{Design of the DEFUSE3 Trial}
  %\VignetteEngine{knitr::rmarkdown}
  \usepackage[utf8]{inputenc}
---

```{r echo=F}
### get knitr just the way we like it

knitr::opts_chunk$set(
  message = FALSE,
  warning = FALSE,
  error = FALSE,
  tidy = FALSE,
  cache = FALSE
)
```

## Introduction

Here, we present the calculations for the initial design of the
DEFUSE3 trial based on [@Lai2014191] and [@Lai201593]. The trial
parameters are fixed as follows.


```{r}
library(ASSISTant)
##Fix randomization vector N, errors, eps
trialParameters <- list(N = c(200, 340, 476), type1Error = 0.025,
                        eps = 1/2, type2Error = 0.1)
```

The design parameters are the following for various scenarios.

```{r}
designParameters <- list(
    nul0 = list(prevalence = rep(1/6, 6), mean = matrix(0, 2, 6),
                sd = matrix(1, 2, 6)),
    alt1 = list(prevalence = rep(1/6, 6), mean = rbind(rep(0, 6),
                                                       c(0.5, 0.4, 0.3, 0, 0, 0)),
                sd = matrix(1, 2, 6)),
    alt2 = list(prevalence = rep(1/6, 6), mean = rbind(rep(0, 6),
                                                     c(0.5, 0.5, 0, 0, 0, 0)),
                sd = matrix(1,2, 6)),
    alt3 = list(prevalence = rep(1/6, 6), mean = rbind(rep(0, 6), rep(0.36, 6)),
                sd = matrix(1,2, 6)),
    alt4 = list(prevalence = rep(1/6, 6), mean = rbind(rep(0, 6), rep(0.30, 6)),
                sd = matrix(1,2, 6)),
    alt5 = list(prevalence = rep(1/6, 6), mean = rbind(rep(0, 6),
                                                       c(0.4, 0.3, 0.2, 0, 0, 0)),
                sd = matrix(1,2, 6)),
    alt6 = list(prevalence = rep(1/6, 6), mean = rbind(rep(0, 6),
                                                       c(0.5, 0.5, 0.3, 0.3, 0.1, 0.1)),
                sd = matrix(1,2, 6))
)
```

## The NULL Scenario

```{r}
defuse3 <- DEFUSE3Design$new(trialParameters = trialParameters,
                             numberOfSimulations = 25000,
                             designParameters = designParameters$nul0,
                             showProgress = FALSE)
print(defuse3)
```

```{r}
result <- defuse3$explore(numberOfSimulations = 25000,
                          rngSeed = 283768,
                          showProgress = FALSE)
analysis <- defuse3$analyze(result)
print(defuse3$summary(analysis))
```

## The ALT1 Scenario

```{r}
result <- defuse3$explore(numberOfSimulations = 25000,
                          rngSeed = 873782,
                          trueParameters = designParameters$alt1,
                          showProgress = FALSE)
analysis <- defuse3$analyze(result)
print(defuse3$summary(analysis))
```

## The ALT2 Scenario

```{r}
result <- defuse3$explore(numberOfSimulations = 25000,
                          rngSeed = 45242,
                          trueParameters = designParameters$alt2,
                          showProgress = FALSE)
analysis <- defuse3$analyze(result)
print(defuse3$summary(analysis))
```

## The ALT3 Scenario

```{r}
result <- defuse3$explore(numberOfSimulations = 25000,
                          rngSeed = 833722,
                          trueParameters = designParameters$alt3,
                          showProgress = FALSE)
analysis <- defuse3$analyze(result)
print(defuse3$summary(analysis))
```

## The ALT4 Scenario

```{r}
result <- defuse3$explore(numberOfSimulations = 25000,
                          rngSeed = 434272,
                          trueParameters = designParameters$alt4,
                          showProgress = FALSE)
analysis <- defuse3$analyze(result)
print(defuse3$summary(analysis))
```

## The ALT5 Scenario

```{r}
result <- defuse3$explore(numberOfSimulations = 25000,
                          rngSeed = 132323,
                          trueParameters = designParameters$alt5,
                          showProgress = FALSE)
analysis <- defuse3$analyze(result)
print(defuse3$summary(analysis))
```

## The ALT6 Scenario

```{r}
result <- defuse3$explore(numberOfSimulations = 25000,
                          rngSeed = 653221,
                          trueParameters = designParameters$alt6,
                          showProgress = FALSE)
analysis <- defuse3$analyze(result)
print(defuse3$summary(analysis))
```

## References
