Skip to contents

Two-process model where both numerator and denominator follow gamma distributions. This is the natural family for ratios of positive continuous quantities.

Use cases:

  • Biomass ratios (species biomass / total biomass)

  • Concentration ratios (analyte / reference)

  • Duration ratios (time in activity / total time)

Usage

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

Arguments

Link function for the numerator mean: "log" (default), "identity" or "inverse".

Link function for the denominator mean: "log" (default), "identity" or "inverse".

Value

A ratiod_family object

Details

The gamma distribution is appropriate for positive continuous data with right skew. The ratio of two gamma random variables does not have a simple closed form, which is why ratio models them jointly.

Shape parameters are estimated for both numerator and denominator, allowing different amounts of variability in each process.

Examples

# Create family object
fam <- ratiod_gamma_gamma()
print(fam)
#> tulpaRatio family: gamma_gamma 
#> Gamma numerator, Gamma denominator (continuous ratios) 
#> 
#> Numerator:  gamma(log)
#> Denominator: gamma (log) 

# Simulate biomass ratio data
set.seed(123)
n <- 50
df <- data.frame(
  species_biomass = rgamma(n, shape = 3, rate = 0.5),
  total_biomass = rgamma(n, shape = 10, rate = 0.3),
  habitat = factor(rep(c("forest", "grassland"), each = n/2)),
  site = factor(rep(1:10, each = n/10))
)

# \donttest{
# Fit model
fit <- tratio(
  species_biomass | total_biomass ~ habitat + (1 | site),
  data = df,
  family = ratiod_gamma_gamma(),
  control = list(iter = 400, chains = 1, seed = 1)
)
summary(fit)
#> ratio model summary
#> ===================
#> 
#> Inference: Exact (Tier 1) via hmc
#> Family: gamma_gamma 
#> 
#> Fixed effects (numerator):
#>             parameter  mean    sd   2.5% 97.5%  rhat ess_bulk
#>       num:(Intercept) 1.587 0.127  1.334 1.828 0.998       52
#>  num:habitatgrassland 0.023 0.189 -0.362 0.396 1.007       63
#> 
#> Fixed effects (denominator):
#>               parameter  mean    sd   2.5% 97.5%  rhat ess_bulk
#>       denom:(Intercept) 3.478 0.093  3.315 3.674 1.041       31
#>  denom:habitatgrassland 0.106 0.142 -0.152 0.398 1.061       38
#> 
#> Variance components:
#>    parameter   mean    sd   2.5%  97.5%  rhat ess_bulk
#>  shape_denom 15.503 3.064 10.490 22.189 1.037      136
#>    shape_num  2.933 0.589  1.926  3.949 1.006      112
#>     sigma_re  0.114 0.065  0.013  0.252 1.074       12
#> 
#> Diagnostics:
#>   Divergences: 0 
#>   Avg. acceptance: 0.873 
#>   Chains: 1 
#>   Iterations: 400 
#>   Warmup: 200 
#>   R-hat > 1.01 for 4 parameter(s), largest 1.074 (sigma_re).
#>   Bulk ESS < 100 for 5 parameter(s), smallest 12 (sigma_re).
#>   Run longer chains or reparameterise before using these estimates.
# }