Skip to content

Commit

Permalink
Merge pull request #12 from Novartis/10-jsm2024
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-bean authored Jul 31, 2024
2 parents 2d6dd86 + d91dd20 commit 3fb7de5
Show file tree
Hide file tree
Showing 27 changed files with 2,529 additions and 15 deletions.
13 changes: 13 additions & 0 deletions index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ development problems. In order to highlight the versatility of that package,
we have developed a collection of case studies covering a diverse set of
clinical questions that were addressed via Bayesian modelling with the `brms` package.

::: {.content-visible when-profile="public"}
::: {.callout-tip}
## Short course at JSM -- Portland, OR -- August 5th 2024

We will offer a short course based on this material at the 2024 Joint Statistical Meetings in Portland on August 5. The materials are available here:

- [Slides](workshops/jsm2024/slides/bamdd_jsm2024.pdf) & [additional material (see readme)](https://github.com/Novartis/bamdd/tree/main/workshops/jsm2024)

:::
:::

## Navigating the site

The material is organized as follows:
Expand All @@ -26,6 +37,7 @@ studies. You can find a [listing with descriptions on this page](src/02_case_stu
as exposing and injecting custom stan code to `brms` models,
and efficient parallel computation to support sampling in `brms`.


## Updates

This web-site is intended as a live document with updates as
Expand All @@ -34,6 +46,7 @@ appropiate. Key changes to the web-site are tracked here:


::: {.content-visible when-profile="public"}
- 31st July 2024: Linked materials from JSM Portland 2024 short course
- 5th June 2024: Added @sec-pos on assessing probability of success of
in Phase-III based on a single-arm trial in Phase-II
- 29th April 2024: Third edition course from Paul Bürkner with the new
Expand Down
3 changes: 2 additions & 1 deletion src/01b_basic_workflow.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ set.seed(5886935)
#| eval: true
#| include: false
# invisible to the reader additional setup steps, which are optional
{{< include setup.R >}}
# {{< include setup.R >}}
source("setup.R")
```

As `brms` models are translated to Stan model files, which must be
Expand Down
8 changes: 6 additions & 2 deletions src/01c_priors.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ bibliography: references.bib

# Model setup & priors {#sec-model-priors}

```{r, include=FALSE}
```{r, eval=TRUE,echo=TRUE,message=FALSE,warning=FALSE}
#| code-fold: true
#| code-summary: "Show R setup"
library(ggplot2)
library(dplyr)
library(knitr)
Expand All @@ -31,7 +34,8 @@ theme_set(theme_bw(12))

```{r, include=FALSE, echo=FALSE, eval=TRUE}
# invisible to the reader additional setup steps, which are optional
{{< include setup.R >}}
# {{< include setup.R >}}
source("setup.R")
```

Within the Bayesian regression modeling in Stan framework `brms`
Expand Down
3 changes: 2 additions & 1 deletion src/02a_meta_analysis.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ set.seed(593467)

```{r, include=FALSE, echo=FALSE, eval=TRUE}
# invisible to the reader additional setup steps, which are optional
{{< include setup.R >}}
# {{< include setup.R >}}
source("setup.R")
```

## Background
Expand Down
3 changes: 2 additions & 1 deletion src/02ab_meta_analysis_trtdiff.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ set.seed(979356)

```{r, include=FALSE, echo=FALSE, eval=TRUE}
# invisible to the reader additional setup steps, which are optional
{{< include setup.R >}}
# {{< include setup.R >}}
source("setup.R")
```

## Background
Expand Down
3 changes: 2 additions & 1 deletion src/02ac_meta_analysis_strata.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ options(width=120, digits=2)

```{r, include=FALSE, echo=FALSE, eval=TRUE}
# invisible to the reader additional setup steps, which are optional
{{< include setup.R >}}
# {{< include setup.R >}}
source("setup.R")
```

## Background
Expand Down
3 changes: 2 additions & 1 deletion src/02b_dose_finding.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ set.seed(8979476)

```{r, include=FALSE, echo=FALSE, eval=TRUE}
# invisible to the reader additional setup steps, which are optional
{{< include setup.R >}}
# {{< include setup.R >}}
source("setup.R")
```

```{r get_annualized_rates}
Expand Down
3 changes: 2 additions & 1 deletion src/02c_dose_escalation.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ set.seed(8794567)

```{r, include=FALSE, echo=FALSE, eval=TRUE}
# invisible to the reader additional setup steps, which are optional
{{< include setup.R >}}
# {{< include setup.R >}}
source("setup.R")
```

Such a model is straightforward to implement in `brms`. Below, we use a nonlinear formula specification, in order to allow the prior for the intercept to be specified on the log scale.
Expand Down
3 changes: 2 additions & 1 deletion src/02cb_tte_dose_escalation.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ gt_format <- function(x) {

```{r, include=FALSE, echo=FALSE, eval=TRUE}
# invisible to the reader additional setup steps, which are optional
{{< include setup.R >}}
# {{< include setup.R >}}
source("setup.R")
```

## Example trial
Expand Down
3 changes: 2 additions & 1 deletion src/02e_multiple_imputation.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ options(brms.normalize=FALSE)

```{r, include=FALSE, echo=FALSE, eval=TRUE}
# invisible to the reader additional setup steps, which are optional
{{< include setup.R >}}
# {{< include setup.R >}}
source("setup.R")
```

Let us consider some simulated data for a trial in chronic obstructive
Expand Down
3 changes: 2 additions & 1 deletion src/02g_longitudinal.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ control_args <- list(adapt_delta = 0.95)

```{r, include=FALSE, echo=FALSE, eval=TRUE}
# invisible to the reader additional setup steps, which are optional
{{< include setup.R >}}
# {{< include setup.R >}}
source("setup.R")
```

```{r get_data, echo = TRUE}
Expand Down
3 changes: 2 additions & 1 deletion src/02h_mmrm.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ options(width=120)

```{r, include=FALSE, echo=FALSE, eval=TRUE}
# invisible to the reader additional setup steps, which are optional
{{< include setup.R >}}
# {{< include setup.R >}}
source("setup.R")
```

```{r include=FALSE}
Expand Down
3 changes: 2 additions & 1 deletion src/02i_time_to_event.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ options(width=120)

```{r, include=FALSE, echo=FALSE, eval=TRUE}
# invisible to the reader additional setup steps, which are optional
{{< include setup.R >}}
# {{< include setup.R >}}
source("setup.R")
```


Expand Down
3 changes: 2 additions & 1 deletion src/02j_network_meta_analysis.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ control_args <- list(adapt_delta=0.95)

```{r, include=FALSE, echo=FALSE, eval=TRUE}
# invisible to the reader additional setup steps, which are optional
{{< include setup.R >}}
# {{< include setup.R >}}
source("setup.R")
```


Expand Down
3 changes: 2 additions & 1 deletion src/02l_single_arm_pos.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ theme_set(theme_bw(base_size=18))

```{r, include=FALSE, echo=FALSE, eval=TRUE}
# invisible to the reader additional setup steps, which are optional
{{< include setup.R >}}
# {{< include setup.R >}}
source("setup.R")
```


Expand Down
28 changes: 28 additions & 0 deletions workshops/jsm2024/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Course materials

These are the materials accompanying the short course "Applied Modelling in Drug Development using brms" at the Joint Statistical Meetings in Portland, OR on August 5, 2024.

Instructors:
- David Ohlssen
- Andrew Bean
- Bjoern Holzhauer

Additional contributors:
- Paul Buerkner
- Sebastian Weber
- Lukas Widmer
- Cong Zhang

## Folder structure

- `schedule.png` has the course schedule
- `slides/bamdd_jsm2024.pdf` is the main slide deck for the course
- `slides/R/` is a directory containing the R code from the case studies presented in the course
- `exercises/` contains two sets of hands-on exercises in the form of Quarto files
- `exercises/solutions` has solutions from the organizers

## Exercise instructions

Course participants can find the exercises in the shared Posit Cloud space for the course (link provided during the course). See slides 38-44 in the main slides for instructions.


154 changes: 154 additions & 0 deletions workshops/jsm2024/exercises/ex1_historical_control.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
---
title: 'brms exercises: historical controls'
author: 'your-name-here'
date: today
output:
html_document:
toc: true
embed-resources: true
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Background

These exercises accompany the case study [Use of Historical Control
Data](TODO:link) as part of the training course "Workshop
on applied modeling in drug development using brms."

## Preliminary code

First load the required packages and set some options as described in the case study.

```{r, warning = FALSE, message = FALSE}
here::i_am("exercises/ex1_historical_control.qmd")
library(here)
library(ggplot2)
library(dplyr)
library(knitr)
library(brms)
library(posterior)
library(bayesplot)
library(RBesT)
theme_set(theme_bw())
options(
# how many processor cores would you like to use?
mc.cores = 4,
# how would you like to access Stan?
brms.backend = "cmdstanr",
# cache model binaries
cmdstanr_write_stan_file_dir=here::here("_brms-cache"),
# no need to normalize likelihoods
brms.normalize = FALSE,
# when you are storing your model to file,
# how shall it be updated?
brms.file_refit = "on_change"
# alternatives: "never", "always"
# use "never" for production
)
set.seed(254335)
```

Then create the dataset used in the example:

```{r}
AS_region <- bind_cols(RBesT::AS, region=sample(c("asia", "europe", "north_america"), 8, TRUE))
kable(AS_region)
```

And fit the model as shown in the case study:

```{r}
model <- bf(r | trials(n) ~ 1 + (1 | study), family=binomial)
model_prior <- prior(normal(0, 2), class="Intercept") +
prior(normal(0, 1), class="sd", coef="Intercept", group="study")
map_mc_brms <- brm(model, AS_region, prior = model_prior,
seed = 4767,
silent = 2, refresh = 0)
```

## Exercise 1

Create a posterior predictive check based on the predictive
distribution for the response rate.
Steps:
* Use `posterior_predict` to create samples from the predictive
distribution of outcomes per trial.
* Use `sweep(predictive, 2, AS_region$n, "/")` to convert these
samples from the predictive distribution of the outcome counts to
samples from the predictive distribution for responder rates.
* Use `ppc_intervals` from `bayesplot` to create a plot showing your
results.

```{r}
# Your solution here -----------------------------------------------------------
```


## Exercise 2

Redo the analysis with region, but treat region as a fixed
effect. Evaluate the informativeness of the obtained MAP priors.
The model formula for `brms` should look like `region_model_fixed
<- bf(r | trials(n) ~ 1 + region + (1 | study), family=binomial)`.
Steps:
* Consider the prior for the region fixed effect first. The reference
region is included in the intercept. The reference region is
implicitly defined by the first level of the variable region when
defined as `factor`.
- Define `asia` to be the reference region in the example. Also
include a level `other` in the set of levels.
- Assume that an odds-ratio of $2$ between regions can be seen as
very large such that a prior of $\mbox{N}(0, (\log(2)/1.96)^2)$
for the region main effect is adequate.
* Obtain the MAP prior for each region by using the
`AS_region_all` data frame defined below and apply
`posterior_linpred` as shown above.
* Convert the MCMC samples from the MAP prior distribution into
mixture distributions with the same code as above.
* Calculate the ESS for each prior distribution with the `ess`
function from `RBesT`.

```{r}
AS_region_all <- data.frame(region=c("asia", "europe", "north_america", "other")) %>%
mutate(study=paste("new_study", region, sep="_"), r=0, n=6)
# Your solution here -----------------------------------------------------------
```


## Exercise 3

Run the analysis for the normal endpoint in the `crohn` data set of
`RBesT`. Refer to the `RBesT` vignette for a [normal endpoint](https://cran.r-project.org/web/packages/RBesT/vignettes/introduction.html)
on more details and context.
Steps:
* Use as `family=gaussian` and use the `se` response modifier in place
of `trials` to specify a known standard error.
* Use the same priors as proposed in the vignette.
* Compare the obtained MAP prior (in MCMC sample form) from `RBesT`
and `brms`.

```{r}
crohn <- RBesT::crohn
# Your solution here -----------------------------------------------------------
```



Loading

0 comments on commit 3fb7de5

Please sign in to comment.