Skip to contents

Two-process model where the numerator follows a beta-binomial distribution, allowing for overdispersion in binomial data. The denominator is the known number of trials.

Use cases:

  • Overdispersed proportions (e.g., infection rates across sites)

  • Hierarchical binomial with extra-binomial variation

  • Proportions with correlation within clusters

Usage

ratiod_beta_binomial(link = "logit")

Arguments

Link function for the success probability: "logit" (default), "probit" or "cloglog".

Value

A ratiod_family object

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))
)

# \donttest{
# Fit model
fit <- tratio(
  infected | tested ~ treatment + (1 | site),
  data = df,
  family = ratiod_beta_binomial(),
  control = list(iter = 400, chains = 1, seed = 1)
)
summary(fit)
#> ratio model summary
#> ===================
#> 
#> Inference: Exact (Tier 1) via hmc
#> Family: beta_binomial_fixed 
#> 
#> Fixed effects (numerator):
#>             parameter   mean    sd   2.5%  97.5%  rhat ess_bulk
#>       num:(Intercept) -1.019 0.274 -1.596 -0.481 1.000       43
#>  num:treatmenttreated  0.294 0.373 -0.503  0.945 0.996       42
#> 
#> Variance components:
#>  parameter  mean    sd  2.5% 97.5%  rhat ess_bulk
#>   sigma_re 0.367 0.228 0.018 0.846 1.062       24
#> 
#> Other parameters:
#>  parameter mean    sd  2.5%  97.5%  rhat ess_bulk
#>        phi 12.9 6.112 5.005 30.681 1.011      119
#> 
#> Diagnostics:
#>   Divergences: 0 
#>   Avg. acceptance: 0.909 
#>   Chains: 1 
#>   Iterations: 400 
#>   Warmup: 200 
#>   R-hat > 1.01 for 2 parameter(s), largest 1.062 (sigma_re).
#>   Bulk ESS < 100 for 3 parameter(s), smallest 24 (sigma_re).
#>   Run longer chains or reparameterise before using these estimates.
# }