These functions construct, validate, and transform an object of class
choice_parameters, which defines the parameters of a choice model.
choice_parameters()constructs achoice_parametersobject.generate_choice_parameters()samples parameters at random, see details.validate_choice_parameters()checks model-specific dimensions.switch_parameter_space()transforms achoice_parametersobject between the interpretation and optimization space, see details.
Usage
choice_parameters(
beta = NULL,
Omega = NULL,
Sigma = NULL,
gamma = NULL,
weights = NULL
)
generate_choice_parameters(
choice_effects,
fixed_parameters = choice_parameters(),
C = 1L
)
validate_choice_parameters(
choice_parameters,
choice_effects,
allow_missing = FALSE
)
switch_parameter_space(choice_parameters, choice_effects)Arguments
- beta
[
numeric(P)|list(C)|NULL]
The coefficient vector for computing the linear-in-parameters systematic utility \(V = X\beta\).For a latent class model, a list of one coefficient vector per class.
- Omega
[
matrix(nrow = P_r, ncol = P_r)|list(C)|NULL]
The covariance matrix of random effects.Not used when
P_r = 0.In a latent class model, a list of one covariance matrix per class.
Covariances involving uncorrelated random effects are fixed to zero.
- Sigma
[
matrix(nrow = J, ncol = J)|numeric(1)|NULL]
Only relevant in the probit model.For unordered alternatives it is the covariance matrix for the Gaussian error term \(\epsilon = U - V\).
In ordered models it reduces to a single variance term.
- gamma
[
numeric(J - 1)|NULL]
Vector of strictly increasing threshold parameters required for ordered models.The first element must equal zero for identification.
- weights
[
numeric(C)|NULL]
Positive latent class weights.- choice_effects
[
choice_effects]
Achoice_effectsobject.- fixed_parameters
[
choice_parameters]
Achoice_parametersobject. Its supplied components are kept fixed. Missing components are completed as described below.- C
[
integer(1)]
Number of latent classes.- choice_parameters
[
choice_parameters|numeric()]
Achoice_parametersobject. Forswitch_parameter_space(), a numeric vector in optimization space is also accepted and converted back to achoice_parametersobject.- allow_missing
[
logical(1)]
Allow required parameter components to be omitted?
Value
choice_parameters(), generate_choice_parameters(), and
validate_choice_parameters() return a choice_parameters list with the
elements:
betaThe coefficient vector (if any).
OmegaThe random-effect covariance matrix on the underlying normal scale (if any).
SigmaThe error term covariance matrix (or variance in ordered models).
gammaThreshold parameters for ordered models (if any).
weightsThe latent class weights (if any).
switch_parameter_space() returns a named numeric vector when given a
choice_parameters object and a choice_parameters object when given a
numeric optimization vector.
Sampling missing choice model parameters
generate_choice_parameters() completes required components that are absent
from fixed_parameters.
Missing components are generated as follows:
betaDrawn independently for each class from a multivariate normal distribution with zero mean and covariance matrix
10 * diag(P).OmegaDrawn independently for each class from an Inverse-Wishart distribution with
P_r + 2degrees of freedom and identity scale matrix. Covariances involving uncorrelated random effects are then set to zero.SigmaFor unordered probit models, the lower right block is drawn from an Inverse-Wishart distribution with
J + 1degrees of freedom and identity scale matrix. The first row and column are fixed to zero and the matrix is scaled so that element \((2, 2)\) equals one. For ordered probit models,Sigmais set to one; logit models do not useSigma.gammaFor ordered models with two categories, set to zero. Otherwise, positive increments are drawn as
exp(z), where the elements ofzare independent standard normal draws, and cumulatively added to the first threshold zero. Unordered models do not usegamma.weightsSet to equal class probabilities
1 / C.
Parameter spaces
The switch_parameter_space() function transforms a choice_parameters
object between the interpretation and optimization space.
The interpretation space is a
listof (not necessarily identified) parameters that can be interpreted.The optimization space is a
numericvector of identified parameters that can be optimized:betais not transformedOmegais represented by its vectorized unique Cholesky factor; elements involving uncorrelated random effects are omittedfor unordered probit models,
Sigmais represented through utility differences relative to the first alternative, with the first variance fixed to one, and transformed to a vectorized unique Cholesky factorfor ordered probit models, the positive scalar
Sigmais log-transformedthe first ordered threshold is fixed to zero and omitted; logarithms of the remaining positive threshold increments are used
latent class parameters are concatenated in class order, and
C - 1log weight ratios use the first class as reference
Examples
### generate choice parameters at random
J <- 3
choice_effects <- choice_effects(
choice_formula = choice_formula(
formula = choice ~ x | y, error_term = "probit",
random_effects = c("x" = "cn")
),
choice_alternatives = choice_alternatives(J = J)
)
(parameters <- generate_choice_parameters(
choice_effects = choice_effects,
fixed_parameters = choice_parameters(
Sigma = diag(c(0, rep(1, J - 1))) # scale and level normalization
)
))
#> $beta
#> y_B y_C ASC_B ASC_C x
#> 0.4069475 -4.8479786 0.6399206 -2.2690565 1.1437793
#>
#> $Omega
#> x
#> x 0.1731118
#>
#> $Sigma
#> A B C
#> A 0 0 0
#> B 0 1 0
#> C 0 0 1
#>
#> attr(,"class")
#> [1] "choice_parameters" "list"
### switch between interpretation and optimization spaces
(optimization_parameters <- switch_parameter_space(
choice_parameters = parameters,
choice_effects = choice_effects
))
#> beta_1 beta_2 beta_3 beta_4 beta_5 o_1 l_2
#> 0.4069475 -4.8479786 0.6399206 -2.2690565 1.1437793 0.4160670 0.0000000
#> l_3
#> 1.0000000
#> attr(,"class")
#> [1] "choice_parameters" "numeric"
switch_parameter_space(
choice_parameters = optimization_parameters,
choice_effects = choice_effects
)
#> $beta
#> y_B y_C ASC_B ASC_C x
#> 0.4069475 -4.8479786 0.6399206 -2.2690565 1.1437793
#>
#> $Omega
#> x
#> x 0.1731118
#>
#> $Sigma
#> A B C
#> A 0 0 0
#> B 0 1 0
#> C 0 0 1
#>
#> attr(,"class")
#> [1] "choice_parameters" "list"
