binom_bf_inequality {multibridge} | R Documentation |
Computes Bayes Factors For Inequality Constrained Independent Binomial Parameters
Description
Computes Bayes factor for inequality constrained binomial parameters using a bridge sampling routine.
Restricted hypothesis H_r
states that binomial proportions follow a particular trend.
Alternative hypothesis H_e
states that binomial proportions are free to vary.
Usage
binom_bf_inequality(
samples = NULL,
restrictions = NULL,
x = NULL,
n = NULL,
Hr = NULL,
a = rep(1, ncol(samples)),
b = rep(1, ncol(samples)),
factor_levels = NULL,
prior = FALSE,
index = 1,
maxiter = 1000,
seed = NULL,
niter = 5000,
nburnin = niter * 0.05
)
Arguments
samples |
matrix of dimension ( |
restrictions |
|
x |
a vector of counts of successes, or a two-dimensional table (or matrix) with 2 columns, giving the counts of successes and failures, respectively |
n |
numeric. Vector of counts of trials. Must be the same length as |
Hr |
string or character. Encodes the user specified informed hypothesis. Use either specified |
a |
numeric. Vector with alpha parameters. Must be the same length as |
b |
numeric. Vector with beta parameters. Must be the same length as |
factor_levels |
character. Vector with category names. Must be the same length as |
prior |
logical. If |
index |
numeric. Index of current restriction. Default is 1 |
maxiter |
numeric. Maximum number of iterations for the iterative updating scheme used in the bridge sampling routine. Default is 1,000 to avoid infinite loops |
seed |
numeric. Sets the seed for reproducible pseudo-random number generation |
niter |
numeric. Vector with number of samples to be drawn from truncated distribution |
nburnin |
numeric. A single value specifying the number of burn-in samples when drawing from the truncated distribution. Minimum number of burn-in samples is 10. Default is 5% of the number of samples. Burn-in samples are removed automatically after the sampling. |
Details
The model assumes that the data in x
(i.e., x_1, ..., x_K
) are the observations of K
independent
binomial experiments, based on n_1, ..., n_K
observations. Hence, the underlying likelihood is the product of the
k = 1, ..., K
individual binomial functions:
(x_1, ... x_K) ~ \prod Binomial(N_k, \theta_k)
Furthermore, the model assigns a beta distribution as prior to each model parameter (i.e., underlying binomial proportions). That is:
\theta_k ~ Beta(\alpha_k, \beta_k)
Value
List consisting of the following elements:
$eval
-
-
q11
: log prior or posterior evaluations for prior or posterior samples -
q12
: log proposal evaluations for prior or posterior samples -
q21
: log prior or posterior evaluations for samples from proposal -
q22
: log proposal evaluations for samples from proposal
-
$niter
number of iterations of the iterative updating scheme
$logml
estimate of log marginal likelihood
$hyp
evaluated inequality constrained hypothesis
$error_measures
-
-
re2
: the approximate relative mean-squared error for the marginal likelihood estimate -
cv
: the approximate coefficient of variation for the marginal likelihood estimate (assumes that bridge estimate is unbiased) -
percentage
: the approximate percentage error of the marginal likelihood estimate
-
Note
The following signs can be used to encode restricted hypotheses: "<"
and ">"
for inequality constraints, "="
for equality constraints,
","
for free parameters, and "&"
for independent hypotheses. The restricted hypothesis can either be a string or a character vector.
For instance, the hypothesis c("theta1 < theta2, theta3")
means
-
theta1
is smaller than boththeta2
andtheta3
The parameters
theta2
andtheta3
both havetheta1
as lower bound, but are not influenced by each other.
The hypothesis c("theta1 < theta2 = theta3 & theta4 > theta5")
means that
Two independent hypotheses are stipulated:
"theta1 < theta2 = theta3"
and"theta4 > theta5"
The restrictions on the parameters
theta1
,theta2
, andtheta3
do not influence the restrictions on the parameterstheta4
andtheta5
.-
theta1
is smaller thantheta2
andtheta3
-
theta2
andtheta3
are assumed to be equal -
theta4
is larger thantheta5
References
Gronau QF, Sarafoglou A, Matzke D, Ly A, Boehm U, Marsman M, Leslie DS, Forster JJ, Wagenmakers E, Steingroever H (2017). “A tutorial on bridge sampling.” Journal of Mathematical Psychology, 81, 80–97.
Sarafoglou A, Haaf JM, Ly A, Gronau QF, Wagenmakers EJ, Marsman M (2021). “Evaluating Multinomial Order Restrictions with Bridge Sampling.” Psychological Methods.
See Also
Other functions to evaluate informed hypotheses:
binom_bf_equality()
,
binom_bf_informed()
,
mult_bf_equality()
,
mult_bf_inequality()
,
mult_bf_informed()
Examples
# priors
a <- c(1, 1, 1, 1)
b <- c(1, 1, 1, 1)
# informed hypothesis
factor_levels <- c('theta1', 'theta2', 'theta3', 'theta4')
Hr <- c('theta1', '<', 'theta2', '<', 'theta3', '<', 'theta4')
results_prior <- binom_bf_inequality(Hr=Hr, a=a, b=b,
factor_levels=factor_levels, prior=TRUE, seed = 2020)
# corresponds to
cbind(exp(results_prior$logml), 1/factorial(4))
# alternative - if you have samples and a restriction list
inequalities <- generate_restriction_list(Hr=Hr, a=a,b=b,
factor_levels=factor_levels)$inequality_constraints
prior_samples <- binom_tsampling(inequalities, niter = 2e3,
prior=TRUE, seed = 2020)
results_prior <- binom_bf_inequality(prior_samples, inequalities, seed=2020)
cbind(exp(results_prior$logml), 1/factorial(4))