Abstract
Hamiltonian Monte Carlo (HMC) is a powerful tool for Bayesian computation. In comparison with the traditional Metropolis–Hastings algorithm, HMC offers greater computational efficiency, especially in higher dimensional or more complex modeling situations. To most statisticians, however, the idea of HMC comes from a less familiar origin, one that is based on the theory of classical mechanics. Its implementation, either through Stan or one of its derivative programs, can appear opaque to beginners. A lack of understanding of the inner working of HMC, in our opinion, has hindered its application to a broader range of statistical problems. In this article, we review the basic concepts of HMC in a language that is more familiar to statisticians, and we describe an HMC implementation in R, one of the most frequently used statistical software environments. We also present hmclearn, an R package for learning HMC. This package contains a general-purpose HMC function for data analysis. We illustrate the use of this package in common statistical models. In doing so, we hope to promote this powerful computational tool for wider use. Example code for common statistical models is presented as supplementary material for online publication.
Supplementary Materials
Appendix:R code for HMC examples. (pdf file type)
R-package for learning HMC:R-package hmclearn contains a general-purpose function as well as utility functions for the model fitting methods described in the article. Example datasets and code are also made available in the package. The package hmclearn can be accessed at https://cran.r-project.org/web/packages/hmclearn/index.html.
Acknowledgments
The authors thank the Editor, Associate Editor, and two reviewers for their many insightful comments.