The posterior_interval function computes Bayesian posterior uncertainty intervals. These intervals are also often referred to as credible intervals.

# S3 method for stapreg
posterior_interval(object, prob = 0.9,
  type = "central", pars = NULL, regex_pars = NULL, ...)



A fitted model object returned by one of the rstap modeling functions. See stapreg-objects.


A number \(p \in (0,1)\) indicating the desired probability mass to include in the intervals. The default is to report \(90\)% intervals (prob=0.9) rather than the traditionally used \(95\)% (see Details).


The type of interval to compute. Currently the only option is "central" (see Details). A central \(100p\)% interval is defined by the \(\alpha/2\) and \(1 - \alpha/2\) quantiles, where \(\alpha = 1 - p\).


An optional character vector of parameter names.


An optional character vector of regular expressions to use for parameter selection. regex_pars can be used in place of pars or in addition to pars. Currently, all functions that accept a regex_pars argument ignore it for models fit using optimization.


Currently ignored.


A matrix with two columns and as many rows as model parameters (or the subset of parameters specified by pars and/or regex_pars). For a given value of prob, \(p\), the columns correspond to the lower and upper \(100p\)% interval limits and have the names \(100\alpha/2\)% and \(100(1 - \alpha/2)\)%, where \(\alpha = 1-p\). For example, if prob=0.9 is specified (a \(90\)% interval), then the column names will be "5%" and "95%", respectively.



Unlike for a frenquentist confidence interval, it is valid to say that, conditional on the data and model, we believe that with probability \(p\) the value of a parameter is in its \(100p\)% posterior interval. This intuitive interpretation of Bayesian intervals is often erroneously applied to frequentist confidence intervals. See Morey et al. (2015) for more details on this issue and the advantages of using Bayesian posterior uncertainty intervals (also known as credible intervals).

Default 90% intervals

We default to reporting \(90\)% intervals rather than \(95\)% intervals for several reasons:

  • Computational stability: \(90\)% intervals are more stable than \(95\)% intervals (for which each end relies on only \(2.5\)% of the posterior draws).

  • Relation to Type-S errors (Gelman and Carlin, 2014): \(95\)% of the mass in a \(90\)% central interval is above the lower value (and \(95\)% is below the upper value). For a parameter \(\theta\), it is therefore easy to see if the posterior probability that \(\theta > 0\) (or \(\theta < 0\)) is larger or smaller than \(95\)%.

Of course, if \(95\)% intervals are desired they can be computed by specifying prob=0.95.

Types of intervals

Currently posterior_interval only computes central intervals because other types of intervals are rarely useful for the models that rstap can estimate. Additional possibilities may be provided in future releases as more models become available.


Gelman, A. and Carlin, J. (2014). Beyond power calculations: assessing Type S (sign) and Type M (magnitude) errors. Perspectives on Psychological Science. 9(6), 641--51.

Morey, R. D., Hoekstra, R., Rouder, J., Lee, M. D., and Wagenmakers, E. (2016). The fallacy of placing confidence in confidence intervals. Psychonomic Bulletin & Review. 23(1), 103--123.

See also

predictive_interval for predictive intervals.


if (!exists("example_model")) example(example_model) posterior_interval(example_model)
#> 5% 95% #> (Intercept) -0.337929817 0.85413584 #> centered_income -0.099481707 0.18529452 #> sex -0.168857465 0.61993844 #> centered_age -0.024665565 0.48883692 #> Coffee_Shop -0.025062586 0.01613831 #> Coffee_Shop_spatial_scale 0.928690973 19.31034138 #> Coffee_Shop_temporal_scale 0.932842404 8.04121361 #> b[(Intercept) subj_ID:1] -0.041123496 0.54308090 #> b[(Intercept) subj_ID:2] -0.229638315 0.48366472 #> b[(Intercept) subj_ID:3] -0.162877587 0.33464210 #> b[(Intercept) subj_ID:4] -0.123127495 0.31668256 #> b[(Intercept) subj_ID:5] -0.253356962 0.11250896 #> b[(Intercept) subj_ID:6] -0.057953777 0.23293371 #> b[(Intercept) subj_ID:7] -0.199121476 0.12333933 #> b[(Intercept) subj_ID:8] -0.039992200 0.49281622 #> b[(Intercept) subj_ID:9] -0.199664050 0.13760538 #> b[(Intercept) subj_ID:10] -0.199748384 0.10789194 #> Sigma[subj_ID:(Intercept),(Intercept)] 0.001314344 0.13795537 #> sigma 0.319289265 0.77705298
posterior_interval(example_model, regex_pars = "Coffee_Shop")
#> 5% 95% #> Coffee_Shop -0.02506259 0.01613831 #> Coffee_Shop_spatial_scale 0.92869097 19.31034138 #> Coffee_Shop_temporal_scale 0.93284240 8.04121361