View source: R/nestlogit_utils.R
| run_nestlogit | R Documentation |
Estimates a nested logit model via maximum likelihood.
run_nestlogit(
data = NULL,
id_col = NULL,
alt_col = NULL,
choice_col = NULL,
covariate_cols = NULL,
nest_col = NULL,
input_data = NULL,
use_asc = TRUE,
theta_init = NULL,
param_names = NULL,
optimizer = NULL,
control = list(),
weights = NULL,
weights_col = NULL,
outside_opt_label = NULL,
include_outside_option = FALSE,
keep_data = TRUE,
se_method = c("hessian", "numeric", "bhhh", "sandwich", "cluster"),
cluster_col = NULL,
nloptr_opts = 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 covariates. |
nest_col |
Name of the column mapping each alternative to its nest (convenience workflow). |
input_data |
List containing prepared input data for estimation
(advanced workflow). Mutually exclusive with |
use_asc |
Logical indicating whether to include alternative specific constants (ASCs). |
theta_init |
Optional initial parameter vector. If |
param_names |
Optional vector of parameter names. If |
optimizer |
Optimizer to use: |
control |
List of optimizer-specific control parameters. |
weights |
Optional weight vector (convenience workflow). If |
weights_col |
Optional name of a column in |
outside_opt_label |
Label for the outside option (convenience workflow). |
include_outside_option |
Logical whether to include an outside option (convenience workflow). |
keep_data |
Logical. If |
se_method |
Method for computing standard errors: |
cluster_col |
Optional name of a column in |
nloptr_opts |
Deprecated. Use |
Two workflows are supported:
Supply data and column names (including
nest_col). Data preparation (prepare_nl_data) is
handled automatically.
Call prepare_nl_data (or build the input
list manually) and pass it via input_data.
A choicer_nl 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 <- 4
dt <- data.table(id = rep(1:N, each = J), alt = rep(1:J, N))
dt[, `:=`(x1 = rnorm(.N), x2 = rnorm(.N))]
dt[, nest := ifelse(alt <= 2, "A", "B")]
dt[, choice := 0L]
dt[, choice := sample(c(1L, rep(0L, J - 1))), by = id]
fit <- run_nestlogit(
data = dt, id_col = "id", alt_col = "alt", choice_col = "choice",
covariate_cols = c("x1", "x2"), nest_col = "nest"
)
summary(fit)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.