# Introduction to Bayesian Computation Using the rstanarm Package

This post is by Eric Novik | 26 Nov 2016

As part of our not-so-secret mission to bring Bayesian computing to broader audiences, we held our second webinar introducing the rstanarm package.

The goal of the rstanarm package is to make it easier to use Bayesian estimation for most common regression models via Stan while preserving the traditional syntax that is used for specifying models in R and R packages like lme4 . In this webinar, Ben Goodrich, one of the developers of rstanarm, will introduce the most salient features of the package. To demonstrate these features, we will fit a model to loan repayments data from Lending Club and show why, in order to make rational decisions for loan approval or interest rate determination, we need a full posterior distribution as opposed to point predictions available in non-Bayesian statistical software.

If you missed the talk or want a refresher, check out the following recording.

Following are some of the additional refences that you may find helpful.

• How to use the rstanarm package vignette by Jonah Gabry and Ben Goodrich.
• Guide to Stan warnings by Jonah Gabry. Stan is sensitive to model misspecification and so you will likely see warnings generated during the fitting process. Not all warnings are created equal; Jonah wrote this up to help you get out of trouble if necessary.
• There are lots of case studies using Stan on mc-stan.org. There is currently one using rstanarm called Hierarchical Partial Pooling for Repeated Binary Trials. Partial pooling is an important concept in multi-level models. We will cover this topic during future webinars.

We tried answering as many questions as we could during the Webinar. Here are a few repeated questions that we did not get a chance to answer.

Can I use all this shiny magic to diagnose a model I have created with RStan?

Yes. You can use shinystan to examine objects that were fit with RStan. You can also use it to examine objects of type mcmc.list from the coda package which were not with Stan.

How can I specify priors in rstanarm?

Take a look at ?rstanarm::priors for prior choices that are currently available. These may change in the future.

Can we write out the stan model to a file?

One way to look at the stan code is to type fit\$stanfit@stanmodel at the R console, where fit is a stanreg object, which is an object that was fit with rstanarm. We do not recommend learning Stan this way as these models are not that easy to read, especially for beginners. Instead, take a look at the Programming Techniques section in the Stan manual.

Does rstanarm support Survival Models?

Not yet, but we are working on it.

Are divergent transitions related to estimating too many parameters for the given sample size? Any general guidelines for handling divergent transitions?

Divergent transitions have to do with the sampler’s inability to explore the posterior with adequate resolution and are generally not related to the number of the parameters. Please, refer to Guide to Stan warnings for more information.