Interpreting plots from rstan plot_diag



Can anyone help me interpret the output of plot_diag in rstan? I ran with 10 chains; all but one of which completed in under an hour. The 4th chain took 13 hours, and I’m trying to find out why. The attached plot is from plot_diag with chain=4.

The top and bottom panel seem to show that only chain 4 had treedepth>6, while the middle panel suggests all chains were spread across all depths. Do these plots just have different opacity settings? Which conclusion is the right one?

Also, is there another way to get at this information? get_adaptation_info returns enormous strings, which are not convenient. Hunting around in the slots of the stanfit object I didn’t see the info anywhere else, though it must be somewhere.treedepth.pdf (76.2 KB)


Answering a couple of parts of my own question after looking at the R source:
First, the info is stored in the sampler_params attribute of @sim$samples (from the get_sampler_params method).
Second, apparently the 4th chain is the only one with big tree depths:

    > xt <- rstan:::.sampler_params_post_warmup(fit4, "treedepth__", as.df=TRUE)
    > summary(xt)
    iterations      chain:1     chain:2     chain:3     chain:4         chain:5
    Min.   :1001   Min.   :6   Min.   :6   Min.   :6   Min.   : 5.00   Min.   :6
    1st Qu.:1251   1st Qu.:6   1st Qu.:6   1st Qu.:6   1st Qu.:10.00   1st Qu.:6
    Median :1500   Median :6   Median :6   Median :6   Median :12.00   Median :6
    Mean   :1500   Mean   :6   Mean   :6   Mean   :6   Mean   :11.23   Mean   :6
    3rd Qu.:1750   3rd Qu.:6   3rd Qu.:6   3rd Qu.:6   3rd Qu.:13.00   3rd Qu.:6
    Max.   :2000   Max.   :6   Max.   :6   Max.   :6   Max.   :15.00   Max.   :6
       chain:6     chain:7     chain:8     chain:9     chain:10
    Min.   :6   Min.   :6   Min.   :6   Min.   :6   Min.   :6
    1st Qu.:6   1st Qu.:6   1st Qu.:6   1st Qu.:6   1st Qu.:6
    Median :6   Median :6   Median :6   Median :6   Median :6
    Mean   :6   Mean   :6   Mean   :6   Mean   :6   Mean   :6
    3rd Qu.:6   3rd Qu.:6   3rd Qu.:6   3rd Qu.:6   3rd Qu.:6
    Max.   :6   Max.   :6   Max.   :6   Max.   :6   Max.   :6

The 4th chain also has a slightly larger stepsize than the others (0.0982; next closest is 0.0945, with values ranging down to 0.066).

I still don’t know why the middle panel shows blue and green for treedepth > 6 while the others show only green.

P.S. Is there a way to get a fixed width font?


Yeah, code formatting is essentially that. One backtick to start and end inline usage, e.g fixed width font, and three to start and end a chunk, e.g.,

fixed width font

As to your main questions, it does look like something is wrong with the transparency settings. We’re going to be deprecating these particular functions soon anyway, so I don’t think we’ll fix this. We have better diagnostic plots in the bayesplot package now that will replace the old ones. Check out

and also the vignette about diagnostics at

Hope that helps!


Also, the nuts_params() function in bayesplot returns the sampler parameter info in an easy to work with data frame:


Just to have it linked here, here’s the RStan issue regarding the deprecation:

Anyone who cares is welcome to chime in!


Thanks for the fixed width font tip; I was using single backticks. Switching to 3 seems to have worked (see Interpreting plots from rstan plot_diag, which I edited), once I moved them to the start of a line.

Oddly, I haven’t found a guide to the markup language discourse uses, though I suppose the upstream site has something. I would expect this site to have some help about it.


If you are are starting a new topic in the modeling category there’s a template that opens that shows how to use different syntax for code and for math. But we should have something like that not just for the modeling category. I’ll see what I can do!