diversion_ratios: Compute aggregate diversion ratios

View source: R/methods.R

diversion_ratios.choicer_hbR Documentation

Compute aggregate diversion ratios

Description

Computes a J x J matrix of diversion ratios. Entry (i, j) is the fraction of demand lost by alternative j that is captured by alternative i when alternative j becomes less attractive.

Usage

## S3 method for class 'choicer_hb'
diversion_ratios(object, elast_var, eps = 0.01, n_draws = 100L, ...)

diversion_ratios(object, ...)

Arguments

object

A fitted model object.

elast_var

Structural covariate to perturb (hierarchical Bayes methods).

eps

Relative perturbation size (default 0.01).

n_draws

Number of posterior draws to integrate over.

...

Additional arguments passed to methods.

Value

A J x J diversion ratio matrix with alternative labels.

Methods (by class)

  • diversion_ratios(choicer_hb): Posterior-mean diversion ratios for hierarchical Bayes fits, from the same perturbation engine as elasticities.choicer_hb(): DR(j \to k) is the fraction of the share alternative j loses (when its elast_var worsens) that flows to k — including the outside option. Columns are the perturbed alternative j, rows the receiving alternative k; the diagonal is 0.

Examples


library(data.table)
set.seed(42)
N <- 50; J <- 3
dt <- data.table(id = rep(1:N, each = J), alt = rep(1:J, N))
dt[, `:=`(x1 = rnorm(.N), x2 = rnorm(.N))]
dt[, choice := 0L]
dt[, choice := sample(c(1L, rep(0L, J - 1))), by = id]
fit <- run_mnlogit(dt, "id", "alt", "choice", c("x1", "x2"))
diversion_ratios(fit)


choicer documentation built on Sept. 5, 2026, 1:07 a.m.