0. Setup
Setup
This is a repository with training material for Tumor Growth Inhibition (TGI) and joint TGI-OS (Overall Survival) modeling.
Here is an overview of the required setup steps, which are described in more detail below:
- Clone the repository from GitHub
- Open the folder in RStudio or VSCode
- Install
RTools
(if you are on Windows) - Install necessary R packages
- Install
cmdstanr
(optional but highly recommended)
Install RTools
If you are running the examples on a Windows PC, you will need to install RTools
, see
here.
You need to use the version of RTools
that matches your R version. You can check your R version by running R.Version()$version.string
.
You can then afterwards check the installation of RTools
with:
if(!require(pkgbuild)) install.packages("pkgbuild")
::has_build_tools() pkgbuild
Install necessary R packages
The following code will install the packages that are required to run the examples in this repository.
<- function(pkg, min_version = NULL) {
install_if_not_available <- suppressWarnings(suppressPackageStartupMessages(
is_installed require(pkg, character.only = TRUE)
))if (is_installed & !is.null(min_version)) {
<- packageVersion(pkg) >= min_version
version_ok
} if (!is_installed | !version_ok) {
install.packages(pkg)
}
}<- c(
packages "bayesplot",
"brms",
"ggplot2",
"gt",
"here",
"janitor",
"modelr",
"posterior",
"readxl",
"rstan",
"tidybayes",
"tidyverse",
"truncnorm"
)sapply(packages, install_if_not_available)
::install_github("genentech/jmpost") remotes
[Optional] Install cmdstanr
Optionally, you can use cmdstanr
as the backend of brms
for fitting the models.
There are a few advantages of using cmdstanr
over the default rstan
:
- With
cmdstanr
, you can cache the compiled model, therefore you don’t need to recompile the model as long as the same formula is used, even after restarting R session (or re-opening RStudio). cmdstanr
is more up-to-date and more actively maintained compared torstan
.
A detailed installation guide for cmdstanr
is available here. Here is a brief summary:
Install
cmdstanr
with:# Typically, you install cmdstanr from the R-universe as follows: install.packages("cmdstanr", repos = c('https://stan-dev.r-universe.dev', getOption("repos"))) # If the above does not work, e.g. because you in a company network or VPN, you can install cmdstanr from GitHub instead: ::install_github("stan-dev/cmdstanr@*release") remotes
Check the compiler toolchain with:
::check_cmdstan_toolchain() cmdstanr
- This should not be a problem on Mac and Linux (including RStudio Cloud instances), but might be a problem on Windows.
- If you have problems, please check the installation guide for Windows.
RTools
is the easiest way.- Even if you have
RTools
, you might still see an error like"Rtools44 installation found but the toolchain was not installed."
. - In this case, you can run
cmdstanr::check_cmdstan_toolchain(fix = TRUE)
and this will likely resolve the issue.
Install the
CmdStan
backend with:::install_cmdstan(cores = 2) cmdstanr
Testing the
cmdstanr
installation- If the above installation was successful, you should now be able to run the following simple model.
library(cmdstanr) <- file.path( file cmdstan_path(), "examples", "bernoulli", "bernoulli.stan" )<- cmdstan_model(file) mod <- list(N = 10, y = c(0, 1, 0, 0, 0, 0, 0, 0, 0, 1)) data_list <- mod$sample( fit data = data_list, seed = 123, chains = 4, parallel_chains = 4, refresh = 500 )