ci: Confidence/Credible/Compatibility Interval (CI) In DominiqueMakowski/bayestestR: Understand and Describe Bayesian Models and Posterior Distributions

Description

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

Usage

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54``` ```ci(x, ...) ## S3 method for class 'numeric' ci(x, ci = 0.95, method = "ETI", verbose = TRUE, BF = 1, ...) ## S3 method for class 'data.frame' ci(x, ci = 0.95, method = "ETI", verbose = TRUE, BF = 1, ...) ## S3 method for class 'sim.merMod' ci( x, ci = 0.95, method = "ETI", effects = c("fixed", "random", "all"), parameters = NULL, verbose = TRUE, ... ) ## S3 method for class 'sim' ci(x, ci = 0.95, method = "ETI", parameters = NULL, verbose = TRUE, ...) ## S3 method for class 'stanreg' ci( x, ci = 0.95, method = "ETI", effects = c("fixed", "random", "all"), component = c("location", "all", "conditional", "smooth_terms", "sigma", "distributional", "auxiliary"), parameters = NULL, verbose = TRUE, BF = 1, ... ) ## S3 method for class 'brmsfit' ci( x, ci = 0.95, method = "ETI", effects = c("fixed", "random", "all"), component = c("conditional", "zi", "zero_inflated", "all"), parameters = NULL, verbose = TRUE, BF = 1, ... ) ## S3 method for class 'BFBayesFactor' ci(x, ci = 0.95, method = "ETI", verbose = TRUE, BF = 1, ...) ## S3 method for class 'MCMCglmm' ci(x, ci = 0.95, 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 `.95` (`95%`). `method` Can be 'ETI' (default), 'HDI', 'BCI' 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.

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

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38``` ```library(bayestestR) posterior <- rnorm(1000) ci(posterior, method = "ETI") ci(posterior, method = "HDI") df <- data.frame(replicate(4, rnorm(100))) ci(df, method = "ETI", ci = c(.80, .89, .95)) ci(df, method = "HDI", ci = c(.80, .89, .95)) ## Not run: 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") } ## End(Not run) ```

DominiqueMakowski/bayestestR documentation built on July 27, 2021, 4:12 p.m.