Compute Confidence/Credible/Compatibility Intervals (CI) or Support Intervals (SI) for Bayesian and frequentist models. The Documentation is accessible for:

ci(x, ...)

# S3 method for numeric
ci(x, ci = 0.89, method = "ETI", verbose = TRUE, BF = 1, ...)

# S3 method for data.frame
ci(x, ci = 0.89, method = "ETI", verbose = TRUE, BF = 1, ...)

# S3 method for emmGrid
ci(x, ci = 0.89, method = "ETI", verbose = TRUE, BF = 1, ...)

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

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

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

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

# S3 method for BFBayesFactor
ci(x, ci = 0.89, method = "ETI", verbose = TRUE, BF = 1, ...)

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

Arguments

x

A stanreg or brmsfit model, or a vector representing a posterior distribution.

...

Currently not used.

ci

Value or vector of probability of the CI (between 0 and 1) to be estimated. Default to .89 (89%) for Bayesian models and .95 (95%) for frequentist models.

method

Can be 'ETI' (default), 'HDI' or 'SI'.

verbose

Toggle off warnings.

BF

The amount of support required to be included in the support interval.

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

Note

When it comes to interpretation, we recommend thinking of the CI in terms of an "uncertainty" or "compatibility" interval, the latter being defined as “Given any value in the interval and the background assumptions, the data should not seem very surprising” (Gelman & Greenland 2019).

There is also a plot()-method implemented in the see-package.

References

Gelman A, Greenland S. Are confidence intervals better termed "uncertainty intervals"? BMJ 2019;l5381. doi: 10.1136/bmj.l5381

Examples

library(bayestestR) posterior <- rnorm(1000) ci(posterior, method = "ETI")
#> # Equal-Tailed Interval #> #> 89% ETI #> ------------- #> [-1.55, 1.45] #>
ci(posterior, method = "HDI")
#> # Highest Density Interval #> #> 89% HDI #> ------------- #> [-1.55, 1.45] #>
df <- data.frame(replicate(4, rnorm(100))) ci(df, method = "ETI", ci = c(.80, .89, .95))
#> # Equal-Tailed Intervals #> #> Parameter | 80% ETI #> ------------------------- #> X1 | [-1.12, 1.42] #> X2 | [-0.93, 1.33] #> X3 | [-1.31, 1.15] #> X4 | [-1.19, 1.42] #> #> #> Parameter | 89% ETI #> ------------------------- #> X1 | [-1.55, 1.50] #> X2 | [-1.17, 1.79] #> X3 | [-1.58, 1.42] #> X4 | [-1.36, 1.60] #> #> #> Parameter | 95% ETI #> ------------------------- #> X1 | [-1.85, 1.73] #> X2 | [-1.75, 2.24] #> X3 | [-1.74, 1.66] #> X4 | [-1.59, 1.74] #> #>
ci(df, method = "HDI", ci = c(.80, .89, .95))
#> # Highest Density Intervals #> #> Parameter | 80% HDI #> ------------------------- #> X1 | [-0.83, 1.49] #> X2 | [-0.98, 1.26] #> X3 | [-1.13, 1.27] #> X4 | [-1.22, 1.05] #> #> #> Parameter | 89% HDI #> ------------------------- #> X1 | [-1.23, 1.75] #> X2 | [-1.06, 1.91] #> X3 | [-1.56, 1.43] #> X4 | [-1.26, 1.69] #> #> #> Parameter | 95% HDI #> ------------------------- #> X1 | [-1.86, 1.75] #> X2 | [-1.93, 2.10] #> X3 | [-1.79, 1.67] #> X4 | [-1.59, 1.77] #> #>
if (FALSE) { if (require("rstanarm")) { model <- stan_glm(mpg ~ wt, data = mtcars, chains = 2, iter = 200, refresh = 0) ci(model, method = "ETI", ci = c(.80, .89)) ci(model, method = "HDI", ci = c(.80, .89)) ci(model, method = "SI") } if (require("brms")) { model <- brms::brm(mpg ~ wt + cyl, data = mtcars) ci(model, method = "ETI") ci(model, method = "HDI") ci(model, method = "SI") } if (require("BayesFactor")) { bf <- ttestBF(x = rnorm(100, 1, 1)) ci(bf, method = "ETI") ci(bf, method = "HDI") } if (require("emmeans")) { model <- emtrends(model, ~1, "wt") ci(model, method = "ETI") ci(model, method = "HDI") ci(model, method = "SI") } }