Stan is an open source probabilistic programing language designed primarily to do Bayesian data analysis (Carpenter et al. 2017). It provides an expressive syntax for statistic modeling and contains an efficient variant of No UTurn Sampler(NUTS), an adaptative Hamiltonian Monte Carlo algorithm that was proven more efficient than commonly used Monte Carlo Markov Chains (MCMC) samplers for complex high dimensional problems (Hoffman and Gelman 2011; Betancourt 2018).
Torsten is a collection of Stan functions to facilitate analysis of pharmacometric data. Given an event schedule and an ODE system, it calculates amounts in each compartment. The current version includes ^{1}:
 Specific linear compartment models:
 One compartment model with first order absorption.
 Two compartment model with elimination from and first order absorption into central compartment
 General linear compartment model described by a system of firstorder linear Ordinary Differential Equations (ODEs).
 General compartment model described by a system of first order ODEs.
 Coupled model with PK forcing function described by a linear one or two compartment model and PD components solved by numerical ODE integration.
The models and data format are based on NONMEM \textregistered{} ^{2}/NMTRAN/PREDPP conventions including:
 recursive calculation of model predictions, which permits piecewise constant covariate values,
 bolus or constant rate inputs into any compartment,
 single dose and multiple dose events,
 steady state dosing events,
 NMTRANcompartible data items such as TIME, EVID, CMT, AMT, RATE, ADDL, II, and SS.
All real variable arguments in Torsten functions can be passed as Stan parameters
.
Implementation summary
 Current Torsten v0.89rc is based on Stan v2.27.0.
 All functions are programmed in C++ and are compatible with the Stan math automatic differentiation library (Carpenter et al. 2015)
 One and two compartment models are based on analytical solutions of governing ODEs.
 General linear compartment models are based on semianalytical solutions using the builtin matrix exponential function
 General compartment models are solved numerically using builtin ODE integrators in Stan. The tuning parameters of the solver are adjustable. The steady state solution is calculated using a numerical algebraic solver.
 Coupled model that has PK forcing function solved analytically and PD ODE components solved numerically.
Development plans
Our current plans for future development of Torsten include the following:
 Build a system to easily share packages of Stan functions (written in C++ or in the Stan language)
 Optimize Matrix exponential functions
 Function for the action of Matrix Exponential on a vector
 Handcoded gradients
 Special algorithm for matrices with special properties
 Develop new method for largescale hierarchical models with costly ODE solving.
 Fix issue that arises when computing the adjoint of the lag time parameter (in a dosing compartment) evaluated at \(t_{\text{lag}} = 0\).
 Extend formal tests
 More unit tests and better CD/CI support.
 Comparison with simulations from the R package
mrgsolve
and the software NONMEM\textregistered{}  Recruit nondeveloper users to conduct beta testing
Bibliography
Betancourt, Michael. 2018. “A Conceptual Introduction to Hamiltonian Monte Carlo.” https://arxiv.org/abs/1701.02434.
Carpenter, Bob, Andrew Gelman, Matthew D. Hoffman, Daniel Lee, Ben Goodrich, Michael Betancourt, Marcus Brubaker, Jiqiang Guo, Peter Li, and Allen Riddell. 2017. “Stan: A Probabilistic Programming Language.” Journal of Statistical Software 76.
Carpenter, Bob, Matthew D. Hoffman, Marcus Brubaker, Daniel Lee, Peter Li, and Michael Betancourt. 2015. “The Stan Math Library: ReverseMode Automatic Differentiation in C++.” arXiv:1509.07164 [Cs], September. http://arxiv.org/abs/1509.07164.
Hoffman, Matthew D., and Andrew Gelman. 2011. “The NoUTurn Sampler: Adaptively Setting Path Lengths in Hamiltonian Monte Carlo.” arXiv:1111.4246 [Cs, Stat], November. http://arxiv.org/abs/1111.4246.

WARNING: The current version of Torsten is a prototype. It is being released for review and comment, and to support limited research applications. It has not been rigorously tested and should not be used for critical applications without further testing or crosschecking by comparison with other methods. We encourage interested users to try Torsten out and are happy to assist. Please report issues, bugs, and feature requests on our GitHub page. ↩︎

NONMEM\textregistered{} is licensed and distributed by ICON Development Solutions. ↩︎