Automatic differentiation in R with Stan Math

Introduction Automatic differentiation Automatic differentiation (AD) refers to the automatic/algorithmic calculation of derivatives of a function defined as a computer program by repeated application of the chain rule. Automatic differentiation plays an important role in many statistical computing problems, such as gradient-based optimization of large-scale models, where gradient calculation by means of numeric differentiation (i.

Step function regression in Stan

Introduction The aim of this post is to provide a working approach to perform piecewise constant or step function regression in Stan. To set up the regression problem, consider noisy observations \(y_1, \ldots, y_n \in \mathbb{R}\) sampled from a standard signal plus i.

Estimating reaction kinetics with Stan and R

Introduction In chemical kinetics, the rate of a solid-state reaction is generally modeled by a reaction rate law (or rate equation) of the form: \[ \frac{d\alpha}{dt} \ = \ k \cdot f(\alpha)\ = \ Ae^{-E_a/RT} \cdot f(\alpha) \]

Fitting the Heckman selection model with Stan and R

Introduction Selection bias Selection bias occurs when sampled data or subjects in a study have been selected in a way that is not representative of the population of interest. As a consequence, conclusions made about the analyzed sample may be difficult to generalize, as the observed effects could be biased towards the sample and do not necessarily extend well to the population that we intended to analyze.

Tracking Stan sampling progress in Shiny

Introduction The previous post demonstrates the use of pre-compiled Stan models in interactive R Shiny applications to avoid unnecessary Stan model (re-)compilation on application start-up. In this short follow-up post we go a step further and tackle the issue of tracking the Stan model sampling progress itself in a shiny-application.

Running compiled Stan models in Shiny

Introduction The aim of this post is to provide a short step-by-step guide on writing interactive R Shiny-applications that include models written in Stan using rstan and rstantools. The remainder of this post assumes a small amount of working knowledge on writing models in Stan and usage of the package rstan to interface Stan from R.