Torsten

Version 0.89.0

A pharmacokinetics/pharmacodynamics library for Stan

Installation

Currently Torsten is based on a forked version of Stan and hosted on GitHub

The latest v0.89rc is compatible with Stan v2.27.0. Torsten can be accessed from command line for cmdstan interface and cmdstanr (https://mc-stan.org/cmdstanr/) for R interface. It requires a modern C++11 compiler as well as a Make utility. See (Team 2020) for details of installation and required toolchain. In particular, we recommend the folowing versions of C++ compilers:

  • Linux: g++ >=7.5 or clang >=8.0,
  • macOS: the XCode version of clang,
  • Windows: g++ 8.1 (available with RTools 4.0).

On windows, the Make utility mingw32-make can be installed as part of RTools.

Command line interface

The command line interface cmdstan is available along with Torsten and can be found at Torsten/cmdstan.

After installation, one can use the following command to build a Torsten model model_name in model_path

cd Torsten/cmdstan
make model_path/model_name # replace "make" with "mingw32-make" on Windows platform

R interface

After installing cmdstanr from https://mc-stan.org/cmdstanr/, use the following command to set path

cmdstanr::set_cmdstan_path("Torsten/cmdstan")

Then one can follow https://mc-stan.org/cmdstanr/articles/cmdstanr.html to compile and run Torsten models.

MPI support

Torsten’s MPI support is of a different flavour than reduce_sum found in Stan. To be able to utilize MPI parallelisation, one first needs to ensure an MPI library such as

is available. Torsen’s implementation is tested on both MPICH and OpenMPI.

To use MPI-supported population/group solvers, add/edit make/local

TORSTEN_MPI=1

# path to MPI headers
CXXFLAGS += -isystem /usr/local/include
# if you are using Metrum's metworx platform, add MPICH3's
# headers with
# CXXFLAGS += -isystem /usr/local/mpich3/include

Note that currently TORSTEN_MPI and STAN_MPI flags conflict on processes management and cannot be used in a same Stan model, and MPI support is only available through cmdstan interface.

Testing

Models in example-models directory are for tutorial and demonstration. The following shows how to build and run the two-compartment model using cmdstanr, and use bayesplot to examine posterior density of CL.

library("cmdstanr")
set_cmdstan_path("Torsten/cmdstan")
file.dir <- file.path("Torsten", "example-models", "pk2cpt")
file  <- file.path(file.dir, "pk2cpt.stan")
model <- cmdstan_model(file)
fit <- model$sample(data = file.path(file.dir, "pk2cpt.data.R"),
                    init = file.path(file.dir, "pk2cpt.init.R"),
                    seed = 123,
                    chains = 4,
                    parallel_chains = 2,
                    refresh = 500)
bayesplot::mcmc_dens_overlay(fit$draws("CL"))

Bibliography

Team, Stan Development. 2020. CmdStan User’s Guide. https://mc-stan.org/docs/2%5F26/cmdstan-guide/index.html.

Last updated on 30 Jun 2021
Published on 25 Jun 2021
 Edit on GitHub