Mixed Logit: ERROR: Singular Hessian, cannot calculate s.e.
Posted: 14 Jan 2022, 09:29
Hi everyone,
I want to estimate a mixed logit model that is very close to the (old) examplaes from the Apollo Homepage (Apollo Example 14: Mixed logit model on Swiss route choice data, uncorrelated Lognormals in utility space). The model (with my parameter) converges, however, while computing the covariance matrix I get the following Errors/Warings:
- ERROR: Singular Hessian, cannot calculate s.e.
- WARNING: Some eigenvalues of the Hessian are positive, indicating convergence to a saddle point!
I used my parameter and the utility function that I wanted to with the mixed logit model and did an basic MNL estimation (based on Apollo Example 2: "Simple MNL model on mode choice SP data"), where the model converges and I get all the results just fine. So I guess, there is something wrong in my model definition for the mixed logit. Do you have any idea what that might be?
Below you find first the results of the mixed logit and afterwards the code for it.
If you have any questions, I glady provide more information.
Thank you very much in advance!
Sutsch
1) Results of the mixed logit ############################################################
####################################################################################
Computing covariance matrix using numerical methods (maxLik). This may take a while, no progress bar displayed.
ERROR: Singular Hessian, cannot calculate s.e.
Hessian written to P3_MLM_MULL_hessian.csv
WARNING: Some eigenvalues of the Hessian are positive, indicating convergence to a saddle point!
Computing score matrix...
Calculating LL(0)...
Calculating LL of each model component...
Model run using Apollo for R, version 0.2.1 on Windows by XXX
www.ApolloChoiceModelling.com
Model name : P3_MLM
Model description : MLM on XXX
Model run at : 2022-01-14 00:01:22
Estimation method : bfgs
Model diagnosis : successful convergence
Number of individuals : 778
Number of observations : 9336
Number of cores used : 4
Number of inter-individual draws : 30 (mlhs)
LL(start) : -6471.222
LL(0) : -6471.222
LL(final) : -4837.951
Rho-square (0) : 0.2524
Adj.Rho-square (0) : 0.2484
AIC : 9727.9
BIC : 9913.58
Estimated parameters : 26
Time taken (hh:mm:ss) : 00:08:10.09
pre-estimation : 00:01:6.21
estimation : 00:01:18.03
post-estimation : 00:05:45.86
Iterations : 43
Min abs eigenvalue of Hessian : 243.249
Some eigenvalues of Hessian are positive, indicating potential problems!
Estimates:
Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0)
asc_alt1 0.12162 NA NA NA NA
mu_p1 -0.37516 NA NA NA NA
mu_p2 -0.11042 NA NA NA NA
mu_a1 0.16079 NA NA NA NA
mu_a2 0.12996 NA NA NA NA
mu_a3 0.13071 NA NA NA NA
mu_s1 0.14692 NA NA NA NA
mu_s2 0.07806 NA NA NA NA
mu_s3 0.12928 NA NA NA NA
mu_d1 0.31295 NA NA NA NA
mu_d2 0.24027 NA NA NA NA
mu_d3 0.44767 NA NA NA NA
mu_d4 0.54913 NA NA NA NA
b_c -0.11947 NA NA NA NA
sigma_p1 0.74017 NA NA NA NA
sigma_p2 0.79890 NA NA NA NA
sigma_a1 -0.22254 NA NA NA NA
sigma_a2 0.01733 NA NA NA NA
sigma_a3 0.13300 NA NA NA NA
sigma_s1 0.09250 NA NA NA NA
sigma_s2 -0.09569 NA NA NA NA
sigma_s3 -0.17211 NA NA NA NA
sigma_d1 -0.07971 NA NA NA NA
sigma_d2 0.06219 NA NA NA NA
sigma_d3 0.11595 NA NA NA NA
sigma_d4 -0.39956 NA NA NA NA
2) Code of the mixed logit (Except for database transformations)#############################
####################################################################################
apollo_control = list(
modelName ="P3_MLM_XXX",
modelDescr ="MLM on XXX",
indivID ="ID",
mixing = TRUE,
nCores = 4
)
database <- read.csv2("XXX.csv",header=TRUE, encoding="latin1")
colnames(database) <- c("ID", colnames(database)[-1])
pollo_beta = c(asc_alt1 = 0,
mu_p1 = 0,
mu_p2 = 0,
mu_a1 = 0,
mu_a2 = 0,
mu_a3 = 0,
mu_s1 = 0,
mu_s2 = 0,
mu_s3 = 0,
mu_d1 = 0,
mu_d2 = 0,
mu_d3 = 0,
mu_d4 = 0,
b_c = 0,
sigma_p1 = 0,
sigma_p2 = 0,
sigma_a1 = 0,
sigma_a2 = 0,
sigma_a3 = 0,
sigma_s1 = 0,
sigma_s2 = 0,
sigma_s3 = 0,
sigma_d1 = 0,
sigma_d2 = 0,
sigma_d3 = 0,
sigma_d4 = 0)
apollo_fixed = c()
apollo_draws = list(
interDrawsType = "mlhs", #more than 5 dimensions, paper: mlhs > halton (Hess, et al. 2006)
interNDraws = 30, #increase later
interUnifDraws = c(),
interNormDraws = c("draws_p1",
"draws_p2",
"draws_a1",
"draws_a2",
"draws_a3",
"draws_s1",
"draws_s2",
"draws_s3",
"draws_d1",
"draws_d2",
"draws_d3",
"draws_d4"),
intraDrawsType = "mlhs",
intraNDraws = 0,
intraUnifDraws = c(),
intraNormDraws = c()
pollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()
#Base Model
randcoeff[["b_p1"]] = (mu_p1 + sigma_p1 * draws_p1)
randcoeff[["b_p2"]] = (mu_p2 + sigma_p2 * draws_p2)
randcoeff[["b_a1"]] = (mu_a1 + sigma_a1 * draws_a1)
randcoeff[["b_a2"]] = (mu_a2 + sigma_a2 * draws_a2)
randcoeff[["b_a3"]] = (mu_a3 + sigma_a3 * draws_a3)
randcoeff[["b_s1"]] = (mu_s1 + sigma_s1 * draws_s1)
randcoeff[["b_s2"]] = (mu_s2 + sigma_s2 * draws_s2)
randcoeff[["b_s3"]] = (mu_s3 + sigma_s3 * draws_s3)
randcoeff[["b_d1"]] = (mu_d1 + sigma_d1 * draws_d1)
randcoeff[["b_d2"]] = (mu_d2 + sigma_d2 * draws_d2)
randcoeff[["b_d3"]] = (mu_d3 + sigma_d3 * draws_d3)
randcoeff[["b_d4"]] = (mu_d4 + sigma_d4 * draws_d4)
return(randcoeff)
}
apollo_inputs = apollo_validateInputs()
apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))
P = list()
V = list()
V[['alt1']] = asc_alt1 +
b_p1 * (att_P_alt1==2) +
b_p2 * (att_P_alt1==3) +
b_a1 * (att_A1_alt1==1) +
b_a2 * (att_A2_alt1==1) +
b_a3 * (att_A3_alt1==1) +
b_s1 * (att_S1_alt1==1) +
b_s2 * (att_S2_alt1==1) +
b_s3 * (att_S3_alt1==1) +
b_d1 * (att_T_alt1==1) +
b_d2 * (att_T_alt1==2) +
b_d3 * (att_T_alt1==3) +
b_d4 * (att_T_alt1==4) +
b_c * att_C_alt1
V[['alt2']] =
b_p1 * (att_P_alt2==2) +
b_p2 * (att_P_alt2==3) +
b_a1 * (att_A1_alt2==1) +
b_a2 * (att_A2_alt2==1) +
b_a3 * (att_A3_alt2==1) +
b_s1 * (att_S1_alt2==1) +
b_s2 * (att_S2_alt2==1) +
b_s3 * (att_S3_alt2==1) +
b_d1 * (att_T_alt2==1) +
b_d2 * (att_T_alt2==2) +
b_d3 * (att_T_alt2==3) +
b_d4 * (att_T_alt2==4) +
b_c * att_C_alt2
mnl_settings = list(
alternatives = c(alt1=1, alt2=2),
avail = list(alt1=1, alt2=1),
choiceVar = choice,
V = V
)
P[['model']] = apollo_mnl(mnl_settings, functionality)
P = apollo_panelProd(P, apollo_inputs, functionality)
P = apollo_avgInterDraws(P, apollo_inputs, functionality)
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
model = apollo_estimate(apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs,
estimate_settings=list(hessianRoutine="maxLik"))
I want to estimate a mixed logit model that is very close to the (old) examplaes from the Apollo Homepage (Apollo Example 14: Mixed logit model on Swiss route choice data, uncorrelated Lognormals in utility space). The model (with my parameter) converges, however, while computing the covariance matrix I get the following Errors/Warings:
- ERROR: Singular Hessian, cannot calculate s.e.
- WARNING: Some eigenvalues of the Hessian are positive, indicating convergence to a saddle point!
I used my parameter and the utility function that I wanted to with the mixed logit model and did an basic MNL estimation (based on Apollo Example 2: "Simple MNL model on mode choice SP data"), where the model converges and I get all the results just fine. So I guess, there is something wrong in my model definition for the mixed logit. Do you have any idea what that might be?
Below you find first the results of the mixed logit and afterwards the code for it.
If you have any questions, I glady provide more information.
Thank you very much in advance!
Sutsch
1) Results of the mixed logit ############################################################
####################################################################################
Computing covariance matrix using numerical methods (maxLik). This may take a while, no progress bar displayed.
ERROR: Singular Hessian, cannot calculate s.e.
Hessian written to P3_MLM_MULL_hessian.csv
WARNING: Some eigenvalues of the Hessian are positive, indicating convergence to a saddle point!
Computing score matrix...
Calculating LL(0)...
Calculating LL of each model component...
Model run using Apollo for R, version 0.2.1 on Windows by XXX
www.ApolloChoiceModelling.com
Model name : P3_MLM
Model description : MLM on XXX
Model run at : 2022-01-14 00:01:22
Estimation method : bfgs
Model diagnosis : successful convergence
Number of individuals : 778
Number of observations : 9336
Number of cores used : 4
Number of inter-individual draws : 30 (mlhs)
LL(start) : -6471.222
LL(0) : -6471.222
LL(final) : -4837.951
Rho-square (0) : 0.2524
Adj.Rho-square (0) : 0.2484
AIC : 9727.9
BIC : 9913.58
Estimated parameters : 26
Time taken (hh:mm:ss) : 00:08:10.09
pre-estimation : 00:01:6.21
estimation : 00:01:18.03
post-estimation : 00:05:45.86
Iterations : 43
Min abs eigenvalue of Hessian : 243.249
Some eigenvalues of Hessian are positive, indicating potential problems!
Estimates:
Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0)
asc_alt1 0.12162 NA NA NA NA
mu_p1 -0.37516 NA NA NA NA
mu_p2 -0.11042 NA NA NA NA
mu_a1 0.16079 NA NA NA NA
mu_a2 0.12996 NA NA NA NA
mu_a3 0.13071 NA NA NA NA
mu_s1 0.14692 NA NA NA NA
mu_s2 0.07806 NA NA NA NA
mu_s3 0.12928 NA NA NA NA
mu_d1 0.31295 NA NA NA NA
mu_d2 0.24027 NA NA NA NA
mu_d3 0.44767 NA NA NA NA
mu_d4 0.54913 NA NA NA NA
b_c -0.11947 NA NA NA NA
sigma_p1 0.74017 NA NA NA NA
sigma_p2 0.79890 NA NA NA NA
sigma_a1 -0.22254 NA NA NA NA
sigma_a2 0.01733 NA NA NA NA
sigma_a3 0.13300 NA NA NA NA
sigma_s1 0.09250 NA NA NA NA
sigma_s2 -0.09569 NA NA NA NA
sigma_s3 -0.17211 NA NA NA NA
sigma_d1 -0.07971 NA NA NA NA
sigma_d2 0.06219 NA NA NA NA
sigma_d3 0.11595 NA NA NA NA
sigma_d4 -0.39956 NA NA NA NA
2) Code of the mixed logit (Except for database transformations)#############################
####################################################################################
apollo_control = list(
modelName ="P3_MLM_XXX",
modelDescr ="MLM on XXX",
indivID ="ID",
mixing = TRUE,
nCores = 4
)
database <- read.csv2("XXX.csv",header=TRUE, encoding="latin1")
colnames(database) <- c("ID", colnames(database)[-1])
pollo_beta = c(asc_alt1 = 0,
mu_p1 = 0,
mu_p2 = 0,
mu_a1 = 0,
mu_a2 = 0,
mu_a3 = 0,
mu_s1 = 0,
mu_s2 = 0,
mu_s3 = 0,
mu_d1 = 0,
mu_d2 = 0,
mu_d3 = 0,
mu_d4 = 0,
b_c = 0,
sigma_p1 = 0,
sigma_p2 = 0,
sigma_a1 = 0,
sigma_a2 = 0,
sigma_a3 = 0,
sigma_s1 = 0,
sigma_s2 = 0,
sigma_s3 = 0,
sigma_d1 = 0,
sigma_d2 = 0,
sigma_d3 = 0,
sigma_d4 = 0)
apollo_fixed = c()
apollo_draws = list(
interDrawsType = "mlhs", #more than 5 dimensions, paper: mlhs > halton (Hess, et al. 2006)
interNDraws = 30, #increase later
interUnifDraws = c(),
interNormDraws = c("draws_p1",
"draws_p2",
"draws_a1",
"draws_a2",
"draws_a3",
"draws_s1",
"draws_s2",
"draws_s3",
"draws_d1",
"draws_d2",
"draws_d3",
"draws_d4"),
intraDrawsType = "mlhs",
intraNDraws = 0,
intraUnifDraws = c(),
intraNormDraws = c()
pollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()
#Base Model
randcoeff[["b_p1"]] = (mu_p1 + sigma_p1 * draws_p1)
randcoeff[["b_p2"]] = (mu_p2 + sigma_p2 * draws_p2)
randcoeff[["b_a1"]] = (mu_a1 + sigma_a1 * draws_a1)
randcoeff[["b_a2"]] = (mu_a2 + sigma_a2 * draws_a2)
randcoeff[["b_a3"]] = (mu_a3 + sigma_a3 * draws_a3)
randcoeff[["b_s1"]] = (mu_s1 + sigma_s1 * draws_s1)
randcoeff[["b_s2"]] = (mu_s2 + sigma_s2 * draws_s2)
randcoeff[["b_s3"]] = (mu_s3 + sigma_s3 * draws_s3)
randcoeff[["b_d1"]] = (mu_d1 + sigma_d1 * draws_d1)
randcoeff[["b_d2"]] = (mu_d2 + sigma_d2 * draws_d2)
randcoeff[["b_d3"]] = (mu_d3 + sigma_d3 * draws_d3)
randcoeff[["b_d4"]] = (mu_d4 + sigma_d4 * draws_d4)
return(randcoeff)
}
apollo_inputs = apollo_validateInputs()
apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))
P = list()
V = list()
V[['alt1']] = asc_alt1 +
b_p1 * (att_P_alt1==2) +
b_p2 * (att_P_alt1==3) +
b_a1 * (att_A1_alt1==1) +
b_a2 * (att_A2_alt1==1) +
b_a3 * (att_A3_alt1==1) +
b_s1 * (att_S1_alt1==1) +
b_s2 * (att_S2_alt1==1) +
b_s3 * (att_S3_alt1==1) +
b_d1 * (att_T_alt1==1) +
b_d2 * (att_T_alt1==2) +
b_d3 * (att_T_alt1==3) +
b_d4 * (att_T_alt1==4) +
b_c * att_C_alt1
V[['alt2']] =
b_p1 * (att_P_alt2==2) +
b_p2 * (att_P_alt2==3) +
b_a1 * (att_A1_alt2==1) +
b_a2 * (att_A2_alt2==1) +
b_a3 * (att_A3_alt2==1) +
b_s1 * (att_S1_alt2==1) +
b_s2 * (att_S2_alt2==1) +
b_s3 * (att_S3_alt2==1) +
b_d1 * (att_T_alt2==1) +
b_d2 * (att_T_alt2==2) +
b_d3 * (att_T_alt2==3) +
b_d4 * (att_T_alt2==4) +
b_c * att_C_alt2
mnl_settings = list(
alternatives = c(alt1=1, alt2=2),
avail = list(alt1=1, alt2=1),
choiceVar = choice,
V = V
)
P[['model']] = apollo_mnl(mnl_settings, functionality)
P = apollo_panelProd(P, apollo_inputs, functionality)
P = apollo_avgInterDraws(P, apollo_inputs, functionality)
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
model = apollo_estimate(apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs,
estimate_settings=list(hessianRoutine="maxLik"))