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)**.

## Usage

```
eti(x, ...)
# S3 method for numeric
eti(x, ci = 0.95, verbose = TRUE, ...)
# S3 method for stanreg
eti(
x,
ci = 0.95,
effects = c("fixed", "random", "all"),
component = c("location", "all", "conditional", "smooth_terms", "sigma",
"distributional", "auxiliary"),
parameters = NULL,
verbose = TRUE,
...
)
# S3 method for brmsfit
eti(
x,
ci = 0.95,
effects = c("fixed", "random", "all"),
component = c("conditional", "zi", "zero_inflated", "all"),
parameters = NULL,
verbose = TRUE,
...
)
```

## Arguments

- x
Vector representing a posterior distribution, or a data frame of such vectors. Can also be a Bayesian model.

**bayestestR**supports a wide range of models (see, for example,`methods("hdi")`

) and not all of those are documented in the 'Usage' section, because methods for other classes mostly resemble the arguments of the`.numeric`

or`.data.frame`

methods.- ...
Currently not used.

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

`.95`

(`95%`

).- verbose
Toggle off warnings.

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

- 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.

- 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.

## 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. While this can be useful to better represent the credibility
mass of a distribution, the HDI also has some limitations. See `spi()`

for
details.

The `95%`

or `89%`

Credible Intervals (CI)
are two reasonable ranges to characterize the uncertainty related to the estimation (see here for a discussion about the differences between these two values).

The `89%`

intervals (`ci = 0.89`

) are deemed to be more stable than, for
instance, `95%`

intervals (Kruschke, 2014). An effective sample size
of at least 10.000 is recommended if one wants to estimate `95%`

intervals
with high precision (Kruschke, 2014, p. 183ff). Unfortunately, the
default number of posterior samples for most Bayes packages (e.g., `rstanarm`

or `brms`

) is only 4.000 (thus, you might want to increase it when fitting
your model). 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).

However, `95%`

has some advantages too. For instance, it
shares (in the case of a normal posterior distribution) an intuitive
relationship with the standard deviation and it conveys a more accurate image
of the (artificial) bounds of the distribution. Also, because it is wider, it
makes analyses more conservative (i.e., the probability of covering 0 is
larger for the `95%`

CI than for lower ranges such as `89%`

), which is a good
thing in the context of the reproducibility crisis.

A `95%`

equal-tailed interval (ETI) has `2.5%`

