Skip to contents

Two-process model where both numerator and denominator follow negative binomial distributions. This is the core family for count-count ratios where both processes exhibit overdispersion.

Use cases:

  • Species counts / total counts (relative abundance)

  • Events / opportunities (both counts)

  • Any ratio where numerator and denominator are overdispersed counts

Usage

ratiod_negbin_negbin(link_num = "log", link_denom = "log")

Arguments

Link function for the numerator mean: "log".

Link function for the denominator mean: "log".

Value

A ratiod_family object

Examples

# Create family object
fam <- ratiod_negbin_negbin()
print(fam)
#> tulpaRatio family: negbin_negbin 
#> Negative binomial numerator, negative binomial denominator 
#> 
#> Numerator:  neg_binomial_2(log)
#> Denominator: neg_binomial_2 (log) 

# Simulate data for relative abundance
set.seed(123)
n <- 60
df <- data.frame(
  sp_count = rnbinom(n, size = 5, mu = 15),
  total_count = rnbinom(n, size = 8, mu = 100),
  habitat = factor(rep(c("forest", "grassland"), each = n/2)),
  site = factor(rep(1:10, each = n/10))
)

# \donttest{
# Fit model
fit <- tratio(
  sp_count | total_count ~ habitat + (1 | site),
  data = df,
  family = ratiod_negbin_negbin(),
  control = list(iter = 400, chains = 1, seed = 1)
)
summary(fit)
#> ratio model summary
#> ===================
#> 
#> Inference: Exact (Tier 1) via hmc
#> Family: negbin_negbin 
#> 
#> Fixed effects (numerator):
#>             parameter   mean    sd   2.5% 97.5%  rhat ess_bulk
#>       num:(Intercept)  2.615 0.112  2.427 2.872 1.046       58
#>  num:habitatgrassland -0.017 0.157 -0.394 0.264 1.040       47
#> 
#> Fixed effects (denominator):
#>               parameter   mean    sd   2.5% 97.5%  rhat ess_bulk
#>       denom:(Intercept)  4.669 0.106  4.493  4.96 1.000       38
#>  denom:habitatgrassland -0.032 0.163 -0.344  0.37 1.002       31
#> 
#> Variance components:
#>  parameter  mean    sd  2.5%  97.5%  rhat ess_bulk
#>  phi_denom 5.786 1.031 4.200  8.142 0.998      133
#>    phi_num 6.350 1.689 3.655 10.368 1.008      124
#>   sigma_re 0.111 0.084 0.003  0.302 1.025       17
#> 
#> Diagnostics:
#>   Divergences: 0 
#>   Avg. acceptance: 0.883 
#>   Chains: 1 
#>   Iterations: 400 
#>   Warmup: 200 
#>   R-hat > 1.01 for 3 parameter(s), largest 1.046 (num:(Intercept)).
#>   Bulk ESS < 100 for 5 parameter(s), smallest 17 (sigma_re).
#>   Run longer chains or reparameterise before using these estimates.
# }