This function compte the Bayes factors (BFs) that are appropriate to the
input. For vectors or single models, it will compute BFs for single parameters, or is hypothesis is specified,
BFs for restricted models. For multiple models,
it will return the BF corresponding to comparison between models and if a model comparison is passed, it will
compute the inclusion BF.
For a complete overview of these functions, read the Bayes factor vignette.
bayesfactor(
...,
prior = NULL,
direction = "two-sided",
null = 0,
hypothesis = NULL,
effects = "fixed",
verbose = TRUE,
denominator = 1,
match_models = FALSE,
prior_odds = NULL
)A numeric vector, model object(s), or the output from
bayesfactor_models.
An object representing a prior distribution (see 'Details').
Test type (see 'Details'). One of 0,
"two-sided" (default, two tailed), -1, "left" (left
tailed) or 1, "right" (right tailed).
Value of the null, either a scalar (for point-null) or a range (for a interval-null).
A character vector specifying the restrictions as logical conditions (see examples below).
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 with sd_ or
cor_).
"grouplevel" returns random effects group level estimates, i.e. those
parameters that start with r_.
"random" returns both "random_variance" and "grouplevel".
"all" returns fixed effects and random effects variances.
"full" returns all parameters.
Toggle off warnings.
Either an integer indicating which of the models to use as
the denominator, or a model to be used as a denominator. Ignored for
BFBayesFactor.
See details.
Optional vector of prior odds for the models. See
BayesFactor::priorOdds<-.
Some type of Bayes factor, depending on the input. See
bayesfactor_parameters(), bayesfactor_models() or bayesfactor_inclusion().
There is also a plot()-method implemented in the see-package.
if (FALSE) { # \dontrun{
library(bayestestR)
prior <- distribution_normal(1000, mean = 0, sd = 1)
posterior <- distribution_normal(1000, mean = 0.5, sd = 0.3)
bayesfactor(posterior, prior = prior, verbose = FALSE)
# rstanarm models
# ---------------
model <- suppressWarnings(rstanarm::stan_lmer(extra ~ group + (1 | ID), data = sleep))
bayesfactor(model, verbose = FALSE)
# Frequentist models
# ---------------
m0 <- lm(extra ~ 1, data = sleep)
m1 <- lm(extra ~ group, data = sleep)
m2 <- lm(extra ~ group + ID, data = sleep)
comparison <- bayesfactor(m0, m1, m2)
comparison
bayesfactor(comparison)
} # }