binom_tsampling: Samples From Truncated Beta Densities

View source: R/bmult_sampling_binom.R

binom_tsamplingR Documentation

Samples From Truncated Beta Densities

Description

Based on specified inequality constraints, samples from truncated prior or posterior beta densities.

Usage

binom_tsampling(
  inequalities,
  index = 1,
  niter = 10000,
  prior = FALSE,
  nburnin = niter * 0.05,
  seed = NULL
)

Arguments

inequalities

list that contains inequality constraints for each independent inequality constrained hypotheses. The list is created in the generate_restriction_list function

index

numeric. If multiple independent inequality constraints are specified, this index determines for which inequality constraint samples should be drawn. Must be a single value. Default is 1

niter

numeric. A single value specifying the number of samples. Default is set to 10,000

prior

logical. If TRUE ignores the data that are encoded in inequalities and thus samples from the prior distribution. Default is FALSE.

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.

seed

numeric. Sets the seed for reproducible pseudo-random number generation

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) ~ ∏ Binomial(N_k, θ_k)

Furthermore, the model assigns a beta distribution as prior to each model parameter (i.e., underlying binomial proportions). That is:

θ_k ~ Beta(α_k, β_k)

Value

matrix of dimension niter * nsamples containing samples from truncated beta distributions.

Note

When equality constraints are specified in the restricted hypothesis, this function samples from the conditional Beta distributions given that the equality constraints hold.

Only inequality constrained parameters are sampled. Free parameters or parameters that are exclusively equality constrained will be ignored.

References

\insertRef

damien2001samplingmultibridge

See Also

generate_restriction_list

Examples

x <- c(200, 130, 40, 10)
n <- c(200, 200, 200, 200)
a <- c(1, 1, 1, 1)
b <- c(1, 1, 1, 1)
factor_levels <- c('binom1', 'binom2', 'binom3', 'binom4')
Hr <- c('binom1 > binom2 > binom3 > binom4')

# generate restriction list
inequalities <- generate_restriction_list(x=x, n=n, Hr=Hr, a=a, b=b, 
factor_levels=factor_levels)$inequality_constraints

# sample from prior distribution
prior_samples <- binom_tsampling(inequalities, niter = 500, 
prior=TRUE)
# sample from posterior distribution
post_samples <- binom_tsampling(inequalities, niter = 500)

multibridge documentation built on Nov. 1, 2022, 5:05 p.m.