| mnl_elasticities_parallel | R Documentation |
Computes the aggregate elasticity matrix (weighted average of individual elasticities) for the Multinomial Logit model.
mnl_elasticities_parallel(
theta,
X,
alt_idx,
choice_idx,
M,
weights,
elast_var_idx,
use_asc = TRUE,
include_outside_option = FALSE
)
theta |
K + J - 1 or K + J vector with model parameters |
X |
sum(M) x K design matrix with covariates. |
alt_idx |
sum(M) x 1 vector with indices of alternatives; 1-based indexing |
choice_idx |
N x 1 vector (kept for API consistency, but not used) |
M |
N x 1 vector with number of alternatives for each individual |
weights |
N x 1 vector with weights for each observation |
elast_var_idx |
1-based index of the column in X for which to compute the elasticity |
use_asc |
whether to use alternative-specific constants |
include_outside_option |
whether to include outside option |
J x J matrix of aggregate elasticities
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"))
elas <- choicer:::mnl_elasticities_parallel(coef(fit), fit$data$X, fit$data$alt_idx,
fit$data$choice_idx, fit$data$M, fit$data$weights, elast_var_idx = 1L)
elas
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.