StanCat

R-CMD-check

Version 0.2

This package has one simple function: stan_caterpillar. It creates caterpillar plots for posterior distributions in stanfit objects created with Stan.

You use regular expressions to identify the parameters, so that you can easily plot a number of parameters using very compact code.

Example

First run your Stan model as usual:

# Create Stan model
library(rstan)

rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())

scode <- "
    parameters {
        real y[2];
    }
    model {
        y[1] ~ normal(0, 1);
        y[2] ~ double_exponential(0, 2);
    }
"

# Run
fit <- stan(model_code = scode, iter = 10000, verbose = FALSE)

We can then use regular expressions to identify all of the parameters that we want to plot. y\\[.*\\] in the example below identifies both the y[1] and y[2] parameters.

Note that \\[ and \\] are needed to include the square brackets as the square brackets in the Stan model, rather than as the special [] regular expressions brackets.

StanCat::stan_caterpillar(fit, pars = 'y\\[.*\\]')

Install

Use devtools to install the package:

devtools::install_github('christophergandrud/StanCat')


christophergandrud/StanCat documentation built on Jan. 6, 2023, 10:49 p.m.