Two-process model where the numerator follows a beta-binomial distribution, allowing for overdispersion in binomial data. The denominator is the number of trials, which can be fixed or modelled.
Use cases:
Overdispersed proportions (e.g., infection rates across sites)
Hierarchical binomial with extra-binomial variation
Proportions with correlation within clusters
Details
The beta-binomial distribution arises when the success probability itself follows a beta distribution. This creates overdispersion (variance > binomial variance) and is useful when:
There is unmodelled heterogeneity in success probability
Observations within clusters are correlated
The binomial assumption of independent trials is violated
The overdispersion parameter \(\rho\) (intra-class correlation) ranges from 0 (binomial) to 1 (maximum overdispersion).
Examples
# Create family object
fam <- ratiod_beta_binomial()
print(fam)
#> tulpaRatio family: beta_binomial_fixed
#> Beta-binomial numerator with fixed denominator (overdispersed proportions)
#>
#> Numerator: beta_binomial(logit)
#> Denominator: fixed (fixed)
# Simulate overdispersed proportion data
set.seed(123)
n <- 40
df <- data.frame(
infected = rbinom(n, size = 20, prob = rbeta(n, 2, 5)),
tested = rep(20L, n),
treatment = factor(rep(c("control", "treated"), each = n/2)),
site = factor(rep(1:8, each = n/8))
)
if (FALSE) { # \dontrun{
# Fit model (slow, not run on CRAN)
fit <- tratio(
infected | tested ~ treatment + (1 | site),
data = df,
family = ratiod_beta_binomial(),
control = list(iter = 200, warmup = 100, chains = 1)
)
} # }