-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Novartis/10-jsm2024
- Loading branch information
Showing
27 changed files
with
2,529 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ----------------------------------------------------------- | ||
``` | ||
|
||
|
||
|
Oops, something went wrong.