posterior_interval: Generic function and default method for posterior uncertainty...

Description Usage Arguments Value See Also Examples

View source: R/posterior_interval.R

Description

These intervals are often referred to as credible intervals, but we use the term uncertainty intervals to highlight the fact that wider intervals correspond to greater uncertainty. See posterior_interval.stanreg in the rstanarm package for an example.

Usage

1
2
3
4
posterior_interval(object, ...)

## Default S3 method:
posterior_interval(object, prob = 0.9, ...)

Arguments

object

The object to use.

...

Arguments passed to methods. See the methods in the rstanarm package for examples.

prob

A number p (0 < p < 1) indicating the desired probability mass to include in the intervals.

Value

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

The default method just takes object to be a matrix (one column per parameter) and computes quantiles, with prob defaulting to 0.9.

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Default method takes a numeric matrix (of posterior draws)
draws <- matrix(rnorm(100 * 5), 100, 5) # fake draws
colnames(draws) <- paste0("theta_", 1:5)
posterior_interval(draws)

# Example using rstanarm package:
# posterior_interval method for 'stanreg' objects
## Not run: 
if (require("rstanarm")) {
  fit <- stan_glmer(
    mpg ~ wt + am + (1|cyl),
    data = mtcars,
    QR = TRUE,
    prior = normal(0, 1),
    iter = 500 # to speed up example
  )
  rstanarm::posterior_interval(fit, prob = 0.5)
}

## End(Not run)

# Also see help("posterior_interval", package = "rstanarm")

stan-dev/rstantools documentation built on Oct. 27, 2018, 9:09 a.m.