A support interval contains only the values of the parameter that predict the observed data better
than average, by some degree k; these are values of the parameter that are associated with an
updating factor greater or equal than k. From the perspective of the Savage-Dickey Bayes factor, testing
against a point null hypothesis for any value within the support interval will yield a Bayes factor smaller
than 1/k.
For more info, see the Bayes factors vignette.
Usage
si(posterior, ...)
# S3 method for class 'numeric'
si(posterior, prior = NULL, BF = 1, verbose = TRUE, ...)
# S3 method for class 'stanreg'
si(
posterior,
prior = NULL,
BF = 1,
verbose = TRUE,
effects = "fixed",
component = "location",
parameters = NULL,
...
)
# S3 method for class 'get_predicted'
si(
posterior,
prior = NULL,
BF = 1,
use_iterations = FALSE,
verbose = TRUE,
...
)
# S3 method for class 'data.frame'
si(posterior, prior = NULL, BF = 1, rvar_col = NULL, verbose = TRUE, ...)Arguments
- posterior
A numerical vector,
stanreg/brmsfitobject,emmGridor a data frame - representing a posterior distribution(s) from (see 'Details').- ...
Arguments passed to and from other methods. (Can be used to pass arguments to internal
logspline::logspline().)- prior
An object representing a prior distribution (see 'Details').
- BF
The amount of support required to be included in the support interval.
- verbose
Toggle off warnings.
- effects
Should variables for fixed effects (
"fixed"), random effects ("random") or both ("all") be returned? Only applies to mixed models. May be abbreviated.For models of from packages brms or rstanarm there are additional options:
"fixed"returns fixed effects."random_variance"return random effects parameters (variance and correlation components, e.g. those parameters that start withsd_orcor_)."grouplevel"returns random effects group level estimates, i.e. those parameters that start withr_."random"returns both"random_variance"and"grouplevel"."all"returns fixed effects and random effects variances."full"returns all parameters.
- component
Which type of parameters to return, such as parameters for the conditional model, the zero-inflated part of the model, the dispersion term, etc. See details in section Model Components. May be abbreviated. Note that the conditional component also refers to the count or mean component - names may differ, depending on the modeling package. There are three convenient shortcuts (not applicable to all model classes):
component = "all"returns all possible parameters.If
component = "location", location parameters such asconditional,zero_inflated,smooth_terms, orinstrumentsare returned (everything that are fixed or random effects - depending on theeffectsargument - but no auxiliary parameters).For
component = "distributional"(or"auxiliary"), components likesigma,dispersion,betaorprecision(and other auxiliary parameters) are returned.
- 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. Useparametersto select specific parameters for the output.- use_iterations
Logical, if
TRUEandxis aget_predictedobject, (returned byinsight::get_predicted()), the function is applied to the iterations instead of the predictions. This only applies to models that return iterations for predicted values (e.g.,brmsfitmodels).- rvar_col
A single character - the name of an
rvarcolumn in the data frame to be processed. See example inp_direction().
Value
A data frame containing the lower and upper bounds of the SI.
Note that if the level of requested support is higher than observed in the data, the
interval will be [NA,NA].
Details
This method is used to compute support intervals based on prior and posterior distributions.
Note
There is also a plot()-method implemented in the see-package.
Choosing a value of BF
The choice of BF (the level of support) depends on what we want our interval
to represent:
A
BF= 1 contains values whose credibility is not decreased by observing the data.A
BF> 1 contains values who received more impressive support from the data.A
BF< 1 contains values whose credibility has not been impressively decreased by observing the data. Testing against values outside this interval will produce a Bayes factor larger than 1/BFin support of the alternative. E.g., if an SI (BF = 1/3) excludes 0, the Bayes factor against the point-null will be larger than 3.
Prior and posterior considerations
In order to correctly and precisely estimate Bayes factors, a rule of thumb
are the 4 P's: Proper Priors and Plentiful
Posteriors.
For the computation of Bayes factors, the model priors must be proper priors
(at the very least they should be not flat, and it is preferable that they
be informative) (Note that by default, brms::brm() uses flat priors for
fixed-effects); Wide priors result in smaller marginal likelihoods, and thus
models with wider priors are trivially less likely than models with narrower
priors - where, at the extreme, that a model with completely flat priors is
infinitely less favorable than a point null model (this is called the
Jeffreys-Lindley-Bartlett paradox). Thus, you should only ever try (or want)
to compute a Bayes factor when you have an informed prior.
Additionally, for models using MCMC estimation the number of posterior
samples needed for testing is substantially larger than for estimation (the
default of 4000 samples may not be enough in many cases). A conservative rule
of thumb is to obtain 10 times more samples than would be required for
estimation (Gronau, Singmann, & Wagenmakers, 2017). If less than 40,000
samples are detected, a warning is issued.
Obtaining prior samples
It is important to provide the correct prior for meaningful results,
to match the posterior-type input:
A numeric vector -
priorshould also be a numeric vector, representing the prior-distributionA data frame -
priorshould also be a data frame, representing the prior-estimates, in matching column order.If
rvar_colis specified,priorshould be the name of anrvarcolumn that represents the prior-estimates.
Supported Bayesian model (
stanreg,brmsfit, etc.)priorshould be a model an equivalent model with MCMC samples from the priors only. Seeunupdate().If
prioris set toNULL,unupdate()is called internally (not supported forbrmsfit_multiplemodel).
Output from a
{marginaleffects}function -priorshould also be an equivalent output from a{marginaleffects}function based on a prior-model (Seeunupdate()).Output from an
{emmeans}functionpriorshould also be an equivalent output from an{emmeans}function based on a prior-model (Seeunupdate()).priorcan also be the original (posterior) model, in which case the function will try to "unupdate" the estimates (not supported if the estimates have undergone any transformations –"log","response", etc. – or anyregriding).
References
Wagenmakers, E., Gronau, Q. F., Dablander, F., & Etz, A. (2018, November 22). The Support Interval. doi:10.31234/osf.io/zwnxb
Examples
library(bayestestR)
prior <- distribution_normal(1000, mean = 0, sd = 1)
posterior <- distribution_normal(1000, mean = 0.5, sd = 0.3)
si(posterior, prior, verbose = FALSE)
#> BF = 1 SI: [0.04, 1.04]
# \donttest{
# rstanarm models
# ---------------
library(rstanarm)
contrasts(sleep$group) <- contr.equalprior_pairs # see vignette
stan_model <- stan_lmer(extra ~ group + (1 | ID), data = sleep)
#>
#> SAMPLING FOR MODEL 'continuous' NOW (CHAIN 1).
#> Chain 1:
#> Chain 1: Gradient evaluation took 2.9e-05 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.29 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.191 seconds (Warm-up)
#> Chain 1: 0.195 seconds (Sampling)
#> Chain 1: 0.386 seconds (Total)
#> Chain 1:
#>
#> SAMPLING FOR MODEL 'continuous' NOW (CHAIN 2).
#> Chain 2:
#> Chain 2: Gradient evaluation took 1.5e-05 seconds
#> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.15 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.199 seconds (Warm-up)
#> Chain 2: 0.176 seconds (Sampling)
#> Chain 2: 0.375 seconds (Total)
#> Chain 2:
#>
#> SAMPLING FOR MODEL 'continuous' NOW (CHAIN 3).
#> Chain 3:
#> Chain 3: Gradient evaluation took 5.8e-05 seconds
#> Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0.58 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.169 seconds (Warm-up)
#> Chain 3: 0.253 seconds (Sampling)
#> Chain 3: 0.422 seconds (Total)
#> Chain 3:
#>
#> SAMPLING FOR MODEL 'continuous' NOW (CHAIN 4).
#> Chain 4:
#> Chain 4: Gradient evaluation took 1.6e-05 seconds
#> Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0.16 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.169 seconds (Warm-up)
#> Chain 4: 0.185 seconds (Sampling)
#> Chain 4: 0.354 seconds (Total)
#> Chain 4:
si(stan_model, verbose = FALSE)
#> Support Interval
#>
#> Parameter | BF = 1 SI | Effects | Component
#> --------------------------------------------------
#> (Intercept) | [0.41, 2.72] | fixed | conditional
#> group1 | [0.44, 2.75] | fixed | conditional
si(stan_model, BF = 3, verbose = FALSE)
#> Support Interval
#>
#> Parameter | BF = 3 SI | Effects | Component
#> --------------------------------------------------
#> (Intercept) | [0.83, 2.33] | fixed | conditional
#> group1 | [0.66, 2.44] | fixed | conditional
# emmGrid objects
# ---------------
library(emmeans)
group_diff <- pairs(emmeans(stan_model, ~group))
si(group_diff, prior = stan_model, verbose = FALSE)
#> Support Interval
#>
#> contrast | BF = 1 SI
#> --------------------------------
#> group1 - group2 | [-2.76, -0.34]
# brms models
# -----------
library(brms)
contrasts(sleep$group) <- contr.equalprior_pairs # see vingette
my_custom_priors <-
set_prior("student_t(3, 0, 1)", class = "b") +
set_prior("student_t(3, 0, 1)", class = "sd", group = "ID")
brms_model <- suppressWarnings(brm(extra ~ group + (1 | ID),
data = sleep,
prior = my_custom_priors,
refresh = 0
))
#> Compiling Stan program...
#> Start sampling
si(brms_model, verbose = FALSE)
#> Support Interval
#>
#> Parameter | BF = 1 SI | Effects | Component
#> --------------------------------------------------
#> b_Intercept | [0.65, 2.47] | fixed | conditional
#> b_group1 | [0.70, 2.43] | fixed | conditional
# }
