count_to_bf: Compute Bayes Factor Using Prior/Posterior Counts

View source: R/count_to.R

count_to_bfR Documentation

Compute Bayes Factor Using Prior/Posterior Counts

Description

Computes the encompassing Bayes factor (and standard error) defined as the ratio of posterior/prior samples that satisfy the order constraints (e.g., of a polytope).

Usage

count_to_bf(
  posterior,
  prior,
  exact_prior,
  log = FALSE,
  beta = c(1/2, 1/2),
  samples = 3000
)

Arguments

posterior

a vector (or matrix) with entries (or columns) count = number of posterior samples within polytope and M = total number of samples. See count_binom.

prior

a vecotr or matrix similar as for posterior, but based on samples from the prior distribution.

exact_prior

optional: the exact prior probabability of the order constraints. For instance, exact_prior=1/factorial(4) if pi1<pi2<pi3<pi4 (and if the prior is symmetric). If provided, prior is ignored.

log

whether to return the log-Bayes factor instead of the Bayes factor

beta

prior shape parameters of the beta distributions used for approximating the standard errors of the Bayes-factor estimates. The default is Jeffreys' prior.

samples

number of samples from beta distributions used to compute standard errors.

The unconstrained (encompassing) model is the saturated baseline model that assumes a separate, independent probability for each observable frequency. The Bayes factor is obtained as the ratio of posterior/prior samples within an order-constrained subset of the parameter space.

The standard error of the (stepwise) encompassing Bayes factor is estimated by sampling ratios from beta distributions, with parameters defined by the posterior/prior counts (see Hoijtink, 2011; p. 211).

Value

a matrix with two columns (Bayes factor and SE of approximation) and three rows:

  • `bf_0u`: constrained vs. unconstrained (saturated) model

  • `bf_u0`: unconstrained vs. constrained model

  • `bf_00'`: constrained vs. complement of inequality-constrained model (e.g., pi>.2 becomes pi<=.2; this assumes identical equality constraints for both models)

References

Hoijtink, H. (2011). Informative Hypotheses: Theory and Practice for Behavioral and Social Scientists. Boca Raton, FL: Chapman & Hall/CRC.

See Also

count_binom, count_multinom

Examples

# vector input
post <- c(count = 1447, M = 5000)
prior <- c(count = 152, M = 10000)
count_to_bf(post, prior)

# matrix input (due to nested stepwise procedure)
post <- cbind(count = c(139, 192), M = c(200, 1000))
count_to_bf(post, prior)

# exact prior probability known
count_to_bf(
  posterior = c(count = 1447, M = 10000),
  exact_prior = 1 / factorial(4)
)

multinomineq documentation built on Nov. 22, 2022, 5:09 p.m.