Compute the Equal-Tailed Interval (ETI) of posterior distributions using the quantiles method. The probability of being below this interval is equal to the probability of being above it. The ETI can be used in the context of uncertainty characterisation of posterior distributions as Credible Interval (CI).

eti(x, ...)

# S3 method for numeric
eti(x, ci = 0.89, verbose = TRUE, ...)

# S3 method for data.frame
eti(x, ci = 0.89, verbose = TRUE, ...)

# S3 method for MCMCglmm
eti(x, ci = 0.89, verbose = TRUE, ...)

# S3 method for bayesQR
eti(x, ci = 0.89, verbose = TRUE, ...)

# S3 method for sim.merMod
eti(
  x,
  ci = 0.89,
  effects = c("fixed", "random", "all"),
  parameters = NULL,
  verbose = TRUE,
  ...
)

# S3 method for sim
eti(x, ci = 0.89, parameters = NULL, verbose = TRUE, ...)

# S3 method for emmGrid
eti(x, ci = 0.89, verbose = TRUE, ...)

# S3 method for stanreg
eti(
  x,
  ci = 0.89,
  effects = c("fixed", "random", "all"),
  parameters = NULL,
  verbose = TRUE,
  ...
)

# S3 method for brmsfit
eti(
  x,
  ci = 0.89,
  effects = c("fixed", "random", "all"),
  component = c("conditional", "zi", "zero_inflated", "all"),
  parameters = NULL,
  verbose = TRUE,
  ...
)

# S3 method for BFBayesFactor
eti(x, ci = 0.89, verbose = TRUE, ...)

Arguments

x

Vector representing a posterior distribution, or a data frame of such vectors. Can also be a Bayesian model (stanreg, brmsfit, MCMCglmm, mcmc or bcplm) or a BayesFactor model.

...

Currently not used.

ci

Value or vector of probability of the (credible) interval - CI (between 0 and 1) to be estimated. Default to .89 (89%).

verbose

Toggle off warnings.

effects

Should results for fixed effects, random effects or both be returned? Only applies to mixed models. May be abbreviated.

parameters

Regular expression pattern that describes the parameters that should be returned. Meta-parameters (like lp__ or prior_) are filtered by default, so only parameters that typically appear in the summary() are returned. Use parameters to select specific parameters for the output.

component

Should results for all parameters, parameters for the conditional model or the zero-inflated part of the model be returned? May be abbreviated. Only applies to brms-models.

Value

A data frame with following columns:

  • Parameter The model parameter(s), if x is a model-object. If x is a vector, this column is missing.

  • CI The probability of the credible interval.

  • CI_low, CI_high The lower and upper credible interval limits for the parameters.

Details

Unlike equal-tailed intervals (see eti()) that typically exclude 2.5% from each tail of the distribution and always include the median, the HDI is not equal-tailed and therefore always includes the mode(s) of posterior distributions.

By default, hdi() and eti() return the 89% intervals (ci = 0.89), deemed to be more stable than, for instance, 95% intervals (Kruschke, 2014). An effective sample size of at least 10.000 is recommended if 95% intervals should be computed (Kruschke, 2014, p. 183ff). Moreover, 89 indicates the arbitrariness of interval limits - its only remarkable property is being the highest prime number that does not exceed the already unstable 95% threshold (McElreath, 2015).

A 90% equal-tailed interval (ETI) has 5% of the distribution on either side of its limits. It indicates the 5th percentile and the 95h percentile. In symmetric distributions, the two methods of computing credible intervals, the ETI and the HDI, return similar results.

This is not the case for skewed distributions. Indeed, it is possible that parameter values in the ETI have lower credibility (are less probable) than parameter values outside the ETI. This property seems undesirable as a summary of the credible values in a distribution.

On the other hand, the ETI range does change when transformations are applied to the distribution (for instance, for a log odds scale to probabilities): the lower and higher bounds of the transformed distribution will correspond to the transformed lower and higher bounds of the original distribution. On the contrary, applying transformations to the distribution will change the resulting HDI.

Examples

library(bayestestR) posterior <- rnorm(1000) eti(posterior)
#> # Equal-Tailed Interval #> #> 89% ETI #> ------------- #> [-1.65, 1.70] #>
eti(posterior, ci = c(.80, .89, .95))
#> # Equal-Tailed Intervals #> #> 80% ETI #> ------------- #> [-1.31, 1.31] #> #> #> 89% ETI #> ------------- #> [-1.65, 1.70] #> #> #> 95% ETI #> ------------- #> [-2.07, 2.04] #> #>
df <- data.frame(replicate(4, rnorm(100))) eti(df)
#> # Equal-Tailed Interval #> #> Parameter | 89% ETI #> ------------------------- #> X1 | [-1.83, 1.62] #> X2 | [-1.59, 1.53] #> X3 | [-1.97, 1.19] #> X4 | [-1.80, 1.77] #>
eti(df, ci = c(.80, .89, .95))
#> # Equal-Tailed Intervals #> #> Parameter | 80% ETI #> ------------------------- #> X1 | [-1.51, 1.40] #> X2 | [-1.44, 1.36] #> X3 | [-1.46, 1.01] #> X4 | [-1.51, 1.49] #> #> #> Parameter | 89% ETI #> ------------------------- #> X1 | [-1.83, 1.62] #> X2 | [-1.59, 1.53] #> X3 | [-1.97, 1.19] #> X4 | [-1.80, 1.77] #> #> #> Parameter | 95% ETI #> ------------------------- #> X1 | [-2.10, 2.02] #> X2 | [-2.22, 1.98] #> X3 | [-2.32, 2.15] #> X4 | [-1.87, 2.00] #> #>
if (FALSE) { library(rstanarm) model <- stan_glm(mpg ~ wt + gear, data = mtcars, chains = 2, iter = 200, refresh = 0) eti(model) eti(model, ci = c(.80, .89, .95)) library(emmeans) eti(emtrends(model, ~1, "wt")) library(brms) model <- brms::brm(mpg ~ wt + cyl, data = mtcars) eti(model) eti(model, ci = c(.80, .89, .95)) library(BayesFactor) bf <- ttestBF(x = rnorm(100, 1, 1)) eti(bf) eti(bf, ci = c(.80, .89, .95)) }