Compute Confidence/Credible/Compatibility Intervals (CI) or Support Intervals (SI) for Bayesian and frequentist models. The Documentation is accessible for:
Usage
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", BF = 1, rvar_col = NULL, verbose = TRUE, ...)
# 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
orbrmsfit
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
0.95
(95%
).- method
- verbose
Toggle off warnings.
- BF
The amount of support required to be included in the support interval.
- rvar_col
A single character - the name of an
rvar
column in the data frame to be processed. See example inp_direction()
.- 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__
orprior_
) are filtered by default, so only parameters that typically appear in thesummary()
are returned. Useparameters
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), ifx
is a model-object. Ifx
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. 10.1136/bmj.l5381
Examples
library(bayestestR)
posterior <- rnorm(1000)
ci(posterior, method = "ETI")
#> 95% ETI: [-2.00, 1.96]
ci(posterior, method = "HDI")
#> 95% HDI: [-1.91, 2.03]
df <- data.frame(replicate(4, rnorm(100)))
ci(df, method = "ETI", ci = c(0.80, 0.89, 0.95))
#> Equal-Tailed Interval
#>
#> Parameter | 80% ETI | 89% ETI | 95% ETI
#> ---------------------------------------------------------
#> X1 | [-1.46, 1.35] | [-1.70, 1.63] | [-1.94, 1.94]
#> X2 | [-1.21, 1.34] | [-1.51, 1.71] | [-1.81, 2.08]
#> X3 | [-1.20, 1.19] | [-1.54, 1.48] | [-2.02, 1.71]
#> X4 | [-1.22, 1.51] | [-1.88, 1.61] | [-2.20, 1.82]
ci(df, method = "HDI", ci = c(0.80, 0.89, 0.95))
#> Highest Density Interval
#>
#> Parameter | 80% HDI | 89% HDI | 95% HDI
#> ---------------------------------------------------------
#> X1 | [-1.38, 1.37] | [-1.95, 1.37] | [-1.77, 2.17]
#> X2 | [-1.20, 1.35] | [-1.64, 1.52] | [-2.15, 1.80]
#> X3 | [-1.21, 1.17] | [-1.46, 1.56] | [-2.07, 1.72]
#> X4 | [-1.03, 1.52] | [-1.45, 1.74] | [-2.34, 1.71]
model <- suppressWarnings(
stan_glm(mpg ~ wt, data = mtcars, chains = 2, iter = 200, refresh = 0)
)
ci(model, method = "ETI", ci = c(0.80, 0.89))
#> Equal-Tailed Interval
#>
#> Parameter | 80% ETI | 89% ETI | Effects | Component
#> ---------------------------------------------------------------------
#> (Intercept) | [34.59, 39.93] | [34.12, 40.56] | fixed | conditional
#> wt | [-6.10, -4.52] | [-6.27, -4.33] | fixed | conditional
ci(model, method = "HDI", ci = c(0.80, 0.89))
#> Highest Density Interval
#>
#> Parameter | 80% HDI | 89% HDI
#> ---------------------------------------------
#> (Intercept) | [34.36, 39.67] | [34.20, 40.60]
#> wt | [-6.09, -4.51] | [-6.37, -4.47]
bf <- ttestBF(x = rnorm(100, 1, 1))
ci(bf, method = "ETI")
#> Equal-Tailed Interval
#>
#> Parameter | 95% ETI
#> -------------------------
#> Difference | [0.80, 1.23]
ci(bf, method = "HDI")
#> Highest Density Interval
#>
#> Parameter | 95% HDI
#> -------------------------
#> Difference | [0.81, 1.24]
model <- emtrends(model, ~1, "wt", data = mtcars)
ci(model, method = "ETI")
#> Equal-Tailed Interval
#>
#> X1 | 95% ETI
#> ------------------------
#> overall | [-6.37, -4.20]
ci(model, method = "HDI")
#> Highest Density Interval
#>
#> X1 | 95% HDI
#> ------------------------
#> overall | [-6.37, -4.18]