| wesml_vcov | R Documentation |
Recomputes the robust Huber-White sandwich variance
V = A^{-1} B A^{-1} for a fitted multinomial (MNL), mixed (MXL) or
nested (NL) logit, where the bread
A = \sum_i w_i (-H_i) is the weighted negated Hessian and the meat
B = \sum_i w_i^2 s_i s_i' is the weight-squared outer product of the
per-individual scores. This is the appropriate variance under choice-based
(endogenous stratified) / WESML weighting, where the inverse-Hessian and the
ordinary BHHH variance are invalid. It can be called on any fitted model
(e.g. one estimated with se_method = "hessian") to obtain robust
standard errors post hoc, without refitting.
wesml_vcov(object, ...)
## S3 method for class 'choicer_mxl'
wesml_vcov(object, type = c("vcov", "se"), ...)
## S3 method for class 'choicer_mnl'
wesml_vcov(object, type = c("vcov", "se"), ...)
## S3 method for class 'choicer_nl'
wesml_vcov(object, type = c("vcov", "se"), ...)
object |
A fitted |
... |
Unused. |
type |
Either |
If the stored weights are uniform (all equal), a warning is emitted: the returned variance is then the ordinary robust (Huber-White) variance, not a WESML-weighted variance. Refit with WESML weights for a choice-based-sampling correction.
A variance-covariance matrix (type = "vcov") or a named
numeric vector of standard errors (type = "se"), in the raw
parameter space.
wesml_weights, sample_by_choice,
run_mxlogit
library(data.table)
set.seed(1)
N <- 200L; J <- 3L
dt <- data.table(id = rep(seq_len(N), each = J), alt = rep(1:J, N))
dt[, `:=`(x1 = rnorm(.N), w1 = rnorm(.N))]
dt[, choice := as.integer(seq_len(.N) == sample.int(.N, 1L)), by = id]
fit <- run_mxlogit(dt, "id", "alt", "choice", "x1", "w1", S = 50L)
wesml_vcov(fit, "se")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.