I am trying to run a mixed logit model with error component and variance heterogeneity. I followed the example given here to include variance heterogeneity https://www.apollochoicemodelling.com/f ... means#p107 and the model runs, but while all the coefficients are estimated, their standard errors are just NAs. Previously, I ran a mixed logit model with error component (without variance heterogeneity) and a mixed logit model with variance heterogeneity (without error component), and they both worked fine. Could you please help me find the error in my code, or is there some other issue due to including both error components and variance heterogeneity in the same model?
Here is my code:
Code: Select all
### Initialise code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName="MXL_noprotest_error_component",
modelDescr = "Mixed logit model, no protest respondents, but with error component ",
indivID = "KMG.MID",
nCores = 4,
outputDirectory = "output",
seed=12345
)
database = anketa2
apollo_beta = c(mu_b_fallow = 0,
sigma_b_fallow = 0.01,
mu_b_meadow = 0,
sigma_b_meadow = 0.01,
mu_b_lands = 0,
sigma_b_lands = 0,
b_payment = 0,
mu_b_asc = 0,
sigma_b_asc = 0,
sigma_bsh = 0.01,
lambda_AE_sig_fallow=0.1,
lambda_AE_sig_meadow=0.1,
lambda_AE_sig_lands=0.1,
lambda_AE_sig_ASC=0.1)
### Vector with names (in quotes) of parameters to be kept fixed at their starting value in apollo_beta, use apollo_beta_fixed = c() if none
apollo_fixed = c()
# ################################################################# #
#### DEFINE RANDOM COMPONENTS ####
# ################################################################# #
### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "halton",
interNDraws = 500,
interUnifDraws = c(),
interNormDraws = c("draws_fallow","draws_meadow","draws_lands","draws_bsh", "draws_asc"),
intraDrawsType = "halton",
intraNDraws = 0,
intraUnifDraws = c(),
intraNormDraws = c()
)
### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()
randcoeff[["b_fallow"]] =( mu_b_fallow + sigma_b_fallow * Q65^lambda_AE_sig_fallow*draws_fallow )
randcoeff[["b_meadow"]] = ( mu_b_meadow + sigma_b_meadow *Q65^lambda_AE_sig_meadow * draws_meadow )
randcoeff[["b_lands"]] = ( mu_b_lands + sigma_b_lands *Q65^lambda_AE_sig_lands * draws_lands )
randcoeff[["b_asc"]] = ( mu_b_asc + sigma_b_asc*Q65^lambda_AE_sig_ASC * draws_asc )
randcoeff[["bsh"]] = ( sigma_bsh * draws_bsh )
return(randcoeff)
}
# ################################################################# #
#### GROUP AND VALIDATE INPUTS ####
# ################################################################# #
apollo_inputs = apollo_validateInputs()
# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION ####
# ################################################################# #
apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
### Function initialisation: do not change the following three commands
### Attach inputs and detach after function exit
apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))
### Create list of probabilities P
P = list()
### List of utilities: these must use the same names as in mnl_settings, order is irrelevant
V = list()
V[["alt1"]] = b_fallow * fallow_1 + b_meadow * meadow_1 + b_lands * lands_1 + b_payment * payment_1
V[["alt2"]] = b_fallow * fallow_2 + b_meadow * meadow_2 + b_lands * lands_2 + b_payment * payment_2
V[["alt3"]] = b_asc+bsh
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(alt1=1, alt2=2, alt3=3),
avail = list(alt1=1, alt2=1, alt3=1),
choiceVar = choice,
utilities = V
)
### Compute probabilities using MNL model
P[["model"]] = apollo_mnl(mnl_settings, functionality)
### Take product across observation for same individual
P = apollo_panelProd(P, apollo_inputs, functionality)
### Average across inter-individual draws
P = apollo_avgInterDraws(P, apollo_inputs, functionality)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
# ################################################################# #
#### MODEL ESTIMATION ####
# ################################################################# #
model5 = apollo_estimate(apollo_beta, apollo_fixed,apollo_probabilities, apollo_inputs)
summary(model5)
# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #
output5<-apollo_modelOutput(model5, modelOutput_settings=list(printCorr=T))