Get startedGet started for free

Altering the estimation process

1. Altering the estimation process

So far we've talked about how to edit characteristics of the model such as the number and length of chains, and prior distributions. In addition to these characteristics, there are some internal options that affect how the sampling of the posterior distribution occurs. In most cases, the default options are sufficient. However, the need to alter these options comes up often enough that it's worth discussing them. The technical details of these options are beyond the scope of this course, but we will talk about how they can be changed to resolve error message we sometimes get.

2. Divergent transitions

The first error message we'll talk about concerns divergent transitions. This happens when the size betweens the steps of the estimator are too big. The Stan documentation describes this like walking down a steep hill. Taking too big of a step may make you fall. But you can take smaller steps and make it down safely, even if it takes longer. We can control the step size in Stan by sending a list to the `control` argument that specifies an adapt_delta. The adapt_delta argument can range from 0 to 1, and is set to 0-point-9-5 by default in rstanarm. By increasing the adapt_delta, we can decrease the step size, and in many cases resolve the divergent transitions error.

3. Exceeding the Maximum Treedepth

The second error message you may sometimes encounter is one saying that the maximum tree depth has been reached. In the sampling algorithm used by Stan and therefore rstanarm, the sampler looks for a place to "U-Turn" in a series of possible branches. Again, the specifics of this process are beyond the scope of this course. What's important to know here is that if the sampler reachers the max tree depth before finding a good place to "U-Turn", then the sample terminated the iteration before finding a good stopping place. Therefore the posterior distribution is not being sampled as efficiently as it should be. As with adapt_delta, we can control the maximum tree depth in Stan by sending a list to the control argument that specifies a max_treedepth. The max_treedepth is set to 10 by default in rstanarm. By increasing the max_treedepth, we allow the to look further for a good place to "U-Turn" .

4. Tuning the estimation

Divergent transitions and hitting the maximum tree depth are important issues to pay attention to during the estimation of a model. These errors may represent threats to the validity of your inferences about parameter values. Although these errors are uncommon for the models we're estimating in this course, these are important concepts to understand and know how to address in practice. Luckily, rstanarm allows for these errors to be easily addressed, so that we can be sure that our parameter estimates are coming from a stable estimation.

5. Let's practice!

Now let's practice tuning the estimation process.