Skip to contents

Takes as input a stanfit object from call to sampling and plots traces for desired parameters.

Usage

trace_plot(object, pars, ...)

# S3 method for class 'stanfit'
trace_plot(object, pars, labels, divergences = FALSE, warmup = FALSE, ...)

Arguments

object

output from call to sampling.

pars

character vector of posterior parameter samples to be extracted.

...

(not used)

labels

character or expression vector of labels

divergences

should divergent samples be marked?

warmup

should warmup samples be included?

Examples

require(rstan)

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.7e-05 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.17 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.008 seconds (Warm-up)
#> Chain 1:                0.009 seconds (Sampling)
#> Chain 1:                0.017 seconds (Total)
#> Chain 1: 

trace_plot(mdl.fit, pars = "mu", labels = expression(mu))