| vcov.choicer_fit | R Documentation |
With no arguments, returns the variance-covariance matrix implied by the
fit's own se_method (triggering lazy computation if needed). Passing
type recomputes a different variance estimator post hoc from the
stored data — no refit needed (requires keep_data = TRUE):
"hessian"Inverse of the analytical negated Hessian.
"bhhh"Inverse of the BHHH/OPG information
\sum_i w_i s_i s_i'.
"robust"Huber-White sandwich
A^{-1} (\sum_i w_i^2 s_i s_i') A^{-1} — also the valid WESML
variance under choice-based weighting.
"cluster"Cluster-robust sandwich
A^{-1} (\sum_g g_g g_g') A^{-1} with
g_g = \sum_{i \in g} w_i s_i the within-cluster sum of weighted
scores. Requires cluster (or a fit made with
cluster_col). No small-sample correction is applied.
Here i indexes choice situations. For repeated choices by the
same decision maker (panel data), cluster on the decision maker.
## S3 method for class 'choicer_fit'
vcov(object, type = NULL, cluster = NULL, ...)
object |
A choicer_fit object. |
type |
|
cluster |
Cluster labels for
Defaults to the labels stored at fit time via |
... |
Additional arguments (ignored). |
Note (mixed logit): clustering repairs the inference, not the
estimand. run_mxlogit() treats each choice situation as an
independent draw from the mixing distribution (a cross-sectional MSL
likelihood, not the panel product form), so on panel data the point
estimates target that cross-sectional model; type = "cluster" makes
their standard errors robust to within-person dependence but does not turn
the fit into a panel mixed logit. For panel random coefficients use
run_hmnlogit (person_col).
Named variance-covariance matrix, or NULL if unavailable.
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[, person := rep(1:10, each = 5)[id]]
dt[, choice := 0L]
dt[, choice := sample(c(1L, rep(0L, J - 1))), by = id]
fit <- run_mnlogit(dt, "id", "alt", "choice", c("x1", "x2"))
vcov(fit) # as fitted (hessian)
vcov(fit, type = "robust") # Huber-White, post hoc
# named by situation id -> safe regardless of order
cl <- dt[, person[1L], by = id]
vcov(fit, type = "cluster", cluster = setNames(cl$V1, cl$id))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.