View source: R/mxlogit_utils.R
| run_mxlogit | R Documentation |
Estimates a mixed logit model via simulated maximum likelihood.
run_mxlogit(
data = NULL,
id_col = NULL,
alt_col = NULL,
choice_col = NULL,
covariate_cols = NULL,
random_var_cols = NULL,
input_data = NULL,
eta_draws = NULL,
S = 100L,
rc_dist = NULL,
rc_mean = FALSE,
rc_correlation = FALSE,
use_asc = TRUE,
theta_init = NULL,
lower = NULL,
upper = NULL,
optimizer = NULL,
control = list(),
se_method = c("hessian", "bhhh", "sandwich", "cluster"),
scale_vars = c("none", "sd", "mad", "iqr"),
weights = NULL,
outside_opt_label = NULL,
include_outside_option = FALSE,
draws = c("store", "generate"),
seed = NULL,
scramble = c("permuted", "none", "owen"),
keep_data = TRUE,
nloptr_opts = NULL,
weights_col = NULL,
cluster_col = NULL
)
data |
Data frame containing choice data (convenience workflow).
Mutually exclusive with |
id_col |
Name of the column identifying choice situations. |
alt_col |
Name of the column identifying alternatives. |
choice_col |
Name of the column indicating chosen alternative (1/0). |
covariate_cols |
Vector of column names for fixed covariates. |
random_var_cols |
Vector of column names for random coefficients. |
input_data |
List output from |
eta_draws |
Array of shape K_w x S x N with standard normal draws.
Required for the advanced workflow; auto-generated from |
S |
Integer number of Halton draws per individual (convenience workflow only). Default 100. |
rc_dist |
Integer vector indicating distribution of random coefficients (0 = normal, 1 = log-normal). Default: all normal. |
rc_mean |
Logical indicating whether to estimate means for random coefficients. |
rc_correlation |
Logical indicating whether random coefficients are
correlated (convenience workflow). Ignored when |
use_asc |
Logical indicating whether to include alternative-specific constants. |
theta_init |
Initial parameter vector in natural-scale units. If
|
lower, upper |
Optional parameter bounds for the optimizer, in
natural-scale units (forward-transformed internally to scaled space when
|
optimizer |
Optimizer to use: |
control |
List of optimizer-specific control parameters. |
se_method |
Method for computing standard errors. One of
|
scale_vars |
Pre-estimation column scaling for design matrices. One of
|
weights |
Optional weight vector (convenience workflow). If |
outside_opt_label |
Label for the outside option (convenience workflow). |
include_outside_option |
Logical whether to include an outside option (convenience workflow). |
draws |
Draw storage mode. One of |
seed |
Integer master seed for the on-the-fly generator. Used only when
|
scramble |
Scrambling mode for on-the-fly Halton draws. One of
|
keep_data |
Logical. If |
nloptr_opts |
Deprecated. Use |
weights_col |
Optional name of a column in |
cluster_col |
Optional name of a column in |
Two workflows are supported:
Supply data and column names. Data preparation
(prepare_mxl_data) and Halton draw generation
(get_halton_normals) are handled automatically.
Call prepare_mxl_data and
get_halton_normals yourself, then pass the results via
input_data and eta_draws.
A choicer_mxl object (inherits from choicer_fit).
Standard S3 methods available: summary(), coef(),
vcov(), logLik(), AIC(), BIC(),
nobs().
library(data.table)
set.seed(42)
N <- 100; J <- 3
dt <- data.table(id = rep(1:N, each = J), alt = rep(1:J, N))
dt[, `:=`(x1 = rnorm(.N), w1 = rnorm(.N), w2 = rnorm(.N))]
dt[, choice := 0L]
dt[, choice := sample(c(1L, rep(0L, J - 1))), by = id]
fit <- run_mxlogit(
data = dt, id_col = "id", alt_col = "alt", choice_col = "choice",
covariate_cols = "x1", random_var_cols = c("w1", "w2"), S = 50L
)
summary(fit)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.