Generates synthetic choice data with random coefficients drawn from a
multivariate normal (optionally log-normal per dimension) and an additional
mean shifter mu. Random coefficients are parameterized via the lower
Cholesky factor of Sigma. Covariates are Uniform(-1, 1) by default;
columns named in price_cols are drawn as -Uniform(0.1, 3) to mimic
strictly-negative price variables.
Arguments
- N
Number of choice situations.
- J
Number of inside alternatives.
- beta
Fixed coefficients for
x1..x{K_x}(lengthK_x = length(beta)).- delta
ASCs for inside alternatives (length
J). Defaults to an alternating pattern ofc(0.5, -0.5).- mu
Mean shifter for random coefficients (length
K_w = ncol(Sigma)). Defaults to a zero vector.- Sigma
Covariance matrix of random coefficients (square,
K_w x K_w).- rc_dist
Integer vector (length
K_w):0Lfor normal,1Lfor log-normal. DefaultNULLis treated as all-normal.- rc_correlation
Logical; if
NULL(default) it is auto-detected from the off-diagonal entries ofSigma.- price_cols
Character vector of
w*column names to draw as-Uniform(0.1, 3)instead ofUniform(-1, 1). DefaultNULL.- seed
Random seed (
NULLskipsset.seed()).- outside_option
Logical; include outside option with
alt = 0.- vary_choice_set
Logical; if
TRUE(default) choice set size is sampled uniformly from2:J.
Value
A choicer_sim object. true_params includes beta, delta,
Sigma, L_params (packed Cholesky parameters), mu, rc_dist,
rc_correlation.
Details
Random coefficients are constructed to match the estimator's
parameterization in src/mxlogit.cpp. For every dimension the raw draw
is L %*% eta where eta ~ N(0, I). A normal random coefficient
(rc_dist = 0) is then gamma_k = mu_k + (L %*% eta)_k. A log-normal
random coefficient (rc_dist = 1) follows the shifted log-normal
beta_k = exp(mu_k) + exp((L %*% eta)_k) – not the textbook
exp(mu_k + sigma_k * eta) – so mu_k in true_params$mu is on the
same scale the estimator recovers and recovery_table() can compare
like-for-like.
Examples
# \donttest{
sim <- simulate_mxl_data(N = 1000, J = 4, seed = 123)
print(sim)
#> <choicer_sim: mxl>
#> settings:
#> N = 1000
#> J = 4
#> K_x = 2
#> K_w = 2
#> outside_option = TRUE
#> vary_choice_set = TRUE
#> rows in $data: 3989
#> true_params: beta, delta, Sigma, L_params, mu, rc_dist, rc_correlation
# }