---
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```

```{r, echo = F}
suppressPackageStartupMessages(library(ph2rand))
```

# ph2rand <img src='man/figures/ph2rand.png' align="right" height="139" />

*Randomized Phase II Oncology Trials with Bernoulli Outcomes*

## Description

__ph2rand__ provides functions to assist with the design of randomized comparative phase II oncology trials that assume their primary outcome variable is Bernoulli distributed.
Specifically, support is provided to (a) perform a sample size calculation when using one of several published designs (Jung, 2008; Jung and Sargent, 2014; Kepner, 2010; Litwin *et al*, 2017, Shan *et al*, 2013), (b) evaluate the operating characteristics of a given design (both analytically and via simulation), and (c) produce informative plots.

## Getting started

You can install the the latest development version of __ph2rand__, available from [GitHub](https://github.com/), with

```{r, eval = F}
devtools::install_github("mjg211/ph2rand")
```

An introductory example of how to make use of the package’s core functionality can be found below.
For further help, please see the package vignettes or email michael.grayling@newcastle.ac.uk.

## Example: Two-stage designs

We demonstrate functionality for two-stage designs, with the approach for single-stage designs being similar.
First, find a two-stage design from Jung (2008) for the default parameters

```{r binomial}
des_jung <- des_two_stage()
```

Then examine its required sample size in each arm, in each stage

```{r binomial_samplesize}
des_jung$nC
des_jung$nE
```

Next, look at its key operating characteristics

```{r binomial_opchar}
des_jung$opchar
```

Compare this to the equivalent design from Litwin *et al* (2017)

```{r sat}
des_litwin_et_al <- des_two_stage(type  = "sat",
                                  nCmax = 20L)
des_litwin_et_al$nC
des_litwin_et_al$nE
des_litwin_et_al$opchar
```

Now to that from Shan (2013)

```{r barnard}
des_shan_et_al <- des_two_stage(type  = "barnard",
                                nCmax = 40L)
des_shan_et_al$nC
des_shan_et_al$nE
des_shan_et_al$opchar
```

And finally that from Jung and Sargent (2014)

```{r fisher}
des_jung_sargent <- des_two_stage(type  = "fisher")
des_jung_sargent$nC
des_jung_sargent$nE
des_jung_sargent$opchar
```

We can then readily find the terminal points of any of these designs, along with their probability mass functions and operating characteristics for any true response rates.
For example, consider two scenarios given by

```{r pi}
pi <- rbind(c(0.1, 0.1),
            c(0.1, 0.3))
```

Then find the terminal points, probability mass functions, and operating characteristics (both analytically and via simulation) of the Jung (2008) design with

```{r terminal_pmf_opchar}
terminal_jung <- terminal(des_jung)
terminal_jung$terminal
pmf_jung      <- pmf(des_jung, pi)
pmf_jung$pmf
opchar_jung   <- opchar(des_jung, pi)
opchar_jung$opchar
sim_jung      <- sim(des_jung, pi)
sim_jung$sim
```

Finally, we can plot various factors relating to the designs.
For example, plot the terminal points of the Jung (2008) design (with their associated decisions), along with the probability of rejecting the null hypothesis when the response probabilities are equal in the two arms or when the difference in the response probabilities is the chosen treatment effect

```{r plot}
plot(des_jung)
```

See the package vignettes for further details.

## References

Jung SH (2008) Randomized phase II trials with a prospective control.
*Stat Med* 27(4):568--83.
DOI: [10.1002/sim.2961](https://doi.org/10.1002/sim.2961).
PMID: [17573688](https://pubmed.ncbi.nlm.nih.gov/17573688).

Jung SH, Sargent DJ (2014) Randomized phase II clinical trials.
*J Biopharm Stat* 24(4):802--16.
DOI: [10.1080/10543406.2014.901343](https://doi.org/10.1080/10543406.2014.901343).
PMID: [24697589](https://pubmed.ncbi.nlm.nih.gov/24697589).

Kepner JL (2010) On group sequential designs comparing two binomial proportions.
*J Biopharm Stat* 20(1):145--59.
DOI: [10.1080/10543400903280621](https://doi.org/10.1080/10543400903280621).
PMID: [20077254](https://pubmed.ncbi.nlm.nih.gov/20077254).

Litwin S, Basickes S, Ross EA (2017) Two-sample binary phase 2 trials with low type I error and low sample size.
*Stat Med* 36(9):1383--94.
DOI: [10.1002/sim.7226](https://doi.org/10.1002/sim.7226).
PMID: [28118686](https://pubmed.ncbi.nlm.nih.gov/28118686).

Shan G, Ma C, Hutson AD, Wilding GE (2013) Randomized two-stage phase II clinical trial designs based on Barnard's exact test.
*J Biopharm Stat* 23(5):1081--90.
DOI: [10.1080/10543406.2013.813525](https://doi.org/10.1080/10543406.2013.813525).
PMID: [23957517](https://pubmed.ncbi.nlm.nih.gov/23957517).