---
title: "&nbsp;"
output: html_document
params:
  alpha:      NA
  beta:       NA
  delta0:     NA
  delta1:     NA
  e:          NA
  efix:       NA
  f:          NA
  ffix:       NA
  integer:    NA
  J:          NA
  K:          NA
  lower:      NA
  maxN:       NA
  n10:        NA
  n1:         NA
  opchar:     NA
  pi0:        NA
  plots:      NA
  power:      NA
  ratio_type: NA
  ratio_init: NA
  ratio:      NA
  stopping:   NA
  swss:       NA
  upper:      NA
---

  ```{r setup, include = F}
knitr::opts_chunk$set(echo = F, results = "asis")
```

```{r params, echo = F, results = "asis"}
alpha      <- params$alpha
beta       <- params$beta
delta0     <- params$delta0
delta1     <- params$delta1
e          <- params$e
efix       <- params$efix
f          <- params$f
ffix       <- params$ffix
integer    <- params$integer
J          <- params$J
K          <- params$K
lower      <- params$lower
maxN       <- params$maxN
n10        <- params$n10
n1         <- params$n1
opchar     <- params$opchar
pi0        <- params$pi0
plots      <- params$plots
power      <- params$power
ratio_type <- params$ratio_type
ratio_init <- params$ratio_init
ratio      <- params$ratio
sigma      <- params$sigma
stopping   <- params$stopping
swss       <- params$swss
upper      <- params$upper
```

```{r input_text, echo = F, results = "asis"}
if (power == "marginal") {
  power_type_text     <- "marginal power for each null hypothesis"
  power_scenario_text <-
    "each of their respective least favourable configurations"
} else {
  power_scenario_text <- "the global alternative hypothesis"
  if (power == "conjunctive") {
    power_type_text   <- "conjunctive power"
  } else if (power == "disjunctive") {
    power_type_text   <- "disjunctive power"
  }
}

if (ratio_type == "equal_all") {
  ratio_text          <- "the same as the control arm"
} else if (ratio_type == "equal_exp") {
  ratio_text          <- paste0(ratio_init[1], " times that of the control arm")
} else {
  ratio_text          <- paste0(round(1/sqrt(K), 3),
                                " times that of the control arm")
}

if (lower == "fixed") {
  lower_prelim <- "fixed value"
} else if (lower == "obf") {
  lower_prelim <- "O'Brien-Fleming"
} else if (lower == "pocock") {
  lower_prelim <- "Pocock"
} else if (lower == "triangular") {
  lower_prelim <- "triangular"
}

if (upper == "fixed") {
  upper_prelim <- "fixed value"
} else if (upper == "obf") {
  upper_prelim <- "O'Brien-Fleming"
} else if (upper == "pocock") {
  upper_prelim <- "Pocock"
} else if (upper == "triangular") {
  upper_prelim <- "triangular"
}

if (lower == "fixed") {
  lower_text          <- paste0(lower_prelim, ", with a fixed value of ", ffix)
} else {
  lower_text          <- lower_prelim
}

if (upper == "fixed") {
  upper_text          <- paste0(upper_prelim, ", with a fixed value of ", efix)
} else {
  upper_text          <- upper_prelim
}

if (integer) {
  integer_text        <- "will"
} else {
  integer_text        <- "will not"
}

if (plots) {
  plot_text           <- "will"
} else {
  plot_text           <- "will not"
}
```

```{r output_text, echo = F, results = "asis"}
FWER                  <- round(opchar$FWERI1[1], 3)
if (power == "marginal") {
  power_type_text     <- "minimum marginal power"
  power_value         <-
    round(min(diag(as.matrix(opchar[-(1:2), (K + 4):(2*K + 3)]))), 3)
} else {
  power_scenario_text <- "the global alternative hypothesis."
  if (power == "conjunctive") {
    power_type_text   <- "conjunctive power"
    power_value       <- round(opchar$Pcon[2], 3)
  } else if (power == "disjunctive") {
    power_type_text   <- "disjunctive power"
    power_value       <- round(opchar$Pdis[2], 3)
  }
}
if (swss == "fixed") {
  swss_text  <- "is"
  swss_text2 <- round(n1, 3)
} else {
  swss_text  <- "to the control arm is"
  swss_text2 <- round(n10, 3)
}
```

#### Inputs

The following choices were made:

  - $K = \boldsymbol{`r K`}$ experimental treatments will initially be included in the trial.
- A maximum of $J = \boldsymbol{`r J`}$ stages will be allowed in the trial.
- A __`r stopping`__ stopping rule will be used.
- The stage-wise sample size will be __`r swss`__.
- The lower stopping boundaries will be __`r lower_text`__.
- The upper stopping boundaries will be __`r upper_text`__.
- A family-wise error-rate of $\alpha = \boldsymbol{`r alpha`}$ will be used.
- The __`r power_type_text`__ will be controlled to level $1-\beta = \boldsymbol{`r 1 - beta`}$ under __`r power_scenario_text`__.
- The response rate in the control arm will be assumed to be: $\pi_0 = \boldsymbol{`r pi0`}$.
- The interesting and uninteresting treatment effects will be: $\delta_1 = \boldsymbol{`r round(delta1, 3)`}$ and $\delta_0 = \boldsymbol{`r round(delta0, 3)`}$ respectively.
- The target allocation to each of the experimental arms will be: __`r ratio_text`__.
- The sample size in each arm __`r integer_text`__ be required to be an integer.
- Plots __`r plot_text`__ be produced.

#### Outputs

- The maximum required sample size is: $\boldsymbol{`r round(maxN, 3)`}$.
- The stage-wise sample size __`r swss_text`__: __`r swss_text2`__.
- The realised allocation ratios to the experimental arms are: $(r_1,\dots,r_K) = \boldsymbol{(`r paste(rep(round(ratio, 3), K), collapse = ", ")`)}$.
- The maximum familywise error-rate is: $\boldsymbol{`r FWER`}$.
- The __`r power_type_text`__ is: $\boldsymbol{`r power_value`}$.
- The lower stopping boundaries are: $\boldsymbol{`r paste0("(", paste(round(f, 3), collapse = ", "), ")")`}$.
- The upper stopping boundaries are: $\boldsymbol{`r paste0("(", paste(round(e, 3), collapse = ", "), ")")`}$.