of the distribution on either
side of its limits. It indicates the 2.5th percentile and the 97.5h
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)
#> 95% ETI: [-1.93, 1.84]
eti(posterior, ci = c(0.80, 0.89, 0.95))
#> Equal-Tailed Interval
#>
#> 80% ETI | 89% ETI | 95% ETI
#> ---------------------------------------------
#> [-1.29, 1.25] | [-1.58, 1.53] | [-1.93, 1.84]
df <- data.frame(replicate(4, rnorm(100)))
eti(df)
#> Equal-Tailed Interval
#>
#> Parameter | 95% ETI
#> -------------------------
#> X1 | [-1.93, 2.19]
#> X2 | [-1.70, 1.96]
#> X3 | [-1.91, 1.63]
#> X4 | [-1.87, 1.87]
eti(df, ci = c(0.80, 0.89, 0.95))
#> Equal-Tailed Interval
#>
#> Parameter | 80% ETI | 89% ETI | 95% ETI
#> ---------------------------------------------------------
#> X1 | [-1.16, 1.28] | [-1.74, 1.78] | [-1.93, 2.19]
#> X2 | [-0.96, 1.62] | [-1.40, 1.70] | [-1.70, 1.96]
#> X3 | [-1.07, 0.88] | [-1.52, 1.15] | [-1.91, 1.63]
#> X4 | [-1.20, 1.18] | [-1.67, 1.47] | [-1.87, 1.87]
# \dontrun{
library(rstanarm)
model <- stan_glm(mpg ~ wt + gear, data = mtcars, chains = 2, iter = 200, refresh = 0)
#> Warning: The largest R-hat is 1.06, indicating chains have not mixed.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#r-hat
#> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#bulk-ess
#> Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#tail-ess
eti(model)
#> Equal-Tailed Interval
#>
#> Parameter | 95% ETI | Effects | Component
#> ----------------------------------------------------
#> (Intercept) | [29.80, 50.38] | fixed | conditional
#> wt | [-6.99, -3.94] | fixed | conditional
#> gear | [-2.21, 1.24] | fixed | conditional
eti(model, ci = c(0.80, 0.89, 0.95))
#> Equal-Tailed Interval
#>
#> Parameter | 80% ETI | 89% ETI | 95% ETI | Effects | Component
#> --------------------------------------------------------------------------------------
#> (Intercept) | [32.43, 45.66] | [31.18, 47.98] | [29.80, 50.38] | fixed | conditional
#> wt | [-6.44, -4.62] | [-6.66, -4.35] | [-6.99, -3.94] | fixed | conditional
#> gear | [-1.52, 0.79] | [-1.88, 0.99] | [-2.21, 1.24] | fixed | conditional
library(emmeans)
eti(emtrends(model, ~1, "wt"))
#> Equal-Tailed Interval
#>
#> Parameter | 95% ETI
#> --------------------------
#> overall | [-6.99, -3.94]
library(brms)
model <- brms::brm(mpg ~ wt + cyl, data = mtcars)
#> Compiling Stan program...
#> Start sampling
#>
#> SAMPLING FOR MODEL '2d19b3a372313df641edf05db5e9f303' NOW (CHAIN 1).
#> Chain 1:
#> Chain 1: Gradient evaluation took 1.3e-05 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.13 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.030085 seconds (Warm-up)
#> Chain 1: 0.034711 seconds (Sampling)
#> Chain 1: 0.064796 seconds (Total)
#> Chain 1:
#>
#> SAMPLING FOR MODEL '2d19b3a372313df641edf05db5e9f303' NOW (CHAIN 2).
#> Chain 2:
#> Chain 2: Gradient evaluation took 8e-06 seconds
#> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.08 seconds.
#> Chain 2: Adjust your expectations accordingly!
#> Chain 2:
#> Chain 2:
#> Chain 2: Iteration: 1 / 2000 [ 0%] (Warmup)
#> Chain 2: Iteration: 200 / 2000 [ 10%] (Warmup)
#> Chain 2: Iteration: 400 / 2000 [ 20%] (Warmup)
#> Chain 2: Iteration: 600 / 2000 [ 30%] (Warmup)
#> Chain 2: Iteration: 800 / 2000 [ 40%] (Warmup)
#> Chain 2: Iteration: 1000 / 2000 [ 50%] (Warmup)
#> Chain 2: Iteration: 1001 / 2000 [ 50%] (Sampling)
#> Chain 2: Iteration: 1200 / 2000 [ 60%] (Sampling)
#> Chain 2: Iteration: 1400 / 2000 [ 70%] (Sampling)
#> Chain 2: Iteration: 1600 / 2000 [ 80%] (Sampling)
#> Chain 2: Iteration: 1800 / 2000 [ 90%] (Sampling)
#> Chain 2: Iteration: 2000 / 2000 [100%] (Sampling)
#> Chain 2:
#> Chain 2: Elapsed Time: 0.031236 seconds (Warm-up)
#> Chain 2: 0.034223 seconds (Sampling)
#> Chain 2: 0.065459 seconds (Total)
#> Chain 2:
#>
#> SAMPLING FOR MODEL '2d19b3a372313df641edf05db5e9f303' NOW (CHAIN 3).
#> Chain 3:
#> Chain 3: Gradient evaluation took 1e-05 seconds
#> Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0.1 seconds.
#> Chain 3: Adjust your expectations accordingly!
#> Chain 3:
#> Chain 3:
#> Chain 3: Iteration: 1 / 2000 [ 0%] (Warmup)
#> Chain 3: Iteration: 200 / 2000 [ 10%] (Warmup)
#> Chain 3: Iteration: 400 / 2000 [ 20%] (Warmup)
#> Chain 3: Iteration: 600 / 2000 [ 30%] (Warmup)
#> Chain 3: Iteration: 800 / 2000 [ 40%] (Warmup)
#> Chain 3: Iteration: 1000 / 2000 [ 50%] (Warmup)
#> Chain 3: Iteration: 1001 / 2000 [ 50%] (Sampling)
#> Chain 3: Iteration: 1200 / 2000 [ 60%] (Sampling)
#> Chain 3: Iteration: 1400 / 2000 [ 70%] (Sampling)
#> Chain 3: Iteration: 1600 / 2000 [ 80%] (Sampling)
#> Chain 3: Iteration: 1800 / 2000 [ 90%] (Sampling)
#> Chain 3: Iteration: 2000 / 2000 [100%] (Sampling)
#> Chain 3:
#> Chain 3: Elapsed Time: 0.034988 seconds (Warm-up)
#> Chain 3: 0.033017 seconds (Sampling)
#> Chain 3: 0.068005 seconds (Total)
#> Chain 3:
#>
#> SAMPLING FOR MODEL '2d19b3a372313df641edf05db5e9f303' NOW (CHAIN 4).
#> Chain 4:
#> Chain 4: Gradient evaluation took 9e-06 seconds
#> Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0.09 seconds.
#> Chain 4: Adjust your expectations accordingly!
#> Chain 4:
#> Chain 4:
#> Chain 4: Iteration: 1 / 2000 [ 0%] (Warmup)
#> Chain 4: Iteration: 200 / 2000 [ 10%] (Warmup)
#> Chain 4: Iteration: 400 / 2000 [ 20%] (Warmup)
#> Chain 4: Iteration: 600 / 2000 [ 30%] (Warmup)
#> Chain 4: Iteration: 800 / 2000 [ 40%] (Warmup)
#> Chain 4: Iteration: 1000 / 2000 [ 50%] (Warmup)
#> Chain 4: Iteration: 1001 / 2000 [ 50%] (Sampling)
#> Chain 4: Iteration: 1200 / 2000 [ 60%] (Sampling)
#> Chain 4: Iteration: 1400 / 2000 [ 70%] (Sampling)
#> Chain 4: Iteration: 1600 / 2000 [ 80%] (Sampling)
#> Chain 4: Iteration: 1800 / 2000 [ 90%] (Sampling)
#> Chain 4: Iteration: 2000 / 2000 [100%] (Sampling)
#> Chain 4:
#> Chain 4: Elapsed Time: 0.031447 seconds (Warm-up)
#> Chain 4: 0.031676 seconds (Sampling)
#> Chain 4: 0.063123 seconds (Total)
#> Chain 4:
eti(model)
#> Equal-Tailed Interval
#>
#> Parameter | 95% ETI | Effects | Component
#> ----------------------------------------------------
#> b_Intercept | [36.22, 43.28] | fixed | conditional
#> b_wt | [-4.81, -1.65] | fixed | conditional
#> b_cyl | [-2.37, -0.62] | fixed | conditional
eti(model, ci = c(0.80, 0.89, 0.95))
#> Equal-Tailed Interval
#>
#> Parameter | 80% ETI | 89% ETI | 95% ETI | Effects | Component
#> --------------------------------------------------------------------------------------
#> b_Intercept | [37.48, 41.93] | [36.89, 42.57] | [36.22, 43.28] | fixed | conditional
#> b_wt | [-4.21, -2.19] | [-4.48, -1.93] | [-4.81, -1.65] | fixed | conditional
#> b_cyl | [-2.07, -0.95] | [-2.21, -0.80] | [-2.37, -0.62] | fixed | conditional
library(BayesFactor)
bf <- ttestBF(x = rnorm(100, 1, 1))
eti(bf)
#> Equal-Tailed Interval
#>
#> Parameter | 95% ETI
#> -------------------------
#> Difference | [0.85, 1.26]
eti(bf, ci = c(0.80, 0.89, 0.95))
#> Equal-Tailed Interval
#>
#> Parameter | 80% ETI | 89% ETI | 95% ETI
#> -------------------------------------------------------
#> Difference | [0.92, 1.19] | [0.89, 1.22] | [0.85, 1.26]
# }
```