Skip to contents

Compute model-averaged predictions using stacking or pseudo-BMA weights. Model weights are derived from LOO-CV or WAIC, and predictions are combined accordingly.

Usage

ratiod_average(
  ...,
  weights = c("loo", "waic", "pbma", "pbma+"),
  newdata = NULL,
  type = c("ratio", "numerator", "denominator"),
  summary = TRUE
)

# S3 method for class 'ratiod_average'
print(x, digits = 3, ...)

# S3 method for class 'ratiod_average'
fitted(object, ...)

# S3 method for class 'ratiod_average'
weights(object, ...)

Arguments

...

Multiple ratiod_fit objects to average

weights

Method for computing weights: "loo" (stacking, default), "waic", "pbma" (pseudo-BMA), or "pbma+" (pseudo-BMA+ with Bayesian bootstrap).

newdata

Optional new data for predictions. If NULL, uses fitted values.

type

Type of prediction: "ratio" (default), "numerator", or "denominator".

summary

Logical; if TRUE (default), return summary statistics. If FALSE, return full posterior draws.

x

A ratiod_average object

digits

Number of digits for printing

object

A ratiod_average object

Value

A ratiod_average object containing:

  • weights: Model weights

  • predictions: Model-averaged predictions

  • models: List of model names

Predictions data frame or matrix

Named numeric vector of weights

Details

Model averaging accounts for model uncertainty by combining predictions from multiple candidate models. The weighting methods are:

  • stacking (weights = "loo"): Optimal linear combination minimizing leave-one-out prediction error. Recommended default.

  • pseudo-BMA (weights = "pbma"): Weights proportional to exp(-ELPD). Can be unstable with similar models.

  • pseudo-BMA+ (weights = "pbma+"): Bayesian bootstrap variant that accounts for estimation uncertainty.

For ratio predictions, averaging is performed on the log scale to respect the multiplicative nature of ratios.

See also

Examples

# \donttest{
sim <- sim_ratiod(n = 100, family = ratiod_poisson_gamma(), seed = 1)
fit <- tratio(y_num | y_denom ~ x1 + (1 | group), data = sim$data,
              family = ratiod_poisson_gamma(),
              control = list(iter = 1000, chains = 2, seed = 1))
fit0 <- tratio(y_num | y_denom ~ 1 + (1 | group), data = sim$data,
               family = ratiod_poisson_gamma(),
               control = list(iter = 1000, chains = 2, seed = 1))
avg <- ratiod_average(fit0, fit)
#> Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details.
avg
#> ratio model averaging
#> =====================
#> 
#> Method: loo 
#> Models: 2 
#> Prediction type: ratio 
#> 
#> Model weights:
#>   fit0: 0.063
#>   fit: 0.937
#> 
#> Predictions summary (first 6 rows):
#>   mean     sd q2.5  q25  q50  q75 q97.5
#> 1 1.85 0.1557 1.56 1.74 1.84 1.95  2.16
#> 2 1.69 0.0946 1.52 1.62 1.69 1.76  1.88
#> 3 1.65 0.0946 1.48 1.58 1.64 1.72  1.84
#> 4 1.54 0.1277 1.31 1.45 1.53 1.62  1.81
#> 5 1.47 0.1597 1.17 1.36 1.46 1.57  1.80
#> 6 1.55 0.1212 1.33 1.47 1.55 1.63  1.81
#>   ... 94 more rows
weights(avg)
#>       fit0        fit 
#> 0.06304897 0.93695103 
# }