bayesfactor_restricted {bayestestR}R Documentation

Bayes Factors (BF) for Order Restricted Models

Description

This method computes Bayes factors for comparing a model with an order restrictions on its parameters with the fully unrestricted model. Note that this method should only be used for confirmatory analyses.

The bf_* function is an alias of the main function.

For more info, in particular on specifying correct priors for factors with more than 2 levels, see the Bayes factors vignette.

Usage

bayesfactor_restricted(
  posterior,
  hypothesis,
  prior = NULL,
  verbose = TRUE,
  ...
)

bf_restricted(posterior, hypothesis, prior = NULL, verbose = TRUE, ...)

## S3 method for class 'stanreg'
bayesfactor_restricted(
  posterior,
  hypothesis,
  prior = NULL,
  verbose = TRUE,
  effects = c("fixed", "random", "all"),
  component = c("conditional", "zi", "zero_inflated", "all"),
  ...
)

## S3 method for class 'brmsfit'
bayesfactor_restricted(
  posterior,
  hypothesis,
  prior = NULL,
  verbose = TRUE,
  effects = c("fixed", "random", "all"),
  component = c("conditional", "zi", "zero_inflated", "all"),
  ...
)

## S3 method for class 'blavaan'
bayesfactor_restricted(
  posterior,
  hypothesis,
  prior = NULL,
  verbose = TRUE,
  ...
)

## S3 method for class 'emmGrid'
bayesfactor_restricted(
  posterior,
  hypothesis,
  prior = NULL,
  verbose = TRUE,
  ...
)

Arguments

posterior

A stanreg / brmsfit object, emmGrid or a data frame - representing a posterior distribution(s) from (see Details).

hypothesis

A character vector specifying the restrictions as logical conditions (see examples below).

prior

An object representing a prior distribution (see Details).

verbose

Toggle off warnings.

...

Currently not used.

effects

Should results for fixed effects, random effects or both be returned? Only applies to mixed models. May be abbreviated.

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.

Details

This method is used to compute Bayes factors for order-restricted models vs un-restricted models by setting an order restriction on the prior and posterior distributions (Morey & Wagenmakers, 2013).

(Though it is possible to use bayesfactor_restricted() to test interval restrictions, it is more suitable for testing order restrictions; see examples).

Value

A data frame containing the (log) Bayes factor representing evidence against the un-restricted model.

Setting the correct prior

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); As the priors for the alternative get wider, the likelihood of the null value(s) increases, to the extreme that for completely flat priors the null is infinitely more favorable than the alternative (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.

(Note that by default, brms::brm() uses flat priors for fixed-effects; See example below.)

It is important to provide the correct prior for meaningful results.

Interpreting Bayes Factors

A Bayes factor greater than 1 can be interpreted as evidence against the null, at which one convention is that a Bayes factor greater than 3 can be considered as "substantial" evidence against the null (and vice versa, a Bayes factor smaller than 1/3 indicates substantial evidence in favor of the null-model) (Wetzels et al. 2011).

References

Examples

library(bayestestR)
prior <- data.frame(
  X = rnorm(100),
  X1 = rnorm(100),
  X3 = rnorm(100)
)

posterior <- data.frame(
  X = rnorm(100, .4),
  X1 = rnorm(100, -.2),
  X3 = rnorm(100)
)

hyps <- c(
  "X > X1 & X1 > X3",
  "X > X1"
)

bayesfactor_restricted(posterior, hypothesis = hyps, prior = prior)
## Not run: 
# rstanarm models
# ---------------
if (require("rstanarm") && require("emmeans")) {
  fit_stan <- stan_glm(mpg ~ wt + cyl + am,
    data = mtcars, refresh = 0
  )
  hyps <- c(
    "am > 0 & cyl < 0",
    "cyl < 0",
    "wt - cyl > 0"
  )
  bayesfactor_restricted(fit_stan, hypothesis = hyps)

  # emmGrid objects
  # ---------------
  # replicating http://bayesfactor.blogspot.com/2015/01/multiple-comparisons-with-bayesfactor-2.html
  disgust_data <- read.table(url("http://www.learnbayes.org/disgust_example.txt"), header = TRUE)

  contrasts(disgust_data$condition) <- contr.orthonorm # see vignette
  fit_model <- stan_glm(score ~ condition, data = disgust_data, family = gaussian())

  em_condition <- emmeans(fit_model, ~condition)
  hyps <- c("lemon < control & control < sulfur")

  bayesfactor_restricted(em_condition, prior = fit_model, hypothesis = hyps)
  # > # Bayes Factor (Order-Restriction)
  # >
  # >                          Hypothesis P(Prior) P(Posterior)   BF
  # >  lemon < control & control < sulfur     0.17         0.75 4.49
  # > ---
  # > Bayes factors for the restricted model vs. the un-restricted model.
}

## End(Not run)

[Package bayestestR version 0.10.0 Index]