---
title: "Three-outcome clinical trial design (tout)"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Three-outcome clinical trial design (tout)}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r setup}
library(tout)
```

## Introduction

Early phase clinical trials typically employ a hypothesis test as their primary analysis, with this test having two possible outcomes: we will either **go** to the next stage of evaluation (e.g. a large phase III trial), or we will **stop** development. In a testing framework these decisions correspond with the rejection of the null hypothesis, or the failure to reject it, respectively.

Some authors have suggested that phase II drug trials can extend this approach to allow for a third intermediate outcome, where we **pause** if we observe data that is not so bad as to warrant an immediate stop, nor so good as to warrant an immediate go. A similar approach is very common in pilot trials of complex interventions. In both settings, the mechanics are the same: we compute an estimate $\hat{\rho}$ of the parameter of interest, $\rho$, and compare it against two thresholds, $x_0$ and $x_1$, such that

\begin{equation}\label{eqn:three_outcome}
\text{Decision} = 
\begin{cases}
\text{go} & \text{ if } \hat{\rho} \geq x_1 \\
\text{pause} & \text{ if } x_0 < \hat{\rho} < x_1 \\
\text{stop} & \text{ if } \hat{\rho} < x_0. \\
\end{cases}
\end{equation}

The `tout` package lets us determine optimal values for the decision thresholds $x_0$ and $x_1$ and the sample size $n$. In particular, it will find the smallest possible trial which will satisfy constraints on the following three operating characteristics:

- $\alpha$, the probability of proceeding to the main trial when $\rho \leq \rho_0$;
- $\beta$, the probability of not proceeding to the main trial when $\rho \geq \rho_1$; and
- $\gamma$, the probability of making an immediate stop or go decision when $\rho = (\rho_0 + \rho_1)/2$.

## A simple example

Suppose the parameter of interest, $\rho$, is the probability of adherence in the intervention arm of a pilot trial. Suppose further that our null and alternative hypotheses are $\rho_0 = 0.5$ and $\rho_1 = 0.7$, respectively. Using typical type I and II error constraints, $\alpha \leq 0.05$ and $\beta \leq 0.2$, we can find the smallest design that will ensure a probability of at least $1 - \gamma = 0.5$ that we will obtain a pause decision if the true parameter value is midway between the null and alternative hypotheses:

```{r}
design <- tout_design(rho_0 = 0.5, rho_1 = 0.7, alpha_nom = 0.05, beta_nom  = 0.2, gamma_nom = 0.5)

design
```
We can visualise the sampling distribution of the test statistic under each hypothesis, highlighting the decisions which will be made:

```{r, out.width="70%"}
plot(design)
```

## Making decisions following a pause outcome

The testing framework employed in `tout` acknowledges that a final stop/go decision must be made following a pause outcome, and factors this into the calculation of error rates. This requires an assumption about how well such decisions will be made; in particular, we must estimate the probabilities that we will incorrectly go when $\rho \leq \rho_0$ (denoted $\eta_0$), and that we will incorrectly stop when $\rho \geq \rho_1$ (denoted $\eta_1$). By default, `tout_design()` assumes that $\eta_0 = \eta_1 = 0.5$, but we can change these if we wish:

```{r}
design <- tout_design(rho_0 = 0.5, rho_1 = 0.7, alpha_nom = 0.05, beta_nom  = 0.2, gamma_nom = 0.5, eta_0 = 0.3, eta_1 = 0.4)

design
```

## Making adjustments following a pause outcome

We often anticipate making some adjustments to the intervention and/or the trial design following a pause outcome, in an attempt to improve the parameter of interest and ensure the subsequent trial is successful. We can incorporate this in `tout` if we can specify an interval for the effect of this modification $\tau \in [\tau_{min}, \tau_{max}]$. For example, suppose we anticipate an improvement in adherence in the range of $\tau \in [0.01, 0.05]$. The optimal design is then

```{r}
design <- tout_design(rho_0 = 0.5, rho_1 = 0.7, alpha_nom = 0.05, beta_nom  = 0.2, gamma_nom = 0.5, tau = c(0.01, 0.05))

design
```

## Designs for continuous endpoints

By default, `tout_design()` assumes a binary endpoint. We can find designs for continuous endpoints if we supply the (assumed known) standard deviation of the outcome via the `sigma` argument. For example,

```{r}
design <- tout_design(rho_0 = 2, rho_1 = 5, alpha_nom = 0.05, beta_nom  = 0.2, gamma_nom = 0.5, sigma = 7, tau = c(1, 2), max_n = 500)

design
```

Note that the decision thresholds are given on the scale of the z-statistic.

## Further details

For the case of a binary endpoint, the three error rates are formally defined as:

$$
\begin{align}
\alpha =& \max \big[ \Pr(x_1 < \hat{\rho} ~|~ \rho = \rho_0), ~\eta \Pr(x_0 < \hat{\rho} \leq x_1 ~|~ \rho = \rho_0 - \tau_{min}) \nonumber \\
&+ \Pr(x_1 < \hat{\rho} ~|~ \rho = \rho_0 - \tau_{min}) \big] \\
\beta =& \Pr(\hat{\rho} \leq x_0 ~|~ \rho = \rho_1 - \tau_{max}) + \eta \Pr(x_0 < \hat{\rho} \leq x_1 ~|~ \rho = \rho_1 - \tau_{max}) \\
\gamma =& \Pr(\hat{\rho} \leq x_0 ~|~ \rho = [\rho_0 + \rho_1 - \tau_{min} - \tau_{max}]/2) \\
&+ \Pr(x_1 < \hat{\rho} ~|~ \rho = [\rho_0 + \rho_1 - \tau_{min} - \tau_{max}]/2).
\end{align}
$$

Derivations of these are given in the associated manuscript. The case of continuous endpoints follows, now considering the test statistic to be a z-statistic with distribution

$$
Z \sim N \left( \frac{\rho - \rho_0}{\sqrt{\sigma^2/n}}, 1 \right).
$$

Given any $n$ and $x_1$, the $x_0$ corresponding to the nominal constraint on $\alpha$ can be found exactly. The optimal $x_1$ is determined numerically (using an exhaustive search in the binary case and `optimize()` in the continuous case) with respect to the nominal constraint on $\beta$. Finally, a bisection search is used to find the lowest $n$ which satisfies the nominal constraint on $\gamma$.

## References

- Wilson, D.T., Hudson, E. & Brown, S. Three-outcome designs for external pilot trials with progression criteria. _BMC Med Res Methodol_ 24, 226 (2024). https://doi.org/10.1186/s12874-024-02351-x


