Skip to contents

Takes as input a stanfit object from call to sampling and extracts Rhat and neff values.

Usage

get_rhat(object, pars, ...)

plot_rhat(object, pars, labels, ...)

get_neff(object, pars, ...)

plot_neff(object, pars, labels, ...)

Arguments

object

output from call to sampling.

pars

character vector of posterior parameter samples to be extracted.

...

(not used)

labels

vector of parameter labels

Examples

require(rstan)
#> Loading required package: rstan
#> Loading required package: StanHeaders
#> 
#> rstan version 2.32.7 (Stan version 2.32.2)
#> For execution on a local, multicore CPU with excess RAM we recommend calling
#> options(mc.cores = parallel::detectCores()).
#> To avoid recompilation of unchanged Stan programs, we recommend calling
#> rstan_options(auto_write = TRUE)
#> For within-chain threading using `reduce_sum()` or `map_rect()` Stan functions,
#> change `threads_per_chain` option:
#> rstan_options(threads_per_chain = 1)
#> Do not specify '-march=native' in 'LOCAL_CPPFLAGS' or a Makevars file

mdl <- "data{ int n; vector[n] x; }  
   parameters{ real mu; }  
   model{ x ~ normal(mu, 1.0);} 
   generated quantities{ vector[n] x_sim; real x_sim_sum; 
   for (i in 1:n) x_sim[i] = normal_rng(mu, 1.0); x_sim_sum = sum(x_sim);}\n"  
mdl <- stan_model(model_code = mdl)
n = 20
x = rnorm(n, 0, 2)

mdl.fit <- sampling(mdl, data = list(n = n, x = x), 
   init = function() list(mu = 0), chains = 1)
#> 
#> SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 1).
#> Chain 1: 
#> Chain 1: Gradient evaluation took 1.2e-05 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.12 seconds.
#> Chain 1: Adjust your expectations accordingly!
#> Chain 1: 
#> Chain 1: 
#> Chain 1: Iteration:    1 / 2000 [  0%]  (Warmup)
#> Chain 1: Iteration:  200 / 2000 [ 10%]  (Warmup)
#> Chain 1: Iteration:  400 / 2000 [ 20%]  (Warmup)
#> Chain 1: Iteration:  600 / 2000 [ 30%]  (Warmup)
#> Chain 1: Iteration:  800 / 2000 [ 40%]  (Warmup)
#> Chain 1: Iteration: 1000 / 2000 [ 50%]  (Warmup)
#> Chain 1: Iteration: 1001 / 2000 [ 50%]  (Sampling)
#> Chain 1: Iteration: 1200 / 2000 [ 60%]  (Sampling)
#> Chain 1: Iteration: 1400 / 2000 [ 70%]  (Sampling)
#> Chain 1: Iteration: 1600 / 2000 [ 80%]  (Sampling)
#> Chain 1: Iteration: 1800 / 2000 [ 90%]  (Sampling)
#> Chain 1: Iteration: 2000 / 2000 [100%]  (Sampling)
#> Chain 1: 
#> Chain 1:  Elapsed Time: 0.01 seconds (Warm-up)
#> Chain 1:                0.009 seconds (Sampling)
#> Chain 1:                0.019 seconds (Total)
#> Chain 1: 

get_rhat(mdl.fit, pars = "mu")
#>   parameter    value rating
#> 1        mu 1.000061   Good
get_neff(mdl.fit, pars = "mu")
#>   parameter    n     neff     value   rating
#> 1        mu 1000 356.9613 0.3569613 Moderate