| mxl_bhhh_parallel | R Documentation |
Computes the BHHH approximation to the observed information matrix for the
Mixed Logit model: H_{BHHH} = \sum_i w_i \cdot s_i s_i^\top, where
s_i is the per-individual score (gradient of \log \bar{P}_i).
This outer product of gradients (OPG) estimator provides an alternative to
the analytical Hessian for standard error computation that scales to large
problems where the analytical Hessian is infeasible (e.g., many alternatives
or simulation draws).
mxl_bhhh_parallel(
theta,
X,
W,
alt_idx,
choice_idx,
M,
weights,
eta_draws,
rc_dist,
rc_correlation = TRUE,
rc_mean = FALSE,
use_asc = TRUE,
include_outside_option = FALSE,
gen_seed = -1L,
gen_scramble = 1L,
gen_S = 0L
)
theta |
vector collecting model parameters (beta, mu, L, delta (ASCs)) |
X |
design matrix for covariates with fixed coefficients; sum(M_i) x K_x |
W |
design matrix for covariates with random coefficients; sum(M_i) x K_w or J x K_w |
alt_idx |
sum(M) x 1 vector with indices of alternatives within each choice set; 1-based indexing |
choice_idx |
N x 1 vector with indices of chosen alternatives; 1-based indexing relative to X; 0 is used if include_outside_option=True |
M |
N x 1 vector with number of alternatives for each individual |
weights |
N x 1 vector with weights for each observation |
eta_draws |
Array with choice situation draws; K_w x S x N |
rc_dist |
K_w x 1 integer vector indicating distribution of random coefficients: 0 = normal, 1 = log-normal |
rc_correlation |
whether random coefficients should be correlated |
rc_mean |
whether to estimate means for random coefficients. |
use_asc |
whether to use alternative-specific constants. |
include_outside_option |
whether to include outside option normalized to 0 (if so, the outside option is not included in the data) |
gen_seed |
Integer master seed for the on-the-fly Halton generator. |
gen_scramble |
Integer scramble mode for on-the-fly generation: |
gen_S |
Integer number of draws per individual, used only when |
n_params x n_params PSD matrix representing the observed information
matrix estimated by the outer product of gradients (same sign convention
as the negated Hessian returned by mxl_hessian_parallel, so it can
be inverted directly to obtain vcov).
The BHHH/OPG estimator is only asymptotically equivalent to the Hessian-based information matrix at the true MLE. In finite samples it can underestimate standard errors, particularly when the model is mis-specified or away from the optimum.
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), w1 = rnorm(.N))]
dt[, choice := 0L]
dt[, choice := sample(c(1L, rep(0L, J - 1))), by = id]
d <- prepare_mxl_data(dt, "id", "alt", "choice", "x1", "w1")
eta <- get_halton_normals(50, d$N, ncol(d$W))
theta <- rep(0, ncol(d$X) + ncol(d$W) + nrow(d$alt_mapping) - 1)
H <- choicer:::mxl_bhhh_parallel(theta, d$X, d$W, d$alt_idx, d$choice_idx,
d$M, d$weights, eta, rc_dist = rep(0L, ncol(d$W)),
rc_correlation = FALSE, rc_mean = FALSE)
dim(H)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.