beta_binom: Fit a Binomial model with Beta priors

Description Usage Arguments Details Value Examples

View source: R/beta_binom.R

Description

Fits a Beta-Binomial model to a 2x2 table/matrix of two groups and two outcomes/features.

Usage

1
2
3
4
5
6
beta_binom(
  x,
  n = NULL,
  prior = c(a = 0.5, b = 0.5, c = 0.5, d = 0.5),
  n_sims = 10000
)

Arguments

x

A numeric vector of success counts OR a 2x2 table or matrix.

n

A numeric vector of totals. (Optional if x is a table or matrix.)

prior

Parameters for independent beta priors. See Details.

n_sims

Number of draws (simulations) to make from the posterior distributions.

Details

The model assumes

x_i ~ Binomial(n_i, p_i); p_1 ~ Beta(a, b); p_2 ~ Beta(c, d)

for i = 1, 2. The default is a = b = c = d = 1/2 which corresponds to a Jeffreys prior on p_1 and p_2.

Value

An S3 object of class "beta_binomial_fit". It has the following properties: posterior_simulations, posterior_parameters, successes, totals

Examples

1
2
3
4
5
6
fake_data <- matrix(c(200, 150, 250, 300), nrow = 2, byrow = TRUE)
colnames(fake_data) <- c('Safe' ,'Dangerous')
rownames(fake_data) <- c('Animals', 'Plants')
beta_binom(fake_data)

beta_binom(x = c(200, 250), n = c(350, 550))

bearloga/BCDA documentation built on Feb. 8, 2021, 3:43 p.m.