Version 0.89.0

A pharmacokinetics/pharmacodynamics library for Stan


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 ( 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, use the following command to set path


Then one can follow 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


# 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.


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.

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, ""),
                    init = file.path(file.dir, "pk2cpt.init.R"),
                    seed = 123,
                    chains = 4,
                    parallel_chains = 2,
                    refresh = 500)


Team, Stan Development. 2020. CmdStan User’s Guide.

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