Tutorial: Using R's Distribution Functions in Stan Models (external C++)

Hello all!

I’ve put together a (very brief) tutorial showing how to use some of R’s statistical distribution functions in Stan models via external C++. As the majority of R’s core distributions are implemented in C, we can call these C functions directly without needing an R session at all.

However, this does still require specifying a gradient function - as it’s not possible to autodiff a compiled C function.

I’ve included an example implementation of the quantile functions for the standard-normal and T distributions (with gradients), and a small guide on checking for correctness. Let me know if anything is unclear!

Tutorial: Using R’s C Functions in Stan Models

9 Likes

@spinkney FYI on the approaches for implementing quantile functions here, this was mainly motivated by optimising student-t copula estimation time/efficiency

Cool!

1 Like