Skip to contents

Compute posterior distributions of contrasts (differences or ratios) between conditions for the derived ratio quantity.

Usage

ratio_contrast(
  object,
  contrast,
  type = c("difference", "ratio"),
  ref = NULL,
  ...
)

Arguments

object

A ratiod_fit object

contrast

A formula specifying the contrast, e.g., ~ treatment

type

Type of contrast: "difference" (default) or "ratio"

ref

Reference level for factor contrasts (default: first level)

...

Ignored

Value

A data frame with posterior summaries of contrasts

Examples

# \donttest{
# Generate synthetic data with grouping variable
set.seed(456)
n <- 60
df <- data.frame(
  count = rpois(n, lambda = 25),
  effort = rgamma(n, shape = 12, rate = 1),
  season = sample(c("summer", "winter"), n, replace = TRUE)
)

# Fit model
fit <- tratio(
  count | effort ~ season,
  data = df,
  family = ratiod_poisson_gamma(),
  mode = "hmc",
  control = list(iter = 200, warmup = 100, chains = 1)
)
#> Inference: Exact (Tier 1)
#>   Backend: hmc
#> Fitting ratio model...
#>   Family: poisson_gamma
#>   Observations: 60
#>   Iterations: 200 (warmup: 100)
#> Running NUTS sampler...
#>   Parameters: 5
#>   Iterations: 200 (warmup: 100)
#>   Chains: 1 (cores: 1)

# Compare CPUE between seasons
ratio_contrast(fit, ~ season)
#> tulpaRatio ratio contrasts
#> =====================
#> 
#> Type: difference 
#> Variable: season 
#> Reference: winter 
#> 
#>          contrast       mean       sd        q2.5       q50     q97.5
#>  summer vs winter 0.09773436 0.102406 -0.09660173 0.1063854 0.2893502
#>  prob_positive
#>            0.8

# Ratio of ratios (multiplicative comparison)
ratio_contrast(fit, ~ season, type = "ratio")
#> tulpaRatio ratio contrasts
#> =====================
#> 
#> Type: ratio 
#> Variable: season 
#> Reference: winter 
#> 
#>          contrast     mean        sd      q2.5      q50    q97.5 prob_positive
#>  summer vs winter 1.108385 0.1130709 0.9079263 1.112251 1.335559             1
# }