BayesianFirstAid (version 0.1)

bayes.binom.test: Bayesian First Aid Alternative to the Binomial Test

Description

bayes.binom.test estimates the relative frequency of success using Bayesian estimation and is intended as a replacement for binom.test.

Usage

bayes.binom.test(x, n, comp.theta = 0.5, alternative = NULL, cred.mass = 0.95, n.iter = 15000, progress.bar = "none", p, conf.level)

Arguments

x
number of successes, or a vector of length 2 giving the numbers of successes and failures, respectively.
n
number of trials; ignored if x has length 2.
comp.theta
a fixed relative frequency of success to compare with the estimated relative frequency of success. This argument fills a similar role as p in binom.test.
alternative
ignored and is only retained in order to mantain compatibility with binom.test.
cred.mass
the amount of probability mass that will be contained in reported credible intervals. This argument fills a similar role as conf.level in binom.test.
n.iter
The number of iterations to run the MCMC sampling.
progress.bar
The type of progress bar. Possible values are "text", "gui", and "none".
p
same as comp.theta and is only retained in order to mantain compatibility with binom.test.
conf.level
same as cred.mass and is only retained in order to mantain compatibility with binom.test.

Value

A list of class bayes_binom_test that contains information about the analysis. It can be further inspected using the functions summary, plot, diagnostics and model.code.

Details

Given data on the number of successes and failures bayes.binom.test estimates $\theta$, the relative frequency of success, assuming the following model:

$$x \sim \mathrm{Binom}(\theta, n)$$ $$\theta \sim \mathrm{Beta}(1, 1)$$

binom_diagram.svgoptions: height=250

Here the prior on $\theta$ is a non-informative $Beta(1, 1)$ distribution which is identical to a $Uniform(0, 1)$ distribution. By ploting and looking at a summary of the object returned by bayes.binom.test you can get more information about the shape of the posterior and the posterior predictive distribution. model.code prints out the corresponding R code underlying bayes.binom.test which can be copy-n-pasted into an R script and modified, for example, changing the prior on $\theta$.

Examples

Run this code
# A college dormitory recently sponsored a taste comparison between
# two major soft drinks. Of the 64 students who participated, 39 selected
# brand A, and only 25 selected brand B. Example from
# http://www.elderlab.yorku.ca/~aaron/Stats2022/BinomialTest.htm

bayes.binom.test(x = 39, n = 64)

# Save the return value in order to inspect the model result further.
fit <- bayes.binom.test(x = 39, n = 64, cred.mass=0.8)
summary(fit)
plot(fit)

# MCMC diagnostics (should not be necessary for such a simple model)
diagnostics(fit)

# Print out the R code to run the model. This can be copy n' pasted into
# an R-script and further modified.
model.code(fit)

Run the code above in your browser using DataLab