| nl_diversion_ratios_parallel | R Documentation |
Computes the diversion ratio matrix DR(j->k) for the Nested Logit model. Entry (k, j) = fraction of demand lost by alternative j captured by k. Reduces to the MNL diversion ratios when all lambda = 1.
nl_diversion_ratios_parallel(
theta,
X,
alt_idx,
nest_idx,
M,
weights,
use_asc = TRUE,
include_outside_option = FALSE
)
theta |
(K + n_non_singleton_nests + n_delta) vector with model
parameters. Order: |
X |
sum(M) x K design matrix with covariates. |
alt_idx |
sum(M) x 1 vector with indices of alternatives; 1-based indexing. |
nest_idx |
J x 1 vector with nest indices for each alternative; 1-based indexing. |
M |
N x 1 vector with number of alternatives for each individual. |
weights |
N x 1 vector with weights for each observation. |
use_asc |
whether to use alternative-specific constants. |
include_outside_option |
whether to include outside option normalized to V=0, lambda=1. |
J x J matrix where entry (k, j) = DR(j->k). Diagonal is 0.
library(data.table)
set.seed(42)
N <- 50; J <- 4
dt <- data.table(id = rep(1:N, each = J), alt = rep(1:J, N))
dt[, `:=`(x1 = rnorm(.N), x2 = rnorm(.N))]
dt[, nest := ifelse(alt <= 2, "A", "B")]
dt[, choice := 0L]
dt[, choice := sample(c(1L, rep(0L, J - 1))), by = id]
fit <- run_nestlogit(dt, "id", "alt", "choice", c("x1", "x2"), "nest")
dr <- choicer:::nl_diversion_ratios_parallel(coef(fit), fit$data$X, fit$data$alt_idx,
fit$data$nest_idx, fit$data$M, fit$data$weights)
dr
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.