Important: Read this before posting to this forum
- This forum is for questions related to the use of Apollo. We will answer some general choice modelling questions too, where appropriate, and time permitting. We cannot answer questions about how to estimate choice models with other software packages.
- There is a very detailed manual for Apollo available at http://www.ApolloChoiceModelling.com/manual.html. This contains detailed descriptions of the various Apollo functions, and numerous examples are available at http://www.ApolloChoiceModelling.com/examples.html. In addition, help files are available for all functions, using e.g. ?apollo_mnl
- Before asking a question on the forum, users are kindly requested to follow these steps:
- Check that the same issue has not already been addressed in the forum - there is a search tool.
- Ensure that the correct syntax has been used. For any function, detailed instructions are available directly in Apollo, e.g. by using ?apollo_mnl for apollo_mnl
- Check the frequently asked questions section on the Apollo website, which discusses some common issues/failures. Please see http://www.apollochoicemodelling.com/faq.html
- Make sure that R is using the latest official release of Apollo.
- Users can check which version they are running by entering packageVersion("apollo").
- Then check what is the latest full release (not development version) at http://www.ApolloChoiceModelling.com/code.html.
- To update to the latest official version, just enter install.packages("apollo"). To update to a development version, download the appropriate binary file from http://www.ApolloChoiceModelling.com/code.html, and install the package from file
- If the above steps do not resolve the issue, then users should follow these steps when posting a question:
- provide full details on the issue, including the entire code and output, including any error messages
- posts will not immediately appear on the forum, but will be checked by a moderator first. We check the forum at least twice a week. It may thus take a couple of days for your post to appear and before we reply. There is no need to submit the post multiple times.
n sqrt(diag(varcov)) : NaNs produced
n sqrt(diag(varcov)) : NaNs produced
Good day, Stephane and David. I hope this finds you well.
I’m estimating a latent class model with 3 classes and every time I introduce gamma variables to specify the class allocation utility function, I get NaN standard errors. I have tried to play around with the scaling function (trial and error) but I still get NaN and the warning messages:
Warning messages:
1: In sqrt(diag(varcov)) : NaNs produced
2: In sqrt(diag(robvarcov)) : NaNs produced
Is there any other way to resolve this? I have attached my code and the data.
Here is the code:
### Clear memory
rm(list = ls())
### Load libraries
library(apollo)
### Initialise code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName ="COH 3 latent class",
modelDescr ="MNL with three latent classes",
indivID ="id",
calculateLLC = FALSE,
nCores = 2,
noDiagnostics = TRUE,
outputDirectory = 'output'
)
database = read.csv("CityOfHarare data.csv",header=TRUE)
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(
asc_zupco = 0,
asc_kombi = 0,
asc_car_hh = 0,
b_accessT_a = 0,
b_waitingT_a = 0,
b_accessT_b = 0,
b_waitingT_b = 0,
b_accessT_c = 0,
b_waitingT_c = 0,
b_available = 0,
b_standing_a = 0,
b_kadoma_a = 0,
b_trailer_a = 0,
b_standing_b = 0,
b_kadoma_b = 0,
b_trailer_b = 0,
b_standing_c = 0,
b_kadoma_c = 0,
b_trailer_c = 0,
b_ivt_a = 0,
b_fare_a = 0,
b_ivt_c = 0,
b_fare_c = 0,
b_ivt_b = 0,
b_fare_b = 0,
delta_a = 0,
delta_b = 0,
delta_c = 0,
gamma_gender_a = 0,
gamma_gender_b = 0,
gamma_gender_c = 0,
gamma_NoInc_a = 0,
gamma_IncomeA_a = 0,
gamma_IncomeB_a = 0,
gamma_IncomeC_a = 0,
gamma_IncomeD_a = 0,
# gamma_none_a = 0,
# gamma_student_a = 0,
# gamma_informal_a = 0,
# gamma_formal_a = 0,
gamma_NoInc_b = 0,
gamma_IncomeA_b = 0,
gamma_IncomeB_b = 0,
gamma_IncomeC_b = 0,
gamma_IncomeD_b = 0
# gamma_none_b = 0,
# gamma_student_b = 0,
# gamma_informal_b = 0,
# gamma_formal_b = 0
)
### 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("asc_zupco","b_available","delta_a"
)
# ################################################################# #
#### DEFINE LATENT CLASS COMPONENTS ####
# ################################################################# #
apollo_lcPars=function(apollo_beta, apollo_inputs){
lcpars = list()
lcpars[["b_accessT"]] = list(
b_accessT_a,
b_accessT_b,
b_accessT_c
)
lcpars[["b_waitingT"]] = list(b_waitingT_a, b_waitingT_b, b_waitingT_c)
lcpars[["b_ivt"]] = list(b_ivt_a, b_ivt_b, b_ivt_c)
lcpars[["b_fare"]] = list(b_fare_a, b_fare_b, b_fare_c)
lcpars[["b_standing"]] = list(b_standing_a, b_standing_b, b_standing_c)
lcpars[["b_kadoma"]] = list(b_kadoma_a, b_kadoma_b, b_kadoma_c)
lcpars[["b_trailer"]] = list(b_trailer_a, b_trailer_b, b_trailer_c)
V=list()
gamma_Income_a = gamma_NoInc_a * (income == 0) + gamma_IncomeA_a * (income == 1) +
gamma_IncomeB_a * (income == 2) + gamma_IncomeC_a * (income == 3) +
gamma_IncomeD_a * (income == 4)
gamma_Income_b = gamma_NoInc_b* (income == 0) + gamma_IncomeA_b * (income == 1) +
gamma_IncomeB_b * (income == 2) + gamma_IncomeC_b * (income == 3) +
gamma_IncomeD_b * (income == 4)
# gamma_employment_a = gamma_none_a * (employment == 1) + gamma_student_a * (employment == 2) +
# gamma_informal_a * (employment == 3) + gamma_formal_a * (employment > 3)
#
# gamma_employment_b = gamma_none_b * (employment == 1) + gamma_student_b * (employment == 2) +
# gamma_informal_b * (employment == 3) + gamma_formal_b * (employment > 3)
V[["class_a"]] = delta_a + gamma_gender_a*gender + gamma_Income_a #+ gamma_employment_a
V[["class_b"]] = delta_b + gamma_gender_b*gender + gamma_Income_b #+ gamma_employment_b
V[["class_c"]] = delta_c + gamma_gender_c*gender
classAlloc_settings = list(
alternatives = c(class_a=1, class_b=2, class_c=3),
avail = 1,
V = V
)
lcpars[["pi_values"]] = apollo_classAlloc(classAlloc_settings)
return(lcpars)
}
# ################################################################# #
#### GROUP AND VALIDATE INPUTS ####
# ################################################################# #
apollo_inputs = apollo_validateInputs()
# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION ####
# ################################################################# #
apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
### 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()
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(zupco=2, car_hh=3, kombi=1),
avail = list(zupco=1, kombi=1, car_hh=1),
choiceVar = Choice
)
### Loop over classes
for(s in 1:length(pi_values)){
### Compute class-specific utilities
V=list()
V[['zupco']] = asc_zupco + b_accessT[[s]] * accessT_zupco + b_waitingT[[s]] * waitingT_zupco +
b_available * (seat_zupco == 0) + b_standing[[s]] * (seat_zupco == 3) +
b_ivt[[s]] * ivt_zupco + b_fare[[s]] * fare_zupco
V[['kombi']] = asc_kombi + b_accessT[[s]] * accessT_kombi + b_waitingT[[s]] * waitingT_kombi +
b_available * (seat_kombi == 0) + b_kadoma[[s]] * (seat_kombi == 1) +
b_ivt[[s]] * ivt_kombi + b_fare[[s]] * fare_kombi
V[['car_hh']] = asc_car_hh + b_accessT[[s]] * accessT_car_hh + b_waitingT[[s]] * waitingT_car_hh +
b_available * (seat_car_hh == 0) + b_trailer[[s]] * (seat_car_hh == 2) +
b_ivt[[s]] * ivt_car_hh + b_fare[[s]] * fare_car_hh
mnl_settings$V = V
mnl_settings$componentName = paste0("Class_",s)
### Compute within-class choice probabilities using MNL model
P[[paste0("Class_",s)]] = apollo_mnl(mnl_settings, functionality)
### Take product across observation for same individual
P[[paste0("Class_",s)]] = apollo_panelProd(P[[paste0("Class_",s)]], apollo_inputs ,functionality)
}
### Compute latent class model probabilities
lc_settings = list(inClassProb = P, classProb=pi_values)
P[["model"]] = apollo_lc(lc_settings, apollo_inputs, functionality)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
# ################################################################# #
#### MODEL ESTIMATION ####
# ################################################################# #
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs,
estimate_settings = list(
scaling = c(
# b_accessT_a = 1000,
# b_waitingT_a = 1000,
# b_accessT_b = 1,
# b_waitingT_b = 1000,
# b_accessT_c = 1000,
# b_waitingT_c = 1000,
# b_ivt_a = 1000,
# b_fare_a = 1000,
# b_ivt_b = 1000,
# b_fare_b = 1000,
# b_ivt_c = 1000,
# b_fare_c = 1000,
# delta_b = 10e-10,
gamma_gender_a = 1e-2,
gamma_gender_b = 1e-3,
gamma_gender_c = 1e-2,
gamma_NoInc_a = 1e-2,
gamma_IncomeA_a = 1e-2,
gamma_IncomeB_a = 1e-2,
gamma_IncomeC_a = 1e-2,
gamma_IncomeD_a = 1e-2,
gamma_NoInc_b = 1e-2,
gamma_IncomeA_b = 1e-2,
gamma_IncomeB_b = 1e-2,
gamma_IncomeC_b = 1e-2,
gamma_IncomeD_b = 1e-2
)
))
# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #
apollo_modelOutput(model)
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO FILE, using model name) ----
# ----------------------------------------------------------------- #
#apollo_saveOutput(model)
# ################################################################# #
##### ADDITIONAL RESULTS ANALYSIS AND DIAGNOSTICS ####
# ################################################################# #
### Print the outputs of additional diagnostics to file (comment out sink to file command below if not desired)
### Remember to run the line closing any open sinks at the end of this file
sink(paste(model$apollo_control$modelName,"_additional_output.txt",sep=""),split=TRUE)
# ################################################################# #
##### CLOSE FILE WRITING ####
# ################################################################# #
apollo_lrTest(model,"COH base_model")
apollo_lrTest("COH heterogeneity income",model)
# switch off file writing if in use
if(sink.number()>0) sink()
Model Output:
> rm(list = ls())
>
> ### Load libraries
> library(apollo)
>
> ### Initialise code
> apollo_initialise()
Apollo ignition sequence completed
>
> ### Set core controls
> apollo_control = list(
+ modelName ="COH 3 latent class",
+ modelDescr ="MNL with three latent classes",
+ indivID ="id",
+ calculateLLC = FALSE,
+ nCores = 2,
+ noDiagnostics = TRUE,
+ outputDirectory = 'output'
+ )
>
> #database = read.csv("harare surbubs mode choice data.csv",header=TRUE)
> database = read.csv("CityOfHarare data.csv",header=TRUE)
>
> # ################################################################# #
> #### DEFINE MODEL PARAMETERS ####
> # ################################################################# #
>
> ### Vector of parameters, including any that are kept fixed in estimation
> apollo_beta=c(
+ asc_zupco = 0,
+ asc_kombi = 0,
+ asc_car_hh = 0,
+ b_accessT_a = 0,
+ b_waitingT_a = 0,
+ b_accessT_b = 0,
+ b_waitingT_b = 0,
+ b_accessT_c = 0,
+ b_waitingT_c = 0,
+ b_available = 0,
+ b_standing_a = 0,
+ b_kadoma_a = 0,
+ b_trailer_a = 0,
+ b_standing_b = 0,
+ b_kadoma_b = 0,
+ b_trailer_b = 0,
+ b_standing_c = 0,
+ b_kadoma_c = 0,
+ b_trailer_c = 0,
+ b_ivt_a = 0,
+ b_fare_a = 0,
+ b_ivt_c = 0,
+ b_fare_c = 0,
+ b_ivt_b = 0,
+ b_fare_b = 0,
+ delta_a = 0,
+ delta_b = 0,
+ delta_c = 0,
+ gamma_gender_a = 0,
+ gamma_gender_b = 0,
+ gamma_gender_c = 0,
+ gamma_NoInc_a = 0,
+ gamma_IncomeA_a = 0,
+ gamma_IncomeB_a = 0,
+ gamma_IncomeC_a = 0,
+ gamma_IncomeD_a = 0,
+ # gamma_none_a = 0,
+ # gamma_student_a = 0,
+ # gamma_informal_a = 0,
+ # gamma_formal_a = 0,
+ gamma_NoInc_b = 0,
+ gamma_IncomeA_b = 0,
+ gamma_IncomeB_b = 0,
+ gamma_IncomeC_b = 0,
+ gamma_IncomeD_b = 0
+ # gamma_none_b = 0,
+ # gamma_student_b = 0,
+ # gamma_informal_b = 0,
+ # gamma_formal_b = 0
+ )
>
> ### 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("asc_zupco","b_available","delta_a"
+ )
>
> # ################################################################# #
> #### DEFINE LATENT CLASS COMPONENTS ####
> # ################################################################# #
>
> apollo_lcPars=function(apollo_beta, apollo_inputs){
+ lcpars = list()
+ lcpars[["b_accessT"]] = list(
+ b_accessT_a,
+ b_accessT_b,
+ b_accessT_c
+ )
+ lcpars[["b_waitingT"]] = list(b_waitingT_a, b_waitingT_b, b_waitingT_c)
+ lcpars[["b_ivt"]] = list(b_ivt_a, b_ivt_b, b_ivt_c)
+ lcpars[["b_fare"]] = list(b_fare_a, b_fare_b, b_fare_c)
+ lcpars[["b_standing"]] = list(b_standing_a, b_standing_b, b_standing_c)
+ lcpars[["b_kadoma"]] = list(b_kadoma_a, b_kadoma_b, b_kadoma_c)
+ lcpars[["b_trailer"]] = list(b_trailer_a, b_trailer_b, b_trailer_c)
+
+ V=list()
+ gamma_Income_a = gamma_NoInc_a * (income == 0) + gamma_IncomeA_a * (income == 1) +
+ gamma_IncomeB_a * (income == 2) + gamma_IncomeC_a * (income == 3) +
+ gamma_IncomeD_a * (income == 4)
+
+ gamma_Income_b = gamma_NoInc_b* (income == 0) + gamma_IncomeA_b * (income == 1) +
+ gamma_IncomeB_b * (income == 2) + gamma_IncomeC_b * (income == 3) +
+ gamma_IncomeD_b * (income == 4)
+
+ # gamma_employment_a = gamma_none_a * (employment == 1) + gamma_student_a * (employment == 2) +
+ # gamma_informal_a * (employment == 3) + gamma_formal_a * (employment > 3)
+ #
+ # gamma_employment_b = gamma_none_b * (employment == 1) + gamma_student_b * (employment == 2) +
+ # gamma_informal_b * (employment == 3) + gamma_formal_b * (employment > 3)
+
+ V[["class_a"]] = delta_a + gamma_gender_a*gender + gamma_Income_a #+ gamma_employment_a
+ V[["class_b"]] = delta_b + gamma_gender_b*gender + gamma_Income_b #+ gamma_employment_b
+ V[["class_c"]] = delta_c + gamma_gender_c*gender
+
+ classAlloc_settings = list(
+ alternatives = c(class_a=1, class_b=2, class_c=3),
+ avail = 1,
+ V = V
+ )
+ lcpars[["pi_values"]] = apollo_classAlloc(classAlloc_settings)
+
+ return(lcpars)
+ }
>
> # ################################################################# #
> #### GROUP AND VALIDATE INPUTS ####
> # ################################################################# #
>
> apollo_inputs = apollo_validateInputs()
Several observations per individual detected based on the value of id. Setting panelData in
apollo_control set to TRUE.
All checks on apollo_control completed.
All checks on database completed.
>
> # ################################################################# #
> #### DEFINE MODEL AND LIKELIHOOD FUNCTION ####
> # ################################################################# #
>
> apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
+
+ ### 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()
+ ### Define settings for MNL model component
+ mnl_settings = list(
+ alternatives = c(zupco=2, car_hh=3, kombi=1),
+ avail = list(zupco=1, kombi=1, car_hh=1),
+ choiceVar = Choice
+ )
+
+ ### Loop over classes
+ for(s in 1:length(pi_values)){
+
+ ### Compute class-specific utilities
+ V=list()
+ V[['zupco']] = asc_zupco + b_accessT[[s]] * accessT_zupco + b_waitingT[[s]] * waitingT_zupco +
+ b_available * (seat_zupco == 0) + b_standing[[s]] * (seat_zupco == 3) +
+ b_ivt[[s]] * ivt_zupco + b_fare[[s]] * fare_zupco
+
+ V[['kombi']] = asc_kombi + b_accessT[[s]] * accessT_kombi + b_waitingT[[s]] * waitingT_kombi +
+ b_available * (seat_kombi == 0) + b_kadoma[[s]] * (seat_kombi == 1) +
+ b_ivt[[s]] * ivt_kombi + b_fare[[s]] * fare_kombi
+
+ V[['car_hh']] = asc_car_hh + b_accessT[[s]] * accessT_car_hh + b_waitingT[[s]] * waitingT_car_hh +
+ b_available * (seat_car_hh == 0) + b_trailer[[s]] * (seat_car_hh == 2) +
+ b_ivt[[s]] * ivt_car_hh + b_fare[[s]] * fare_car_hh
+ mnl_settings$V = V
+ mnl_settings$componentName = paste0("Class_",s)
+
+ ### Compute within-class choice probabilities using MNL model
+ P[[paste0("Class_",s)]] = apollo_mnl(mnl_settings, functionality)
+
+ ### Take product across observation for same individual
+ P[[paste0("Class_",s)]] = apollo_panelProd(P[[paste0("Class_",s)]], apollo_inputs ,functionality)
+ }
+
+ ### Compute latent class model probabilities
+ lc_settings = list(inClassProb = P, classProb=pi_values)
+ P[["model"]] = apollo_lc(lc_settings, apollo_inputs, functionality)
+
+ ### Prepare and return outputs of function
+ P = apollo_prepareProb(P, apollo_inputs, functionality)
+ return(P)
+ }
>
> # ################################################################# #
> #### MODEL ESTIMATION ####
> # ################################################################# #
>
> model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs,
+ estimate_settings = list(
+ scaling = c(
+ # b_accessT_a = 1000,
+ # b_waitingT_a = 1000,
+ # b_accessT_b = 1,
+ # b_waitingT_b = 1000,
+ # b_accessT_c = 1000,
+ # b_waitingT_c = 1000,
+ # b_ivt_a = 1000,
+ # b_fare_a = 1000,
+ # b_ivt_b = 1000,
+ # b_fare_b = 1000,
+ # b_ivt_c = 1000,
+ # b_fare_c = 1000,
+ # delta_b = 10e-10,
+ gamma_gender_a = 1e-2,
+ gamma_gender_b = 1e-3,
+ gamma_gender_c = 1e-2,
+ gamma_NoInc_a = 1e-2,
+ gamma_IncomeA_a = 1e-2,
+ gamma_IncomeB_a = 1e-2,
+ gamma_IncomeC_a = 1e-2,
+ gamma_IncomeD_a = 1e-2,
+ gamma_NoInc_b = 1e-2,
+ gamma_IncomeA_b = 1e-2,
+ gamma_IncomeB_b = 1e-2,
+ gamma_IncomeC_b = 1e-2,
+ gamma_IncomeD_b = 1e-2
+ )
+ ))
During estimation, parameters will be scaled using the values in estimate_settings$scaling
Testing likelihood function...
Apollo found a model component of type classAlloc without a componentName. The name was set to
"classAlloc" by default.
Class probability for model component "model" averaged across observations of each individual.
Pre-processing likelihood function...
Preparing workers for multithreading...
Analytical gradient is different to numerical one. Numerical gradients will be used.
Testing influence of parameters......................................
Starting main estimation
Initial function value: -3172.792
Initial gradient value:
asc_kombi asc_car_hh b_accessT_a b_waitingT_a b_accessT_b b_waitingT_b
2.493333e+02 -2.596667e+02 -7.522222e+02 -2.927778e+02 -7.522222e+02 -2.927778e+02
b_accessT_c b_waitingT_c b_standing_a b_kadoma_a b_trailer_a b_standing_b
-7.522222e+02 -2.927778e+02 -3.366667e+01 5.555557e-01 -1.003333e+02 -3.366667e+01
b_kadoma_b b_trailer_b b_standing_c b_kadoma_c b_trailer_c b_ivt_a
5.555557e-01 -1.003333e+02 -3.366667e+01 5.555557e-01 -1.003333e+02 -3.564556e+03
b_fare_a b_ivt_c b_fare_c b_ivt_b b_fare_b delta_b
-1.407833e+04 -3.564556e+03 -1.407833e+04 -3.564556e+03 -1.407833e+04 0.000000e+00
delta_c gamma_gender_a gamma_gender_b gamma_gender_c gamma_NoInc_a gamma_IncomeA_a
0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
gamma_IncomeB_a gamma_IncomeC_a gamma_IncomeD_a gamma_NoInc_b gamma_IncomeA_b gamma_IncomeB_b
0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
gamma_IncomeC_b gamma_IncomeD_b
0.000000e+00 0.000000e+00
initial value 3172.792290
iter 2 value 2475.132011
iter 3 value 2450.691580
iter 4 value 2348.672396
iter 5 value 2072.926917
iter 6 value 2069.099768
iter 7 value 2034.325634
iter 8 value 1946.134411
iter 9 value 1720.793772
iter 10 value 1720.093532
iter 11 value 1712.789885
iter 12 value 1677.110373
iter 13 value 1667.080039
iter 14 value 1650.603691
iter 15 value 1635.423301
iter 16 value 1631.724643
iter 17 value 1628.971658
iter 18 value 1614.071079
iter 19 value 1611.378907
iter 20 value 1607.847534
iter 21 value 1593.179264
iter 22 value 1583.142408
iter 23 value 1579.141794
iter 24 value 1573.994857
iter 25 value 1571.701179
iter 26 value 1569.079040
iter 27 value 1564.357863
iter 28 value 1562.096257
iter 29 value 1560.609604
iter 30 value 1559.560906
iter 31 value 1558.320240
iter 32 value 1555.631864
iter 33 value 1554.382785
iter 34 value 1552.003636
iter 35 value 1548.904749
iter 36 value 1546.827775
iter 37 value 1540.740013
iter 38 value 1538.168092
iter 39 value 1536.946348
iter 40 value 1534.421992
iter 41 value 1532.808748
iter 42 value 1531.409010
iter 43 value 1530.049491
iter 44 value 1529.224814
iter 45 value 1528.257411
iter 46 value 1526.622741
iter 47 value 1522.915467
iter 48 value 1518.591480
iter 49 value 1513.784433
iter 50 value 1505.703343
iter 51 value 1500.459703
iter 52 value 1498.275424
iter 53 value 1497.017497
iter 54 value 1495.620968
iter 55 value 1494.166366
iter 56 value 1492.864888
iter 57 value 1491.842191
iter 58 value 1491.432014
iter 59 value 1491.205563
iter 60 value 1491.101259
iter 61 value 1491.022806
iter 62 value 1490.921574
iter 63 value 1490.797303
iter 64 value 1490.635514
iter 65 value 1490.400966
iter 66 value 1489.989007
iter 67 value 1489.215964
iter 68 value 1487.903341
iter 69 value 1486.123533
iter 70 value 1484.146667
iter 71 value 1482.044221
iter 72 value 1479.800045
iter 73 value 1478.552980
iter 74 value 1477.279446
iter 75 value 1476.723263
iter 76 value 1475.807229
iter 77 value 1475.291486
iter 78 value 1474.921278
iter 79 value 1474.716610
iter 80 value 1474.686353
iter 81 value 1474.665050
iter 82 value 1474.645392
iter 83 value 1474.609638
iter 84 value 1474.529508
iter 85 value 1474.337063
iter 86 value 1474.325809
iter 87 value 1474.322444
iter 88 value 1474.318082
iter 89 value 1474.310959
iter 90 value 1474.309770
iter 91 value 1474.306478
iter 92 value 1474.293756
iter 93 value 1474.271078
iter 94 value 1474.266374
iter 95 value 1474.261768
iter 96 value 1474.241262
iter 97 value 1474.236788
iter 98 value 1474.230984
iter 99 value 1474.224987
iter 100 value 1474.220574
iter 101 value 1474.213670
iter 102 value 1474.212471
iter 103 value 1474.207815
iter 104 value 1474.201697
iter 105 value 1474.198747
iter 106 value 1474.191328
iter 107 value 1474.187450
iter 108 value 1474.186525
iter 109 value 1474.175060
iter 110 value 1474.172785
iter 111 value 1474.090963
iter 112 value 1474.022694
iter 113 value 1473.811828
iter 114 value 1473.053320
iter 115 value 1471.981946
iter 116 value 1471.169127
iter 117 value 1470.907424
iter 118 value 1470.879816
iter 119 value 1470.877246
iter 120 value 1470.873677
iter 121 value 1470.864929
iter 122 value 1470.842540
iter 123 value 1470.789715
iter 124 value 1470.681660
iter 125 value 1470.526202
iter 126 value 1470.409975
iter 127 value 1470.374547
iter 128 value 1470.370689
iter 129 value 1470.370256
iter 130 value 1470.369297
iter 131 value 1470.366877
iter 132 value 1470.360609
iter 133 value 1470.345147
iter 134 value 1470.309876
iter 135 value 1470.243884
iter 136 value 1470.161085
iter 137 value 1470.109814
iter 138 value 1470.098648
iter 139 value 1470.097653
iter 140 value 1470.097388
iter 141 value 1470.096628
iter 142 value 1470.094827
iter 143 value 1470.090071
iter 144 value 1470.078679
iter 145 value 1470.053778
iter 146 value 1470.012236
iter 147 value 1469.971074
iter 148 value 1469.953234
iter 149 value 1469.950281
iter 150 value 1469.950064
iter 151 value 1469.950010
iter 152 value 1469.949825
iter 153 value 1469.949406
iter 154 value 1469.948272
iter 155 value 1469.945507
iter 156 value 1469.939051
iter 157 value 1469.926714
iter 158 value 1469.910606
iter 159 value 1469.900245
iter 160 value 1469.897917
iter 161 value 1469.897754
iter 161 value 1469.897748
iter 161 value 1469.897748
final value 1469.897748
converged
Additional convergence test using scaled estimation. Parameters will be scaled by their current
estimates and additional iterations will be performed.
initial value 1469.897748
iter 2 value 1469.897273
iter 3 value 1469.896975
iter 4 value 1469.896321
iter 5 value 1469.896045
iter 6 value 1469.895983
iter 7 value 1469.895935
iter 8 value 1469.895869
iter 9 value 1469.895685
iter 10 value 1469.895538
iter 11 value 1469.895444
iter 12 value 1469.895303
iter 13 value 1469.895246
iter 14 value 1469.895159
iter 14 value 1469.895152
iter 14 value 1469.895142
final value 1469.895142
converged
Estimated parameters:
Estimate
asc_zupco 0.00000
asc_kombi 1.59143
asc_car_hh 0.12403
b_accessT_a -0.16475
b_waitingT_a -0.04260
b_accessT_b -0.18082
b_waitingT_b -0.07467
b_accessT_c -0.32334
b_waitingT_c -0.10382
b_available 0.00000
b_standing_a -1.65019
b_kadoma_a -2.15242
b_trailer_a -1.81785
b_standing_b -2.87457
b_kadoma_b -1.49531
b_trailer_b -1.94864
b_standing_c -3.72152
b_kadoma_c -2.25701
b_trailer_c -4.84660
b_ivt_a -0.02788
b_fare_a -0.03065
b_ivt_c -0.05188
b_fare_c -0.13069
b_ivt_b -0.06108
b_fare_b -1.15582
delta_a 0.00000
delta_b -2.92261
delta_c 0.20900
gamma_gender_a -3.33787
gamma_gender_b 0.05746
gamma_gender_c -2.41582
gamma_NoInc_a -1.07746
gamma_IncomeA_a -1.17902
gamma_IncomeB_a -0.23606
gamma_IncomeC_a 1.10726
gamma_IncomeD_a 1.40801
gamma_NoInc_b 0.97724
gamma_IncomeA_b 1.30420
gamma_IncomeB_b 0.43908
gamma_IncomeC_b -1.97067
gamma_IncomeD_b -0.74524
Computing covariance matrix using numerical methods (numDeriv).
0%....25%....50%....75%....100%
WARNING: Some eigenvalues of the Hessian are positive, indicating convergence to a saddle point!
Computing score matrix...
Summary of class allocation for LC model component :
Mean prob.
Class_1 0.3459
Class_2 0.1794
Class_3 0.4747
Calculating LL(0) for applicable models...
Calculating LL of each model component...
Warning message:
In sqrt(diag(robvarcov)) : NaNs produced
>
> # ################################################################# #
> #### MODEL OUTPUTS ####
> # ################################################################# #
>
> # ----------------------------------------------------------------- #
> #---- FORMATTED OUTPUT (TO SCREEN) ----
> # ----------------------------------------------------------------- #
>
> apollo_modelOutput(model)
Model run using Apollo for R, version 0.2.6 on Darwin by mapfuriramasimbatutsirai
www.ApolloChoiceModelling.com
Model name : COH 3 latent class
Model description : MNL with three latent classes
Model run at : 2021-12-16 11:19:06
Estimation method : bfgs
Model diagnosis : successful convergence
Number of individuals : 361
Number of rows in database : 2888
Number of modelled outcomes : 2888
Number of cores used : 2
Model without mixing
LL(start) : -3172.792
LL(0, whole model) : -3172.792
LL(C, whole model) : Not applicable
LL(final, whole model) : -1469.895
Rho-square (0) : 0.5367
Adj.Rho-square (0) : 0.5247
AIC : 3015.79
BIC : 3242.59
LL(0,Class_1) : -3172.792
LL(final,Class_1) : -2061.203
LL(0,Class_2) : -3172.792
LL(final,Class_2) : -25476.38
LL(0,Class_3) : -3172.792
LL(final,Class_3) : -2130.269
Estimated parameters : 38
Time taken (hh:mm:ss) : 00:01:52.91
pre-estimation : 00:00:7.04
estimation : 00:01:13.34
post-estimation : 00:00:32.52
Iterations : 180
Min abs eigenvalue of Hessian : 0
Unconstrained optimisation.
These outputs have had the scaling used in estimation applied to them.
Estimates:
Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0)
asc_zupco 0.00000 NA NA NA NA
asc_kombi 1.59143 0.113684 13.998768 0.106164 14.99027
asc_car_hh 0.12403 0.184386 0.672655 0.205754 0.60280
b_accessT_a -0.16475 0.015715 -10.483700 0.025146 -6.55178
b_waitingT_a -0.04260 0.015332 -2.778502 0.016463 -2.58764
b_accessT_b -0.18082 0.048725 -3.711096 0.052691 -3.43182
b_waitingT_b -0.07467 0.057913 -1.289262 0.055938 -1.33477
b_accessT_c -0.32334 0.028422 -11.376360 0.027751 -11.65140
b_waitingT_c -0.10382 0.024724 -4.199174 0.029369 -3.53514
b_available 0.00000 NA NA NA NA
b_standing_a -1.65019 0.232288 -7.104093 0.324661 -5.08282
b_kadoma_a -2.15242 0.174674 -12.322536 0.186423 -11.54593
b_trailer_a -1.81785 0.242577 -7.493917 0.430618 -4.22150
b_standing_b -2.87457 0.992779 -2.895480 1.044760 -2.75142
b_kadoma_b -1.49531 0.453991 -3.293690 0.395655 -3.77932
b_trailer_b -1.94864 0.576904 -3.377759 0.535161 -3.64123
b_standing_c -3.72152 0.434776 -8.559632 0.470552 -7.90885
b_kadoma_c -2.25701 0.249956 -9.029613 0.212694 -10.61151
b_trailer_c -4.84660 0.513237 -9.443198 0.693184 -6.99179
b_ivt_a -0.02788 0.004242 -6.572043 0.005962 -4.67672
b_fare_a -0.03065 0.003578 -8.564745 0.006364 -4.81573
b_ivt_c -0.05188 0.008808 -5.890603 0.013030 -3.98185
b_fare_c -0.13069 0.012536 -10.425065 0.019497 -6.70321
b_ivt_b -0.06108 0.021646 -2.821643 0.022931 -2.66357
b_fare_b -1.15582 2.898e+04 -3.988e-05 56.024482 -0.02063
delta_a 0.00000 NA NA NA NA
delta_b -2.92261 7861.510074 -3.7176e-04 0.923314 -3.16535
delta_c 0.20900 2317.051553 9.020e-05 1.579206 0.13234
gamma_gender_a -3.33787 1598.774002 -0.002088 3.032322 -1.10076
gamma_gender_b 0.05746 1598.773905 3.594e-05 2.995820 0.01918
gamma_gender_c -2.41582 1598.774060 -0.001511 2.994953 -0.80663
gamma_NoInc_a -1.07746 2317.051663 -4.6502e-04 1.444127 -0.74610
gamma_IncomeA_a -1.17902 2317.051652 -5.0885e-04 NaN NaN
gamma_IncomeB_a -0.23606 2317.051611 -1.0188e-04 2.630040 -0.08975
gamma_IncomeC_a 1.10726 2317.051588 4.7787e-04 NaN NaN
gamma_IncomeD_a 1.40801 2317.051702 6.0767e-04 1.563808 0.90037
gamma_NoInc_b 0.97724 4033.647102 2.4227e-04 2.591742 0.37706
gamma_IncomeA_b 1.30420 4033.647098 3.2333e-04 1.250284 1.04312
gamma_IncomeB_b 0.43908 4033.647071 1.0885e-04 1.438180 0.30530
gamma_IncomeC_b -1.97067 4033.647142 -4.8856e-04 1.934733 -1.01857
gamma_IncomeD_b -0.74524 4033.647206 -1.8476e-04 0.217316 -3.42931
Summary of class allocation for LC model component :
Mean prob.
Class_1 0.3459
Class_2 0.1794
Class_3 0.4747
>
> # ----------------------------------------------------------------- #
> #---- FORMATTED OUTPUT (TO FILE, using model name) ----
> # ----------------------------------------------------------------- #
>
> #apollo_saveOutput(model)
>
> # ################################################################# #
> ##### ADDITIONAL RESULTS ANALYSIS AND DIAGNOSTICS ####
> # ################################################################# #
>
> ### Print the outputs of additional diagnostics to file (comment out sink to file command below if not desired)
> ### Remember to run the line closing any open sinks at the end of this file
> sink(paste(model$apollo_control$modelName,"_additional_output.txt",sep=""),split=TRUE)
>
> # ################################################################# #
> ##### CLOSE FILE WRITING ####
> # ################################################################# #
>
> apollo_lrTest(model,"COH base_model")
The order of your two models will be reversed in the output as model 1 has better fit than model
2.
LL par
COH base_model -1714.79 9
COH 3 latent class -1469.90 38
Difference 244.89 29
Likelihood ratio test-value: 489.78
Degrees of freedom: 29
Likelihood ratio test p-value: 3.612e-85
> apollo_lrTest("COH heterogeneity income",model)
LL par
COH heterogeneity income -1619.9 13
COH 3 latent class -1469.9 38
Difference 150.0 25
Likelihood ratio test-value: 300
Degrees of freedom: 25
Likelihood ratio test p-value: 6.012e-49
>
> # switch off file writing if in use
>
> if(sink.number()>0) sink()
Thanks and regards
Tutsie.
I’m estimating a latent class model with 3 classes and every time I introduce gamma variables to specify the class allocation utility function, I get NaN standard errors. I have tried to play around with the scaling function (trial and error) but I still get NaN and the warning messages:
Warning messages:
1: In sqrt(diag(varcov)) : NaNs produced
2: In sqrt(diag(robvarcov)) : NaNs produced
Is there any other way to resolve this? I have attached my code and the data.
Here is the code:
### Clear memory
rm(list = ls())
### Load libraries
library(apollo)
### Initialise code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName ="COH 3 latent class",
modelDescr ="MNL with three latent classes",
indivID ="id",
calculateLLC = FALSE,
nCores = 2,
noDiagnostics = TRUE,
outputDirectory = 'output'
)
database = read.csv("CityOfHarare data.csv",header=TRUE)
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(
asc_zupco = 0,
asc_kombi = 0,
asc_car_hh = 0,
b_accessT_a = 0,
b_waitingT_a = 0,
b_accessT_b = 0,
b_waitingT_b = 0,
b_accessT_c = 0,
b_waitingT_c = 0,
b_available = 0,
b_standing_a = 0,
b_kadoma_a = 0,
b_trailer_a = 0,
b_standing_b = 0,
b_kadoma_b = 0,
b_trailer_b = 0,
b_standing_c = 0,
b_kadoma_c = 0,
b_trailer_c = 0,
b_ivt_a = 0,
b_fare_a = 0,
b_ivt_c = 0,
b_fare_c = 0,
b_ivt_b = 0,
b_fare_b = 0,
delta_a = 0,
delta_b = 0,
delta_c = 0,
gamma_gender_a = 0,
gamma_gender_b = 0,
gamma_gender_c = 0,
gamma_NoInc_a = 0,
gamma_IncomeA_a = 0,
gamma_IncomeB_a = 0,
gamma_IncomeC_a = 0,
gamma_IncomeD_a = 0,
# gamma_none_a = 0,
# gamma_student_a = 0,
# gamma_informal_a = 0,
# gamma_formal_a = 0,
gamma_NoInc_b = 0,
gamma_IncomeA_b = 0,
gamma_IncomeB_b = 0,
gamma_IncomeC_b = 0,
gamma_IncomeD_b = 0
# gamma_none_b = 0,
# gamma_student_b = 0,
# gamma_informal_b = 0,
# gamma_formal_b = 0
)
### 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("asc_zupco","b_available","delta_a"
)
# ################################################################# #
#### DEFINE LATENT CLASS COMPONENTS ####
# ################################################################# #
apollo_lcPars=function(apollo_beta, apollo_inputs){
lcpars = list()
lcpars[["b_accessT"]] = list(
b_accessT_a,
b_accessT_b,
b_accessT_c
)
lcpars[["b_waitingT"]] = list(b_waitingT_a, b_waitingT_b, b_waitingT_c)
lcpars[["b_ivt"]] = list(b_ivt_a, b_ivt_b, b_ivt_c)
lcpars[["b_fare"]] = list(b_fare_a, b_fare_b, b_fare_c)
lcpars[["b_standing"]] = list(b_standing_a, b_standing_b, b_standing_c)
lcpars[["b_kadoma"]] = list(b_kadoma_a, b_kadoma_b, b_kadoma_c)
lcpars[["b_trailer"]] = list(b_trailer_a, b_trailer_b, b_trailer_c)
V=list()
gamma_Income_a = gamma_NoInc_a * (income == 0) + gamma_IncomeA_a * (income == 1) +
gamma_IncomeB_a * (income == 2) + gamma_IncomeC_a * (income == 3) +
gamma_IncomeD_a * (income == 4)
gamma_Income_b = gamma_NoInc_b* (income == 0) + gamma_IncomeA_b * (income == 1) +
gamma_IncomeB_b * (income == 2) + gamma_IncomeC_b * (income == 3) +
gamma_IncomeD_b * (income == 4)
# gamma_employment_a = gamma_none_a * (employment == 1) + gamma_student_a * (employment == 2) +
# gamma_informal_a * (employment == 3) + gamma_formal_a * (employment > 3)
#
# gamma_employment_b = gamma_none_b * (employment == 1) + gamma_student_b * (employment == 2) +
# gamma_informal_b * (employment == 3) + gamma_formal_b * (employment > 3)
V[["class_a"]] = delta_a + gamma_gender_a*gender + gamma_Income_a #+ gamma_employment_a
V[["class_b"]] = delta_b + gamma_gender_b*gender + gamma_Income_b #+ gamma_employment_b
V[["class_c"]] = delta_c + gamma_gender_c*gender
classAlloc_settings = list(
alternatives = c(class_a=1, class_b=2, class_c=3),
avail = 1,
V = V
)
lcpars[["pi_values"]] = apollo_classAlloc(classAlloc_settings)
return(lcpars)
}
# ################################################################# #
#### GROUP AND VALIDATE INPUTS ####
# ################################################################# #
apollo_inputs = apollo_validateInputs()
# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION ####
# ################################################################# #
apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
### 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()
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(zupco=2, car_hh=3, kombi=1),
avail = list(zupco=1, kombi=1, car_hh=1),
choiceVar = Choice
)
### Loop over classes
for(s in 1:length(pi_values)){
### Compute class-specific utilities
V=list()
V[['zupco']] = asc_zupco + b_accessT[[s]] * accessT_zupco + b_waitingT[[s]] * waitingT_zupco +
b_available * (seat_zupco == 0) + b_standing[[s]] * (seat_zupco == 3) +
b_ivt[[s]] * ivt_zupco + b_fare[[s]] * fare_zupco
V[['kombi']] = asc_kombi + b_accessT[[s]] * accessT_kombi + b_waitingT[[s]] * waitingT_kombi +
b_available * (seat_kombi == 0) + b_kadoma[[s]] * (seat_kombi == 1) +
b_ivt[[s]] * ivt_kombi + b_fare[[s]] * fare_kombi
V[['car_hh']] = asc_car_hh + b_accessT[[s]] * accessT_car_hh + b_waitingT[[s]] * waitingT_car_hh +
b_available * (seat_car_hh == 0) + b_trailer[[s]] * (seat_car_hh == 2) +
b_ivt[[s]] * ivt_car_hh + b_fare[[s]] * fare_car_hh
mnl_settings$V = V
mnl_settings$componentName = paste0("Class_",s)
### Compute within-class choice probabilities using MNL model
P[[paste0("Class_",s)]] = apollo_mnl(mnl_settings, functionality)
### Take product across observation for same individual
P[[paste0("Class_",s)]] = apollo_panelProd(P[[paste0("Class_",s)]], apollo_inputs ,functionality)
}
### Compute latent class model probabilities
lc_settings = list(inClassProb = P, classProb=pi_values)
P[["model"]] = apollo_lc(lc_settings, apollo_inputs, functionality)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
# ################################################################# #
#### MODEL ESTIMATION ####
# ################################################################# #
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs,
estimate_settings = list(
scaling = c(
# b_accessT_a = 1000,
# b_waitingT_a = 1000,
# b_accessT_b = 1,
# b_waitingT_b = 1000,
# b_accessT_c = 1000,
# b_waitingT_c = 1000,
# b_ivt_a = 1000,
# b_fare_a = 1000,
# b_ivt_b = 1000,
# b_fare_b = 1000,
# b_ivt_c = 1000,
# b_fare_c = 1000,
# delta_b = 10e-10,
gamma_gender_a = 1e-2,
gamma_gender_b = 1e-3,
gamma_gender_c = 1e-2,
gamma_NoInc_a = 1e-2,
gamma_IncomeA_a = 1e-2,
gamma_IncomeB_a = 1e-2,
gamma_IncomeC_a = 1e-2,
gamma_IncomeD_a = 1e-2,
gamma_NoInc_b = 1e-2,
gamma_IncomeA_b = 1e-2,
gamma_IncomeB_b = 1e-2,
gamma_IncomeC_b = 1e-2,
gamma_IncomeD_b = 1e-2
)
))
# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #
apollo_modelOutput(model)
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO FILE, using model name) ----
# ----------------------------------------------------------------- #
#apollo_saveOutput(model)
# ################################################################# #
##### ADDITIONAL RESULTS ANALYSIS AND DIAGNOSTICS ####
# ################################################################# #
### Print the outputs of additional diagnostics to file (comment out sink to file command below if not desired)
### Remember to run the line closing any open sinks at the end of this file
sink(paste(model$apollo_control$modelName,"_additional_output.txt",sep=""),split=TRUE)
# ################################################################# #
##### CLOSE FILE WRITING ####
# ################################################################# #
apollo_lrTest(model,"COH base_model")
apollo_lrTest("COH heterogeneity income",model)
# switch off file writing if in use
if(sink.number()>0) sink()
Model Output:
> rm(list = ls())
>
> ### Load libraries
> library(apollo)
>
> ### Initialise code
> apollo_initialise()
Apollo ignition sequence completed
>
> ### Set core controls
> apollo_control = list(
+ modelName ="COH 3 latent class",
+ modelDescr ="MNL with three latent classes",
+ indivID ="id",
+ calculateLLC = FALSE,
+ nCores = 2,
+ noDiagnostics = TRUE,
+ outputDirectory = 'output'
+ )
>
> #database = read.csv("harare surbubs mode choice data.csv",header=TRUE)
> database = read.csv("CityOfHarare data.csv",header=TRUE)
>
> # ################################################################# #
> #### DEFINE MODEL PARAMETERS ####
> # ################################################################# #
>
> ### Vector of parameters, including any that are kept fixed in estimation
> apollo_beta=c(
+ asc_zupco = 0,
+ asc_kombi = 0,
+ asc_car_hh = 0,
+ b_accessT_a = 0,
+ b_waitingT_a = 0,
+ b_accessT_b = 0,
+ b_waitingT_b = 0,
+ b_accessT_c = 0,
+ b_waitingT_c = 0,
+ b_available = 0,
+ b_standing_a = 0,
+ b_kadoma_a = 0,
+ b_trailer_a = 0,
+ b_standing_b = 0,
+ b_kadoma_b = 0,
+ b_trailer_b = 0,
+ b_standing_c = 0,
+ b_kadoma_c = 0,
+ b_trailer_c = 0,
+ b_ivt_a = 0,
+ b_fare_a = 0,
+ b_ivt_c = 0,
+ b_fare_c = 0,
+ b_ivt_b = 0,
+ b_fare_b = 0,
+ delta_a = 0,
+ delta_b = 0,
+ delta_c = 0,
+ gamma_gender_a = 0,
+ gamma_gender_b = 0,
+ gamma_gender_c = 0,
+ gamma_NoInc_a = 0,
+ gamma_IncomeA_a = 0,
+ gamma_IncomeB_a = 0,
+ gamma_IncomeC_a = 0,
+ gamma_IncomeD_a = 0,
+ # gamma_none_a = 0,
+ # gamma_student_a = 0,
+ # gamma_informal_a = 0,
+ # gamma_formal_a = 0,
+ gamma_NoInc_b = 0,
+ gamma_IncomeA_b = 0,
+ gamma_IncomeB_b = 0,
+ gamma_IncomeC_b = 0,
+ gamma_IncomeD_b = 0
+ # gamma_none_b = 0,
+ # gamma_student_b = 0,
+ # gamma_informal_b = 0,
+ # gamma_formal_b = 0
+ )
>
> ### 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("asc_zupco","b_available","delta_a"
+ )
>
> # ################################################################# #
> #### DEFINE LATENT CLASS COMPONENTS ####
> # ################################################################# #
>
> apollo_lcPars=function(apollo_beta, apollo_inputs){
+ lcpars = list()
+ lcpars[["b_accessT"]] = list(
+ b_accessT_a,
+ b_accessT_b,
+ b_accessT_c
+ )
+ lcpars[["b_waitingT"]] = list(b_waitingT_a, b_waitingT_b, b_waitingT_c)
+ lcpars[["b_ivt"]] = list(b_ivt_a, b_ivt_b, b_ivt_c)
+ lcpars[["b_fare"]] = list(b_fare_a, b_fare_b, b_fare_c)
+ lcpars[["b_standing"]] = list(b_standing_a, b_standing_b, b_standing_c)
+ lcpars[["b_kadoma"]] = list(b_kadoma_a, b_kadoma_b, b_kadoma_c)
+ lcpars[["b_trailer"]] = list(b_trailer_a, b_trailer_b, b_trailer_c)
+
+ V=list()
+ gamma_Income_a = gamma_NoInc_a * (income == 0) + gamma_IncomeA_a * (income == 1) +
+ gamma_IncomeB_a * (income == 2) + gamma_IncomeC_a * (income == 3) +
+ gamma_IncomeD_a * (income == 4)
+
+ gamma_Income_b = gamma_NoInc_b* (income == 0) + gamma_IncomeA_b * (income == 1) +
+ gamma_IncomeB_b * (income == 2) + gamma_IncomeC_b * (income == 3) +
+ gamma_IncomeD_b * (income == 4)
+
+ # gamma_employment_a = gamma_none_a * (employment == 1) + gamma_student_a * (employment == 2) +
+ # gamma_informal_a * (employment == 3) + gamma_formal_a * (employment > 3)
+ #
+ # gamma_employment_b = gamma_none_b * (employment == 1) + gamma_student_b * (employment == 2) +
+ # gamma_informal_b * (employment == 3) + gamma_formal_b * (employment > 3)
+
+ V[["class_a"]] = delta_a + gamma_gender_a*gender + gamma_Income_a #+ gamma_employment_a
+ V[["class_b"]] = delta_b + gamma_gender_b*gender + gamma_Income_b #+ gamma_employment_b
+ V[["class_c"]] = delta_c + gamma_gender_c*gender
+
+ classAlloc_settings = list(
+ alternatives = c(class_a=1, class_b=2, class_c=3),
+ avail = 1,
+ V = V
+ )
+ lcpars[["pi_values"]] = apollo_classAlloc(classAlloc_settings)
+
+ return(lcpars)
+ }
>
> # ################################################################# #
> #### GROUP AND VALIDATE INPUTS ####
> # ################################################################# #
>
> apollo_inputs = apollo_validateInputs()
Several observations per individual detected based on the value of id. Setting panelData in
apollo_control set to TRUE.
All checks on apollo_control completed.
All checks on database completed.
>
> # ################################################################# #
> #### DEFINE MODEL AND LIKELIHOOD FUNCTION ####
> # ################################################################# #
>
> apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
+
+ ### 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()
+ ### Define settings for MNL model component
+ mnl_settings = list(
+ alternatives = c(zupco=2, car_hh=3, kombi=1),
+ avail = list(zupco=1, kombi=1, car_hh=1),
+ choiceVar = Choice
+ )
+
+ ### Loop over classes
+ for(s in 1:length(pi_values)){
+
+ ### Compute class-specific utilities
+ V=list()
+ V[['zupco']] = asc_zupco + b_accessT[[s]] * accessT_zupco + b_waitingT[[s]] * waitingT_zupco +
+ b_available * (seat_zupco == 0) + b_standing[[s]] * (seat_zupco == 3) +
+ b_ivt[[s]] * ivt_zupco + b_fare[[s]] * fare_zupco
+
+ V[['kombi']] = asc_kombi + b_accessT[[s]] * accessT_kombi + b_waitingT[[s]] * waitingT_kombi +
+ b_available * (seat_kombi == 0) + b_kadoma[[s]] * (seat_kombi == 1) +
+ b_ivt[[s]] * ivt_kombi + b_fare[[s]] * fare_kombi
+
+ V[['car_hh']] = asc_car_hh + b_accessT[[s]] * accessT_car_hh + b_waitingT[[s]] * waitingT_car_hh +
+ b_available * (seat_car_hh == 0) + b_trailer[[s]] * (seat_car_hh == 2) +
+ b_ivt[[s]] * ivt_car_hh + b_fare[[s]] * fare_car_hh
+ mnl_settings$V = V
+ mnl_settings$componentName = paste0("Class_",s)
+
+ ### Compute within-class choice probabilities using MNL model
+ P[[paste0("Class_",s)]] = apollo_mnl(mnl_settings, functionality)
+
+ ### Take product across observation for same individual
+ P[[paste0("Class_",s)]] = apollo_panelProd(P[[paste0("Class_",s)]], apollo_inputs ,functionality)
+ }
+
+ ### Compute latent class model probabilities
+ lc_settings = list(inClassProb = P, classProb=pi_values)
+ P[["model"]] = apollo_lc(lc_settings, apollo_inputs, functionality)
+
+ ### Prepare and return outputs of function
+ P = apollo_prepareProb(P, apollo_inputs, functionality)
+ return(P)
+ }
>
> # ################################################################# #
> #### MODEL ESTIMATION ####
> # ################################################################# #
>
> model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs,
+ estimate_settings = list(
+ scaling = c(
+ # b_accessT_a = 1000,
+ # b_waitingT_a = 1000,
+ # b_accessT_b = 1,
+ # b_waitingT_b = 1000,
+ # b_accessT_c = 1000,
+ # b_waitingT_c = 1000,
+ # b_ivt_a = 1000,
+ # b_fare_a = 1000,
+ # b_ivt_b = 1000,
+ # b_fare_b = 1000,
+ # b_ivt_c = 1000,
+ # b_fare_c = 1000,
+ # delta_b = 10e-10,
+ gamma_gender_a = 1e-2,
+ gamma_gender_b = 1e-3,
+ gamma_gender_c = 1e-2,
+ gamma_NoInc_a = 1e-2,
+ gamma_IncomeA_a = 1e-2,
+ gamma_IncomeB_a = 1e-2,
+ gamma_IncomeC_a = 1e-2,
+ gamma_IncomeD_a = 1e-2,
+ gamma_NoInc_b = 1e-2,
+ gamma_IncomeA_b = 1e-2,
+ gamma_IncomeB_b = 1e-2,
+ gamma_IncomeC_b = 1e-2,
+ gamma_IncomeD_b = 1e-2
+ )
+ ))
During estimation, parameters will be scaled using the values in estimate_settings$scaling
Testing likelihood function...
Apollo found a model component of type classAlloc without a componentName. The name was set to
"classAlloc" by default.
Class probability for model component "model" averaged across observations of each individual.
Pre-processing likelihood function...
Preparing workers for multithreading...
Analytical gradient is different to numerical one. Numerical gradients will be used.
Testing influence of parameters......................................
Starting main estimation
Initial function value: -3172.792
Initial gradient value:
asc_kombi asc_car_hh b_accessT_a b_waitingT_a b_accessT_b b_waitingT_b
2.493333e+02 -2.596667e+02 -7.522222e+02 -2.927778e+02 -7.522222e+02 -2.927778e+02
b_accessT_c b_waitingT_c b_standing_a b_kadoma_a b_trailer_a b_standing_b
-7.522222e+02 -2.927778e+02 -3.366667e+01 5.555557e-01 -1.003333e+02 -3.366667e+01
b_kadoma_b b_trailer_b b_standing_c b_kadoma_c b_trailer_c b_ivt_a
5.555557e-01 -1.003333e+02 -3.366667e+01 5.555557e-01 -1.003333e+02 -3.564556e+03
b_fare_a b_ivt_c b_fare_c b_ivt_b b_fare_b delta_b
-1.407833e+04 -3.564556e+03 -1.407833e+04 -3.564556e+03 -1.407833e+04 0.000000e+00
delta_c gamma_gender_a gamma_gender_b gamma_gender_c gamma_NoInc_a gamma_IncomeA_a
0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
gamma_IncomeB_a gamma_IncomeC_a gamma_IncomeD_a gamma_NoInc_b gamma_IncomeA_b gamma_IncomeB_b
0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
gamma_IncomeC_b gamma_IncomeD_b
0.000000e+00 0.000000e+00
initial value 3172.792290
iter 2 value 2475.132011
iter 3 value 2450.691580
iter 4 value 2348.672396
iter 5 value 2072.926917
iter 6 value 2069.099768
iter 7 value 2034.325634
iter 8 value 1946.134411
iter 9 value 1720.793772
iter 10 value 1720.093532
iter 11 value 1712.789885
iter 12 value 1677.110373
iter 13 value 1667.080039
iter 14 value 1650.603691
iter 15 value 1635.423301
iter 16 value 1631.724643
iter 17 value 1628.971658
iter 18 value 1614.071079
iter 19 value 1611.378907
iter 20 value 1607.847534
iter 21 value 1593.179264
iter 22 value 1583.142408
iter 23 value 1579.141794
iter 24 value 1573.994857
iter 25 value 1571.701179
iter 26 value 1569.079040
iter 27 value 1564.357863
iter 28 value 1562.096257
iter 29 value 1560.609604
iter 30 value 1559.560906
iter 31 value 1558.320240
iter 32 value 1555.631864
iter 33 value 1554.382785
iter 34 value 1552.003636
iter 35 value 1548.904749
iter 36 value 1546.827775
iter 37 value 1540.740013
iter 38 value 1538.168092
iter 39 value 1536.946348
iter 40 value 1534.421992
iter 41 value 1532.808748
iter 42 value 1531.409010
iter 43 value 1530.049491
iter 44 value 1529.224814
iter 45 value 1528.257411
iter 46 value 1526.622741
iter 47 value 1522.915467
iter 48 value 1518.591480
iter 49 value 1513.784433
iter 50 value 1505.703343
iter 51 value 1500.459703
iter 52 value 1498.275424
iter 53 value 1497.017497
iter 54 value 1495.620968
iter 55 value 1494.166366
iter 56 value 1492.864888
iter 57 value 1491.842191
iter 58 value 1491.432014
iter 59 value 1491.205563
iter 60 value 1491.101259
iter 61 value 1491.022806
iter 62 value 1490.921574
iter 63 value 1490.797303
iter 64 value 1490.635514
iter 65 value 1490.400966
iter 66 value 1489.989007
iter 67 value 1489.215964
iter 68 value 1487.903341
iter 69 value 1486.123533
iter 70 value 1484.146667
iter 71 value 1482.044221
iter 72 value 1479.800045
iter 73 value 1478.552980
iter 74 value 1477.279446
iter 75 value 1476.723263
iter 76 value 1475.807229
iter 77 value 1475.291486
iter 78 value 1474.921278
iter 79 value 1474.716610
iter 80 value 1474.686353
iter 81 value 1474.665050
iter 82 value 1474.645392
iter 83 value 1474.609638
iter 84 value 1474.529508
iter 85 value 1474.337063
iter 86 value 1474.325809
iter 87 value 1474.322444
iter 88 value 1474.318082
iter 89 value 1474.310959
iter 90 value 1474.309770
iter 91 value 1474.306478
iter 92 value 1474.293756
iter 93 value 1474.271078
iter 94 value 1474.266374
iter 95 value 1474.261768
iter 96 value 1474.241262
iter 97 value 1474.236788
iter 98 value 1474.230984
iter 99 value 1474.224987
iter 100 value 1474.220574
iter 101 value 1474.213670
iter 102 value 1474.212471
iter 103 value 1474.207815
iter 104 value 1474.201697
iter 105 value 1474.198747
iter 106 value 1474.191328
iter 107 value 1474.187450
iter 108 value 1474.186525
iter 109 value 1474.175060
iter 110 value 1474.172785
iter 111 value 1474.090963
iter 112 value 1474.022694
iter 113 value 1473.811828
iter 114 value 1473.053320
iter 115 value 1471.981946
iter 116 value 1471.169127
iter 117 value 1470.907424
iter 118 value 1470.879816
iter 119 value 1470.877246
iter 120 value 1470.873677
iter 121 value 1470.864929
iter 122 value 1470.842540
iter 123 value 1470.789715
iter 124 value 1470.681660
iter 125 value 1470.526202
iter 126 value 1470.409975
iter 127 value 1470.374547
iter 128 value 1470.370689
iter 129 value 1470.370256
iter 130 value 1470.369297
iter 131 value 1470.366877
iter 132 value 1470.360609
iter 133 value 1470.345147
iter 134 value 1470.309876
iter 135 value 1470.243884
iter 136 value 1470.161085
iter 137 value 1470.109814
iter 138 value 1470.098648
iter 139 value 1470.097653
iter 140 value 1470.097388
iter 141 value 1470.096628
iter 142 value 1470.094827
iter 143 value 1470.090071
iter 144 value 1470.078679
iter 145 value 1470.053778
iter 146 value 1470.012236
iter 147 value 1469.971074
iter 148 value 1469.953234
iter 149 value 1469.950281
iter 150 value 1469.950064
iter 151 value 1469.950010
iter 152 value 1469.949825
iter 153 value 1469.949406
iter 154 value 1469.948272
iter 155 value 1469.945507
iter 156 value 1469.939051
iter 157 value 1469.926714
iter 158 value 1469.910606
iter 159 value 1469.900245
iter 160 value 1469.897917
iter 161 value 1469.897754
iter 161 value 1469.897748
iter 161 value 1469.897748
final value 1469.897748
converged
Additional convergence test using scaled estimation. Parameters will be scaled by their current
estimates and additional iterations will be performed.
initial value 1469.897748
iter 2 value 1469.897273
iter 3 value 1469.896975
iter 4 value 1469.896321
iter 5 value 1469.896045
iter 6 value 1469.895983
iter 7 value 1469.895935
iter 8 value 1469.895869
iter 9 value 1469.895685
iter 10 value 1469.895538
iter 11 value 1469.895444
iter 12 value 1469.895303
iter 13 value 1469.895246
iter 14 value 1469.895159
iter 14 value 1469.895152
iter 14 value 1469.895142
final value 1469.895142
converged
Estimated parameters:
Estimate
asc_zupco 0.00000
asc_kombi 1.59143
asc_car_hh 0.12403
b_accessT_a -0.16475
b_waitingT_a -0.04260
b_accessT_b -0.18082
b_waitingT_b -0.07467
b_accessT_c -0.32334
b_waitingT_c -0.10382
b_available 0.00000
b_standing_a -1.65019
b_kadoma_a -2.15242
b_trailer_a -1.81785
b_standing_b -2.87457
b_kadoma_b -1.49531
b_trailer_b -1.94864
b_standing_c -3.72152
b_kadoma_c -2.25701
b_trailer_c -4.84660
b_ivt_a -0.02788
b_fare_a -0.03065
b_ivt_c -0.05188
b_fare_c -0.13069
b_ivt_b -0.06108
b_fare_b -1.15582
delta_a 0.00000
delta_b -2.92261
delta_c 0.20900
gamma_gender_a -3.33787
gamma_gender_b 0.05746
gamma_gender_c -2.41582
gamma_NoInc_a -1.07746
gamma_IncomeA_a -1.17902
gamma_IncomeB_a -0.23606
gamma_IncomeC_a 1.10726
gamma_IncomeD_a 1.40801
gamma_NoInc_b 0.97724
gamma_IncomeA_b 1.30420
gamma_IncomeB_b 0.43908
gamma_IncomeC_b -1.97067
gamma_IncomeD_b -0.74524
Computing covariance matrix using numerical methods (numDeriv).
0%....25%....50%....75%....100%
WARNING: Some eigenvalues of the Hessian are positive, indicating convergence to a saddle point!
Computing score matrix...
Summary of class allocation for LC model component :
Mean prob.
Class_1 0.3459
Class_2 0.1794
Class_3 0.4747
Calculating LL(0) for applicable models...
Calculating LL of each model component...
Warning message:
In sqrt(diag(robvarcov)) : NaNs produced
>
> # ################################################################# #
> #### MODEL OUTPUTS ####
> # ################################################################# #
>
> # ----------------------------------------------------------------- #
> #---- FORMATTED OUTPUT (TO SCREEN) ----
> # ----------------------------------------------------------------- #
>
> apollo_modelOutput(model)
Model run using Apollo for R, version 0.2.6 on Darwin by mapfuriramasimbatutsirai
www.ApolloChoiceModelling.com
Model name : COH 3 latent class
Model description : MNL with three latent classes
Model run at : 2021-12-16 11:19:06
Estimation method : bfgs
Model diagnosis : successful convergence
Number of individuals : 361
Number of rows in database : 2888
Number of modelled outcomes : 2888
Number of cores used : 2
Model without mixing
LL(start) : -3172.792
LL(0, whole model) : -3172.792
LL(C, whole model) : Not applicable
LL(final, whole model) : -1469.895
Rho-square (0) : 0.5367
Adj.Rho-square (0) : 0.5247
AIC : 3015.79
BIC : 3242.59
LL(0,Class_1) : -3172.792
LL(final,Class_1) : -2061.203
LL(0,Class_2) : -3172.792
LL(final,Class_2) : -25476.38
LL(0,Class_3) : -3172.792
LL(final,Class_3) : -2130.269
Estimated parameters : 38
Time taken (hh:mm:ss) : 00:01:52.91
pre-estimation : 00:00:7.04
estimation : 00:01:13.34
post-estimation : 00:00:32.52
Iterations : 180
Min abs eigenvalue of Hessian : 0
Unconstrained optimisation.
These outputs have had the scaling used in estimation applied to them.
Estimates:
Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0)
asc_zupco 0.00000 NA NA NA NA
asc_kombi 1.59143 0.113684 13.998768 0.106164 14.99027
asc_car_hh 0.12403 0.184386 0.672655 0.205754 0.60280
b_accessT_a -0.16475 0.015715 -10.483700 0.025146 -6.55178
b_waitingT_a -0.04260 0.015332 -2.778502 0.016463 -2.58764
b_accessT_b -0.18082 0.048725 -3.711096 0.052691 -3.43182
b_waitingT_b -0.07467 0.057913 -1.289262 0.055938 -1.33477
b_accessT_c -0.32334 0.028422 -11.376360 0.027751 -11.65140
b_waitingT_c -0.10382 0.024724 -4.199174 0.029369 -3.53514
b_available 0.00000 NA NA NA NA
b_standing_a -1.65019 0.232288 -7.104093 0.324661 -5.08282
b_kadoma_a -2.15242 0.174674 -12.322536 0.186423 -11.54593
b_trailer_a -1.81785 0.242577 -7.493917 0.430618 -4.22150
b_standing_b -2.87457 0.992779 -2.895480 1.044760 -2.75142
b_kadoma_b -1.49531 0.453991 -3.293690 0.395655 -3.77932
b_trailer_b -1.94864 0.576904 -3.377759 0.535161 -3.64123
b_standing_c -3.72152 0.434776 -8.559632 0.470552 -7.90885
b_kadoma_c -2.25701 0.249956 -9.029613 0.212694 -10.61151
b_trailer_c -4.84660 0.513237 -9.443198 0.693184 -6.99179
b_ivt_a -0.02788 0.004242 -6.572043 0.005962 -4.67672
b_fare_a -0.03065 0.003578 -8.564745 0.006364 -4.81573
b_ivt_c -0.05188 0.008808 -5.890603 0.013030 -3.98185
b_fare_c -0.13069 0.012536 -10.425065 0.019497 -6.70321
b_ivt_b -0.06108 0.021646 -2.821643 0.022931 -2.66357
b_fare_b -1.15582 2.898e+04 -3.988e-05 56.024482 -0.02063
delta_a 0.00000 NA NA NA NA
delta_b -2.92261 7861.510074 -3.7176e-04 0.923314 -3.16535
delta_c 0.20900 2317.051553 9.020e-05 1.579206 0.13234
gamma_gender_a -3.33787 1598.774002 -0.002088 3.032322 -1.10076
gamma_gender_b 0.05746 1598.773905 3.594e-05 2.995820 0.01918
gamma_gender_c -2.41582 1598.774060 -0.001511 2.994953 -0.80663
gamma_NoInc_a -1.07746 2317.051663 -4.6502e-04 1.444127 -0.74610
gamma_IncomeA_a -1.17902 2317.051652 -5.0885e-04 NaN NaN
gamma_IncomeB_a -0.23606 2317.051611 -1.0188e-04 2.630040 -0.08975
gamma_IncomeC_a 1.10726 2317.051588 4.7787e-04 NaN NaN
gamma_IncomeD_a 1.40801 2317.051702 6.0767e-04 1.563808 0.90037
gamma_NoInc_b 0.97724 4033.647102 2.4227e-04 2.591742 0.37706
gamma_IncomeA_b 1.30420 4033.647098 3.2333e-04 1.250284 1.04312
gamma_IncomeB_b 0.43908 4033.647071 1.0885e-04 1.438180 0.30530
gamma_IncomeC_b -1.97067 4033.647142 -4.8856e-04 1.934733 -1.01857
gamma_IncomeD_b -0.74524 4033.647206 -1.8476e-04 0.217316 -3.42931
Summary of class allocation for LC model component :
Mean prob.
Class_1 0.3459
Class_2 0.1794
Class_3 0.4747
>
> # ----------------------------------------------------------------- #
> #---- FORMATTED OUTPUT (TO FILE, using model name) ----
> # ----------------------------------------------------------------- #
>
> #apollo_saveOutput(model)
>
> # ################################################################# #
> ##### ADDITIONAL RESULTS ANALYSIS AND DIAGNOSTICS ####
> # ################################################################# #
>
> ### Print the outputs of additional diagnostics to file (comment out sink to file command below if not desired)
> ### Remember to run the line closing any open sinks at the end of this file
> sink(paste(model$apollo_control$modelName,"_additional_output.txt",sep=""),split=TRUE)
>
> # ################################################################# #
> ##### CLOSE FILE WRITING ####
> # ################################################################# #
>
> apollo_lrTest(model,"COH base_model")
The order of your two models will be reversed in the output as model 1 has better fit than model
2.
LL par
COH base_model -1714.79 9
COH 3 latent class -1469.90 38
Difference 244.89 29
Likelihood ratio test-value: 489.78
Degrees of freedom: 29
Likelihood ratio test p-value: 3.612e-85
> apollo_lrTest("COH heterogeneity income",model)
LL par
COH heterogeneity income -1619.9 13
COH 3 latent class -1469.9 38
Difference 150.0 25
Likelihood ratio test-value: 300
Degrees of freedom: 25
Likelihood ratio test p-value: 6.012e-49
>
> # switch off file writing if in use
>
> if(sink.number()>0) sink()
Thanks and regards
Tutsie.
-
stephanehess
- Site Admin
- Posts: 1354
- Joined: 24 Apr 2020, 16:29
Re: n sqrt(diag(varcov)) : NaNs produced
Hi
you're missing the normalisation. For each covariate, you need to fix the gamma to zero in one class (just as you did for the constants).
Stephane
you're missing the normalisation. For each covariate, you need to fix the gamma to zero in one class (just as you did for the constants).
Stephane
Re: n sqrt(diag(varcov)) : NaNs produced
Thanks for your response.
Having omitted the gamma_Incomes for class c which I suggest is equivalent to normalization as attached, I still get the same error:
(Warning message:
In sqrt(diag(robvarcov)) : NaNs produced
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(
asc_zupco = 0,
asc_kombi = 0,
asc_car_hh = 0,
b_accessT_a = 0,
b_waitingT_a = 0,
b_accessT_b = 0,
b_waitingT_b = 0,
b_accessT_c = 0,
b_waitingT_c = 0,
b_available = 0,
b_standing_a = 0,
b_kadoma_a = 0,
b_trailer_a = 0,
b_standing_b = 0,
b_kadoma_b = 0,
b_trailer_b = 0,
b_standing_c = 0,
b_kadoma_c = 0,
b_trailer_c = 0,
b_ivt_a = 0,
b_fare_a = 0,
b_ivt_c = 0,
b_fare_c = 0,
b_ivt_b = 0,
b_fare_b = 0,
delta_a = 0,
delta_b = 0,
delta_c = 0,
gamma_gender_a = 0,
gamma_gender_b = 0,
gamma_gender_c = 0,
gamma_NoInc_a = 0,
gamma_IncomeA_a = 0,
gamma_IncomeB_a = 0,
gamma_IncomeC_a = 0,
gamma_IncomeD_a = 0,
gamma_NoInc_b = 0,
gamma_IncomeA_b = 0,
gamma_IncomeB_b = 0,
gamma_IncomeC_b = 0,
gamma_IncomeD_b = 0
)
### 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("asc_zupco","b_available","delta_a","gamma_gender_c")
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
V=list()
gamma_Income_a = gamma_NoInc_a * (income == 0) + gamma_IncomeA_a * (income == 1) +
gamma_IncomeB_a * (income == 2) + gamma_IncomeC_a * (income == 3) +
gamma_IncomeD_a * (income == 4)
gamma_Income_b = gamma_NoInc_b* (income == 0) + gamma_IncomeA_b * (income == 1) +
gamma_IncomeB_b * (income == 2) + gamma_IncomeC_b * (income == 3) +
gamma_IncomeD_b * (income == 4)
# gamma_employment_a = gamma_none_a * (employment == 1) + gamma_student_a * (employment == 2) +
# gamma_informal_a * (employment == 3) + gamma_formal_a * (employment > 3)
#
# gamma_employment_b = gamma_none_b * (employment == 1) + gamma_student_b * (employment == 2) +
# gamma_informal_b * (employment == 3) + gamma_formal_b * (employment > 3)
V[["class_a"]] = delta_a + gamma_gender_a*gender + gamma_Income_a #+ gamma_employment_a
V[["class_b"]] = delta_b + gamma_gender_b*gender + gamma_Income_b #+ gamma_employment_b
V[["class_c"]] = delta_c + gamma_gender_c*gender
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Estimates:
Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0)
asc_zupco 0.00000 NA NA NA NA
asc_kombi 1.59202 0.113689 14.003330 0.106152 14.99759
asc_car_hh 0.12375 0.184336 0.671321 0.205537 0.60207
b_accessT_a -0.16460 0.015711 -10.477145 0.025112 -6.55474
b_waitingT_a -0.04260 0.015334 -2.778441 0.016469 -2.58692
b_accessT_b -0.18072 0.048709 -3.710238 0.052680 -3.43061
b_waitingT_b -0.07466 0.057907 -1.289397 0.055950 -1.33450
b_accessT_c -0.32337 0.028397 -11.387252 0.027666 -11.68815
b_waitingT_c -0.10384 0.024718 -4.200960 0.029379 -3.53456
b_available 0.00000 NA NA NA NA
b_standing_a -1.64886 0.232311 -7.097643 0.324525 -5.08084
b_kadoma_a -2.15284 0.174707 -12.322583 0.186473 -11.54509
b_trailer_a -1.81565 0.242548 -7.485736 0.430399 -4.21852
b_standing_b -2.87036 0.991430 -2.895174 1.042928 -2.75221
b_kadoma_b -1.49750 0.453919 -3.299048 0.395809 -3.78340
b_trailer_b -1.95145 0.576990 -3.382113 0.535235 -3.64596
b_standing_c -3.72230 0.434770 -8.561545 0.470973 -7.90343
b_kadoma_c -2.25594 0.249817 -9.030349 0.212471 -10.61764
b_trailer_c -4.84405 0.512398 -9.453685 0.690477 -7.01552
b_ivt_a -0.02782 0.004241 -6.560988 0.005957 -4.67087
b_fare_a -0.03064 0.003574 -8.573495 0.006347 -4.82819
b_ivt_c -0.05180 0.008776 -5.903130 0.012925 -4.00781
b_fare_c -0.13063 0.012506 -10.445831 0.019395 -6.73523
b_ivt_b -0.06110 0.021655 -2.821360 0.022950 -2.66217
b_fare_b -0.58987 7.411729 -0.079586 0.039019 -15.11758
delta_a 0.00000 NA NA NA NA
delta_b -2.17082 5283.284204 -4.1089e-04 3.787020 -0.57323
delta_c 0.53479 5658.355947 9.451e-05 1.723708 0.31026
gamma_gender_a 0.00000 NA NA NA NA
gamma_gender_b 3.40028 0.709555 4.792129 0.799623 4.25235
gamma_gender_c 0.92232 0.354884 2.598934 0.402167 2.29338
gamma_NoInc_a -0.75484 5658.355943 -1.3340e-04 3.630482 -0.20792
gamma_IncomeA_a -0.85541 5658.355935 -1.5118e-04 NaN NaN
gamma_IncomeB_a 0.08969 5658.356026 1.585e-05 2.401918 0.03734
gamma_IncomeC_a 1.43347 5658.355951 2.5334e-04 2.218313 0.64620
gamma_IncomeD_a 1.72311 5658.355957 3.0452e-04 NaN NaN
gamma_NoInc_b 0.54505 289.887799 0.001880 0.490636 1.11091
gamma_IncomeA_b 0.87672 289.887757 0.003024 0.508251 1.72497
gamma_IncomeB_b 0.01119 289.887372 3.862e-05 0.157916 0.07089
gamma_IncomeC_b -2.39898 289.888481 -0.008276 0.836249 -2.86874
gamma_IncomeD_b -1.20478 289.889829 -0.004156 1.193103 -1.00979
Summary of class allocation for LC model component :
Mean prob.
Class_1 0.3457
Class_2 0.1795
Class_3 0.4748
Thanks and regards,
Tutsie
Having omitted the gamma_Incomes for class c which I suggest is equivalent to normalization as attached, I still get the same error:
(Warning message:
In sqrt(diag(robvarcov)) : NaNs produced
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(
asc_zupco = 0,
asc_kombi = 0,
asc_car_hh = 0,
b_accessT_a = 0,
b_waitingT_a = 0,
b_accessT_b = 0,
b_waitingT_b = 0,
b_accessT_c = 0,
b_waitingT_c = 0,
b_available = 0,
b_standing_a = 0,
b_kadoma_a = 0,
b_trailer_a = 0,
b_standing_b = 0,
b_kadoma_b = 0,
b_trailer_b = 0,
b_standing_c = 0,
b_kadoma_c = 0,
b_trailer_c = 0,
b_ivt_a = 0,
b_fare_a = 0,
b_ivt_c = 0,
b_fare_c = 0,
b_ivt_b = 0,
b_fare_b = 0,
delta_a = 0,
delta_b = 0,
delta_c = 0,
gamma_gender_a = 0,
gamma_gender_b = 0,
gamma_gender_c = 0,
gamma_NoInc_a = 0,
gamma_IncomeA_a = 0,
gamma_IncomeB_a = 0,
gamma_IncomeC_a = 0,
gamma_IncomeD_a = 0,
gamma_NoInc_b = 0,
gamma_IncomeA_b = 0,
gamma_IncomeB_b = 0,
gamma_IncomeC_b = 0,
gamma_IncomeD_b = 0
)
### 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("asc_zupco","b_available","delta_a","gamma_gender_c")
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
V=list()
gamma_Income_a = gamma_NoInc_a * (income == 0) + gamma_IncomeA_a * (income == 1) +
gamma_IncomeB_a * (income == 2) + gamma_IncomeC_a * (income == 3) +
gamma_IncomeD_a * (income == 4)
gamma_Income_b = gamma_NoInc_b* (income == 0) + gamma_IncomeA_b * (income == 1) +
gamma_IncomeB_b * (income == 2) + gamma_IncomeC_b * (income == 3) +
gamma_IncomeD_b * (income == 4)
# gamma_employment_a = gamma_none_a * (employment == 1) + gamma_student_a * (employment == 2) +
# gamma_informal_a * (employment == 3) + gamma_formal_a * (employment > 3)
#
# gamma_employment_b = gamma_none_b * (employment == 1) + gamma_student_b * (employment == 2) +
# gamma_informal_b * (employment == 3) + gamma_formal_b * (employment > 3)
V[["class_a"]] = delta_a + gamma_gender_a*gender + gamma_Income_a #+ gamma_employment_a
V[["class_b"]] = delta_b + gamma_gender_b*gender + gamma_Income_b #+ gamma_employment_b
V[["class_c"]] = delta_c + gamma_gender_c*gender
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Estimates:
Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0)
asc_zupco 0.00000 NA NA NA NA
asc_kombi 1.59202 0.113689 14.003330 0.106152 14.99759
asc_car_hh 0.12375 0.184336 0.671321 0.205537 0.60207
b_accessT_a -0.16460 0.015711 -10.477145 0.025112 -6.55474
b_waitingT_a -0.04260 0.015334 -2.778441 0.016469 -2.58692
b_accessT_b -0.18072 0.048709 -3.710238 0.052680 -3.43061
b_waitingT_b -0.07466 0.057907 -1.289397 0.055950 -1.33450
b_accessT_c -0.32337 0.028397 -11.387252 0.027666 -11.68815
b_waitingT_c -0.10384 0.024718 -4.200960 0.029379 -3.53456
b_available 0.00000 NA NA NA NA
b_standing_a -1.64886 0.232311 -7.097643 0.324525 -5.08084
b_kadoma_a -2.15284 0.174707 -12.322583 0.186473 -11.54509
b_trailer_a -1.81565 0.242548 -7.485736 0.430399 -4.21852
b_standing_b -2.87036 0.991430 -2.895174 1.042928 -2.75221
b_kadoma_b -1.49750 0.453919 -3.299048 0.395809 -3.78340
b_trailer_b -1.95145 0.576990 -3.382113 0.535235 -3.64596
b_standing_c -3.72230 0.434770 -8.561545 0.470973 -7.90343
b_kadoma_c -2.25594 0.249817 -9.030349 0.212471 -10.61764
b_trailer_c -4.84405 0.512398 -9.453685 0.690477 -7.01552
b_ivt_a -0.02782 0.004241 -6.560988 0.005957 -4.67087
b_fare_a -0.03064 0.003574 -8.573495 0.006347 -4.82819
b_ivt_c -0.05180 0.008776 -5.903130 0.012925 -4.00781
b_fare_c -0.13063 0.012506 -10.445831 0.019395 -6.73523
b_ivt_b -0.06110 0.021655 -2.821360 0.022950 -2.66217
b_fare_b -0.58987 7.411729 -0.079586 0.039019 -15.11758
delta_a 0.00000 NA NA NA NA
delta_b -2.17082 5283.284204 -4.1089e-04 3.787020 -0.57323
delta_c 0.53479 5658.355947 9.451e-05 1.723708 0.31026
gamma_gender_a 0.00000 NA NA NA NA
gamma_gender_b 3.40028 0.709555 4.792129 0.799623 4.25235
gamma_gender_c 0.92232 0.354884 2.598934 0.402167 2.29338
gamma_NoInc_a -0.75484 5658.355943 -1.3340e-04 3.630482 -0.20792
gamma_IncomeA_a -0.85541 5658.355935 -1.5118e-04 NaN NaN
gamma_IncomeB_a 0.08969 5658.356026 1.585e-05 2.401918 0.03734
gamma_IncomeC_a 1.43347 5658.355951 2.5334e-04 2.218313 0.64620
gamma_IncomeD_a 1.72311 5658.355957 3.0452e-04 NaN NaN
gamma_NoInc_b 0.54505 289.887799 0.001880 0.490636 1.11091
gamma_IncomeA_b 0.87672 289.887757 0.003024 0.508251 1.72497
gamma_IncomeB_b 0.01119 289.887372 3.862e-05 0.157916 0.07089
gamma_IncomeC_b -2.39898 289.888481 -0.008276 0.836249 -2.86874
gamma_IncomeD_b -1.20478 289.889829 -0.004156 1.193103 -1.00979
Summary of class allocation for LC model component :
Mean prob.
Class_1 0.3457
Class_2 0.1795
Class_3 0.4748
Thanks and regards,
Tutsie
Re: n sqrt(diag(varcov)) : NaNs produced
Thank you Stephane for your response.
Having omitted gamma_incomes for class c, which I assume is equivalent to normalization, I still get the same error:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Computing covariance matrix using numerical methods (numDeriv).
0%....25%....50%....75%....100%
WARNING: Some eigenvalues of the Hessian are positive, indicating convergence to a saddle point!
Computing score matrix...
Summary of class allocation for LC model component :
Mean prob.
Class_1 0.3457
Class_2 0.1795
Class_3 0.4748
Calculating LL(0) for applicable models...
Calculating LL of each model component...
Warning message:
In sqrt(diag(robvarcov)) : NaNs produced
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(
asc_zupco = 0,
asc_kombi = 0,
asc_car_hh = 0,
b_accessT_a = 0,
b_waitingT_a = 0,
b_accessT_b = 0,
b_waitingT_b = 0,
b_accessT_c = 0,
b_waitingT_c = 0,
b_available = 0,
b_standing_a = 0,
b_kadoma_a = 0,
b_trailer_a = 0,
b_standing_b = 0,
b_kadoma_b = 0,
b_trailer_b = 0,
b_standing_c = 0,
b_kadoma_c = 0,
b_trailer_c = 0,
b_ivt_a = 0,
b_fare_a = 0,
b_ivt_c = 0,
b_fare_c = 0,
b_ivt_b = 0,
b_fare_b = 0,
delta_a = 0,
delta_b = 0,
delta_c = 0,
gamma_gender_a = 0,
gamma_gender_b = 0,
gamma_gender_c = 0,
gamma_NoInc_a = 0,
gamma_IncomeA_a = 0,
gamma_IncomeB_a = 0,
gamma_IncomeC_a = 0,
gamma_IncomeD_a = 0,
gamma_NoInc_b = 0,
gamma_IncomeA_b = 0,
gamma_IncomeB_b = 0,
gamma_IncomeC_b = 0,
gamma_IncomeD_b = 0
)
### 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("asc_zupco","b_available","delta_a","gamma_gender_c")
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
V=list()
gamma_Income_a = gamma_NoInc_a * (income == 0) + gamma_IncomeA_a * (income == 1) +
gamma_IncomeB_a * (income == 2) + gamma_IncomeC_a * (income == 3) +
gamma_IncomeD_a * (income == 4)
gamma_Income_b = gamma_NoInc_b* (income == 0) + gamma_IncomeA_b * (income == 1) +
gamma_IncomeB_b * (income == 2) + gamma_IncomeC_b * (income == 3) +
gamma_IncomeD_b * (income == 4)
# gamma_employment_a = gamma_none_a * (employment == 1) + gamma_student_a * (employment == 2) +
# gamma_informal_a * (employment == 3) + gamma_formal_a * (employment > 3)
#
# gamma_employment_b = gamma_none_b * (employment == 1) + gamma_student_b * (employment == 2) +
# gamma_informal_b * (employment == 3) + gamma_formal_b * (employment > 3)
V[["class_a"]] = delta_a + gamma_gender_a*gender + gamma_Income_a #+ gamma_employment_a
V[["class_b"]] = delta_b + gamma_gender_b*gender + gamma_Income_b #+ gamma_employment_b
V[["class_c"]] = delta_c + gamma_gender_c*gender
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Estimates:
Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0)
asc_zupco 0.00000 NA NA NA NA
asc_kombi 1.59202 0.113689 14.003330 0.106152 14.99759
asc_car_hh 0.12375 0.184336 0.671321 0.205537 0.60207
b_accessT_a -0.16460 0.015711 -10.477145 0.025112 -6.55474
b_waitingT_a -0.04260 0.015334 -2.778441 0.016469 -2.58692
b_accessT_b -0.18072 0.048709 -3.710238 0.052680 -3.43061
b_waitingT_b -0.07466 0.057907 -1.289397 0.055950 -1.33450
b_accessT_c -0.32337 0.028397 -11.387252 0.027666 -11.68815
b_waitingT_c -0.10384 0.024718 -4.200960 0.029379 -3.53456
b_available 0.00000 NA NA NA NA
b_standing_a -1.64886 0.232311 -7.097643 0.324525 -5.08084
b_kadoma_a -2.15284 0.174707 -12.322583 0.186473 -11.54509
b_trailer_a -1.81565 0.242548 -7.485736 0.430399 -4.21852
b_standing_b -2.87036 0.991430 -2.895174 1.042928 -2.75221
b_kadoma_b -1.49750 0.453919 -3.299048 0.395809 -3.78340
b_trailer_b -1.95145 0.576990 -3.382113 0.535235 -3.64596
b_standing_c -3.72230 0.434770 -8.561545 0.470973 -7.90343
b_kadoma_c -2.25594 0.249817 -9.030349 0.212471 -10.61764
b_trailer_c -4.84405 0.512398 -9.453685 0.690477 -7.01552
b_ivt_a -0.02782 0.004241 -6.560988 0.005957 -4.67087
b_fare_a -0.03064 0.003574 -8.573495 0.006347 -4.82819
b_ivt_c -0.05180 0.008776 -5.903130 0.012925 -4.00781
b_fare_c -0.13063 0.012506 -10.445831 0.019395 -6.73523
b_ivt_b -0.06110 0.021655 -2.821360 0.022950 -2.66217
b_fare_b -0.58987 7.411729 -0.079586 0.039019 -15.11758
delta_a 0.00000 NA NA NA NA
delta_b -2.17082 5283.284204 -4.1089e-04 3.787020 -0.57323
delta_c 0.53479 5658.355947 9.451e-05 1.723708 0.31026
gamma_gender_a 0.00000 NA NA NA NA
gamma_gender_b 3.40028 0.709555 4.792129 0.799623 4.25235
gamma_gender_c 0.92232 0.354884 2.598934 0.402167 2.29338
gamma_NoInc_a -0.75484 5658.355943 -1.3340e-04 3.630482 -0.20792
gamma_IncomeA_a -0.85541 5658.355935 -1.5118e-04 NaN NaN
gamma_IncomeB_a 0.08969 5658.356026 1.585e-05 2.401918 0.03734
gamma_IncomeC_a 1.43347 5658.355951 2.5334e-04 2.218313 0.64620
gamma_IncomeD_a 1.72311 5658.355957 3.0452e-04 NaN NaN
gamma_NoInc_b 0.54505 289.887799 0.001880 0.490636 1.11091
gamma_IncomeA_b 0.87672 289.887757 0.003024 0.508251 1.72497
gamma_IncomeB_b 0.01119 289.887372 3.862e-05 0.157916 0.07089
gamma_IncomeC_b -2.39898 289.888481 -0.008276 0.836249 -2.86874
gamma_IncomeD_b -1.20478 289.889829 -0.004156 1.193103 -1.00979
Summary of class allocation for LC model component :
Mean prob.
Class_1 0.3457
Class_2 0.1795
Class_3 0.4748
Kind regards
Tutsie
Having omitted gamma_incomes for class c, which I assume is equivalent to normalization, I still get the same error:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Computing covariance matrix using numerical methods (numDeriv).
0%....25%....50%....75%....100%
WARNING: Some eigenvalues of the Hessian are positive, indicating convergence to a saddle point!
Computing score matrix...
Summary of class allocation for LC model component :
Mean prob.
Class_1 0.3457
Class_2 0.1795
Class_3 0.4748
Calculating LL(0) for applicable models...
Calculating LL of each model component...
Warning message:
In sqrt(diag(robvarcov)) : NaNs produced
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(
asc_zupco = 0,
asc_kombi = 0,
asc_car_hh = 0,
b_accessT_a = 0,
b_waitingT_a = 0,
b_accessT_b = 0,
b_waitingT_b = 0,
b_accessT_c = 0,
b_waitingT_c = 0,
b_available = 0,
b_standing_a = 0,
b_kadoma_a = 0,
b_trailer_a = 0,
b_standing_b = 0,
b_kadoma_b = 0,
b_trailer_b = 0,
b_standing_c = 0,
b_kadoma_c = 0,
b_trailer_c = 0,
b_ivt_a = 0,
b_fare_a = 0,
b_ivt_c = 0,
b_fare_c = 0,
b_ivt_b = 0,
b_fare_b = 0,
delta_a = 0,
delta_b = 0,
delta_c = 0,
gamma_gender_a = 0,
gamma_gender_b = 0,
gamma_gender_c = 0,
gamma_NoInc_a = 0,
gamma_IncomeA_a = 0,
gamma_IncomeB_a = 0,
gamma_IncomeC_a = 0,
gamma_IncomeD_a = 0,
gamma_NoInc_b = 0,
gamma_IncomeA_b = 0,
gamma_IncomeB_b = 0,
gamma_IncomeC_b = 0,
gamma_IncomeD_b = 0
)
### 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("asc_zupco","b_available","delta_a","gamma_gender_c")
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
V=list()
gamma_Income_a = gamma_NoInc_a * (income == 0) + gamma_IncomeA_a * (income == 1) +
gamma_IncomeB_a * (income == 2) + gamma_IncomeC_a * (income == 3) +
gamma_IncomeD_a * (income == 4)
gamma_Income_b = gamma_NoInc_b* (income == 0) + gamma_IncomeA_b * (income == 1) +
gamma_IncomeB_b * (income == 2) + gamma_IncomeC_b * (income == 3) +
gamma_IncomeD_b * (income == 4)
# gamma_employment_a = gamma_none_a * (employment == 1) + gamma_student_a * (employment == 2) +
# gamma_informal_a * (employment == 3) + gamma_formal_a * (employment > 3)
#
# gamma_employment_b = gamma_none_b * (employment == 1) + gamma_student_b * (employment == 2) +
# gamma_informal_b * (employment == 3) + gamma_formal_b * (employment > 3)
V[["class_a"]] = delta_a + gamma_gender_a*gender + gamma_Income_a #+ gamma_employment_a
V[["class_b"]] = delta_b + gamma_gender_b*gender + gamma_Income_b #+ gamma_employment_b
V[["class_c"]] = delta_c + gamma_gender_c*gender
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Estimates:
Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0)
asc_zupco 0.00000 NA NA NA NA
asc_kombi 1.59202 0.113689 14.003330 0.106152 14.99759
asc_car_hh 0.12375 0.184336 0.671321 0.205537 0.60207
b_accessT_a -0.16460 0.015711 -10.477145 0.025112 -6.55474
b_waitingT_a -0.04260 0.015334 -2.778441 0.016469 -2.58692
b_accessT_b -0.18072 0.048709 -3.710238 0.052680 -3.43061
b_waitingT_b -0.07466 0.057907 -1.289397 0.055950 -1.33450
b_accessT_c -0.32337 0.028397 -11.387252 0.027666 -11.68815
b_waitingT_c -0.10384 0.024718 -4.200960 0.029379 -3.53456
b_available 0.00000 NA NA NA NA
b_standing_a -1.64886 0.232311 -7.097643 0.324525 -5.08084
b_kadoma_a -2.15284 0.174707 -12.322583 0.186473 -11.54509
b_trailer_a -1.81565 0.242548 -7.485736 0.430399 -4.21852
b_standing_b -2.87036 0.991430 -2.895174 1.042928 -2.75221
b_kadoma_b -1.49750 0.453919 -3.299048 0.395809 -3.78340
b_trailer_b -1.95145 0.576990 -3.382113 0.535235 -3.64596
b_standing_c -3.72230 0.434770 -8.561545 0.470973 -7.90343
b_kadoma_c -2.25594 0.249817 -9.030349 0.212471 -10.61764
b_trailer_c -4.84405 0.512398 -9.453685 0.690477 -7.01552
b_ivt_a -0.02782 0.004241 -6.560988 0.005957 -4.67087
b_fare_a -0.03064 0.003574 -8.573495 0.006347 -4.82819
b_ivt_c -0.05180 0.008776 -5.903130 0.012925 -4.00781
b_fare_c -0.13063 0.012506 -10.445831 0.019395 -6.73523
b_ivt_b -0.06110 0.021655 -2.821360 0.022950 -2.66217
b_fare_b -0.58987 7.411729 -0.079586 0.039019 -15.11758
delta_a 0.00000 NA NA NA NA
delta_b -2.17082 5283.284204 -4.1089e-04 3.787020 -0.57323
delta_c 0.53479 5658.355947 9.451e-05 1.723708 0.31026
gamma_gender_a 0.00000 NA NA NA NA
gamma_gender_b 3.40028 0.709555 4.792129 0.799623 4.25235
gamma_gender_c 0.92232 0.354884 2.598934 0.402167 2.29338
gamma_NoInc_a -0.75484 5658.355943 -1.3340e-04 3.630482 -0.20792
gamma_IncomeA_a -0.85541 5658.355935 -1.5118e-04 NaN NaN
gamma_IncomeB_a 0.08969 5658.356026 1.585e-05 2.401918 0.03734
gamma_IncomeC_a 1.43347 5658.355951 2.5334e-04 2.218313 0.64620
gamma_IncomeD_a 1.72311 5658.355957 3.0452e-04 NaN NaN
gamma_NoInc_b 0.54505 289.887799 0.001880 0.490636 1.11091
gamma_IncomeA_b 0.87672 289.887757 0.003024 0.508251 1.72497
gamma_IncomeB_b 0.01119 289.887372 3.862e-05 0.157916 0.07089
gamma_IncomeC_b -2.39898 289.888481 -0.008276 0.836249 -2.86874
gamma_IncomeD_b -1.20478 289.889829 -0.004156 1.193103 -1.00979
Summary of class allocation for LC model component :
Mean prob.
Class_1 0.3457
Class_2 0.1795
Class_3 0.4748
Kind regards
Tutsie
-
stephanehess
- Site Admin
- Posts: 1354
- Joined: 24 Apr 2020, 16:29
Re: n sqrt(diag(varcov)) : NaNs produced
You also need to use a base group for income. You cannot estimate a parameter for each category
-
janak12_jp
- Posts: 16
- Joined: 08 Sep 2021, 16:52
Re: n sqrt(diag(varcov)) : NaNs produced
Hi Prof. Stephane,
I am facing a similar issue with my study. I am estimating 2-class LC model. I have tried several specifications and also modified initial coefficients values based on MNL model.
The code is:
The results I am getting:
I am facing a similar issue with my study. I am estimating 2-class LC model. I have tried several specifications and also modified initial coefficients values based on MNL model.
The code is:
Code: Select all
## Clear memory
rm(list = ls())
## Load apollo library
library(apollo)
## Initialise code
apollo_initialise()
## Set core controls
apollo_control = list(
modelName = "LC with MMNL",
modelDescr = "LC with random coefficients", ## LVs to be included later
indivID = "ID",
nCores = 7,
outputDirectory = "output"
)
## Load data
database = read.csv("Analysis.csv", header = T)
## Define model parameters
## Vector of parameters to be estimated
apollo_beta = c(
asc_car = 0,
asc_pt = 0,
asc_ecar = 0,
asc_ebike = 0,
asc_escoot = 0,
asc_aebike = 0,
asc_aescoot = 0,
asc_awalk = 0,
car_ivtt_a_mu = 0, car_ivtt_b_mu = 0, car_ivtt_a_sigma = 0, car_ivtt_b_sigma = 0,
car_egt_a_mu = 0, car_egt_b_mu = 0, car_egt_a_sigma = 0, car_egt_b_sigma = 0,
car_tc_a = 0, car_tc_b = 0,
car_pc_a = 0, car_pc_b = 0,
pt_ivtt_a_mu = 0, pt_ivtt_b_mu = 0, pt_ivtt_a_sigma = 0, pt_ivtt_b_sigma = 0,
pt_act_a_mu = 0, pt_act_b_mu = 0, pt_act_a_sigma = 0, pt_act_b_sigma = 0,
pt_egt_a_mu = 0, pt_egt_b_mu = 0, pt_egt_a_sigma = 0, pt_egt_b_sigma = 0,
pt_wt_a_mu = 0, pt_wt_b_mu = 0, pt_wt_a_sigma = 0, pt_wt_b_sigma = 0,
pt_tc_a = 0, pt_tc_b = 0,
ecar_ivtt_a_mu = 0, ecar_ivtt_b_mu = 0, ecar_ivtt_a_sigma = 0, ecar_ivtt_b_sigma = 0,
ecar_act_a_mu = 0, ecar_act_b_mu = 0, ecar_act_a_sigma = 0, ecar_act_b_sigma = 0,
ecar_egt_a_mu = 0, ecar_egt_b_mu = 0, ecar_egt_a_sigma = 0, ecar_egt_b_sigma = 0,
ecar_tc_a = 0, ecar_tc_b = 0,
ecar_av_a = 0, ecar_av_b = 0,
ecar_wt_a_mu = 0, ecar_wt_b_mu = 0, ecar_wt_a_sigma = 0, ecar_wt_b_sigma = 0,
ebike_ivtt_a_mu = 0, ebike_ivtt_b_mu = 0, ebike_ivtt_a_sigma = 0, ebike_ivtt_b_sigma = 0,
ebike_act_a_mu = 0, ebike_act_b_mu = 0, ebike_act_a_sigma = 0, ebike_act_b_sigma = 0,
ebike_egt_a_mu = 0, ebike_egt_b_mu = 0, ebike_egt_a_sigma = 0, ebike_egt_b_sigma = 0,
ebike_tc_a = 0, ebike_tc_b = 0,
ebike_av_a = 0, ebike_av_b = 0,
ebike_wt_a_mu = 0, ebike_wt_b_mu = 0, ebike_wt_a_sigma = 0, ebike_wt_b_sigma = 0,
escoot_ivtt_a_mu = 0, escoot_ivtt_b_mu = 0, escoot_ivtt_a_sigma = 0, escoot_ivtt_b_sigma = 0,
escoot_act_a_mu = 0, escoot_act_b_mu = 0, escoot_act_a_sigma = 0, escoot_act_b_sigma = 0,
escoot_egt_a_mu = 0, escoot_egt_b_mu = 0, escoot_egt_a_sigma = 0, escoot_egt_b_sigma = 0,
escoot_tc_a = 0, escoot_tc_b = 0,
escoot_av_a = 0, escoot_av_b = 0,
escoot_wt_a_mu = 0, escoot_wt_b_mu = 0, escoot_wt_a_sigma = 0, escoot_wt_b_sigma = 0,
aebike_ivtt_a_mu = 0, aebike_ivtt_b_mu = 0, aebike_ivtt_a_sigma = 0, aebike_ivtt_b_sigma = 0,
aebike_wk_a_mu = 0, aebike_wk_b_mu = 0, aebike_wk_a_sigma = 0, aebike_wk_b_sigma = 0,
aebike_tc_a = 0, aebike_tc_b = 0,
aebike_av_a = 0, aebike_av_b = 0,
aebike_wt_a_mu = 0, aebike_wt_b_mu = 0, aebike_wt_a_sigma = 0, aebike_wt_b_sigma = 0,
aescoot_ivtt_a_mu = 0, aescoot_ivtt_b_mu = 0, aescoot_ivtt_a_sigma = 0, aescoot_ivtt_b_sigma = 0,
aescoot_wk_a_mu = 0, aescoot_wk_b_mu = 0, aescoot_wk_a_sigma = 0, aescoot_wk_b_sigma = 0,
aescoot_tc_a = 0, aescoot_tc_b = 0,
aescoot_av_a = 0, aescoot_av_b = 0,
aescoot_wt_a_mu = 0, aescoot_wt_b_mu = 0, aescoot_wt_a_sigma = 0, aescoot_wt_b_sigma = 0,
awalk_a_mu = 0, awalk_b_mu = 0, awalk_a_sigma = 0, awalk_b_sigma = 0,
delta_a = 0, delta_b = 0,
gamma_age1_a = 0, gamma_age1_b = 0, gamma_age2_a = 0, gamma_age2_b = 0, gamma_age3_a = 0, gamma_age3_b = 0,
gamma_female_a = 0, gamma_female_b = 0,
gamma_hhinc1_a = 0, gamma_hhinc1_b = 0, gamma_hhinc2_a = 0, gamma_hhinc2_b = 0, gamma_hhinc3_a = 0, gamma_hhinc3_b = 0,
gamma_ncar0_a = 0, gamma_ncar0_b = 0, gamma_ncar1_a = 0, gamma_ncar1_b = 0,gamma_ncar2_a = 0, gamma_ncar2_b = 0,
gamma_nbic0_a = 0, gamma_nbic0_b = 0, gamma_nbic1_a = 0, gamma_nbic1_b = 0, gamma_nbic2_a = 0, gamma_nbic2_b = 0
)
## Vector of fixed parameters
apollo_fixed = c("asc_car", "asc_awalk", "delta_b", "gamma_age1_b", "gamma_age2_b", "gamma_age3_b", "gamma_age3_a", "gamma_female_b",
"gamma_hhinc1_b", "gamma_hhinc2_b", "gamma_hhinc3_b", "gamma_hhinc3_a",
"gamma_ncar0_b", "gamma_ncar1_b", "gamma_ncar2_b", "gamma_ncar0_a",
"gamma_nbic0_b", "gamma_nbic1_b", "gamma_nbic2_b", "gamma_nbic0_a")
## Define random parameters
apollo_draws = list(
interDrawsType = "mlhs",
interNDraws = 500,
interUnifDraws = c(),
interNormDraws = c("draws_car_ivtt", "draws_car_egt", "draws_pt_ivtt", "draws_pt_act", "draws_pt_egt", "draws_pt_wt",
"draws_ecar_ivtt", "draws_ecar_act", "draws_ecar_egt", "draws_ecar_wt",
"draws_ebike_ivtt", "draws_ebike_act", "draws_ebike_egt", "draws_ebike_wt",
"draws_escoot_ivtt", "draws_escoot_act", "draws_escoot_egt", "draws_escoot_wt",
"draws_aebike_ivtt", "draws_aebike_wk", "draws_aebike_wt",
"draws_aescoot_ivtt", "draws_aescoot_wk", "draws_aescoot_wt",
"draws_awalk"),
intraDrawsType="mlhs",
intraNDraws=0,
intraUnifDraws=c(),
intraNormDraws=c()
)
apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()
randcoeff[["car_ivtt_a"]] = -exp(car_ivtt_a_mu + car_ivtt_a_sigma*draws_car_ivtt)
randcoeff[["car_ivtt_b"]] = -exp(car_ivtt_b_mu + car_ivtt_b_sigma*draws_car_ivtt)
randcoeff[["car_egt_a"]] = -exp(car_egt_a_mu + car_egt_a_sigma*draws_car_egt)
randcoeff[["car_egt_b"]] = -exp(car_egt_b_mu + car_egt_b_sigma*draws_car_egt)
randcoeff[["pt_ivtt_a"]] = -exp(pt_ivtt_a_mu + pt_ivtt_a_sigma*draws_pt_ivtt)
randcoeff[["pt_ivtt_b"]] = -exp(pt_ivtt_b_mu + pt_ivtt_b_sigma*draws_pt_ivtt)
randcoeff[["pt_act_a"]] = -exp(pt_act_a_mu + pt_act_a_sigma*draws_pt_act)
randcoeff[["pt_act_b"]] = -exp(pt_act_b_mu + pt_act_b_sigma*draws_pt_act)
randcoeff[["pt_egt_a"]] = -exp(pt_egt_a_mu + pt_egt_a_sigma*draws_pt_egt)
randcoeff[["pt_egt_b"]] = -exp(pt_egt_b_mu + pt_egt_b_sigma*draws_pt_egt)
randcoeff[["pt_wt_a"]] = -exp(pt_wt_a_mu + pt_wt_a_sigma*draws_pt_wt)
randcoeff[["pt_wt_b"]] = -exp(pt_wt_b_mu + pt_wt_b_sigma*draws_pt_wt)
randcoeff[["ecar_ivtt_a"]] = -exp(ecar_ivtt_a_mu + ecar_ivtt_a_sigma*draws_ecar_ivtt)
randcoeff[["ecar_ivtt_b"]] = -exp(ecar_ivtt_b_mu + ecar_ivtt_b_sigma*draws_ecar_ivtt)
randcoeff[["ecar_act_a"]] = -exp(ecar_act_a_mu + ecar_act_a_sigma*draws_ecar_act)
randcoeff[["ecar_act_b"]] = -exp(ecar_act_b_mu + ecar_act_b_sigma*draws_ecar_act)
randcoeff[["ecar_egt_a"]] = -exp(ecar_egt_a_mu + ecar_egt_a_sigma*draws_ecar_egt)
randcoeff[["ecar_egt_b"]] = -exp(ecar_egt_b_mu + ecar_egt_b_sigma*draws_ecar_egt)
randcoeff[["ecar_wt_a"]] = -exp(ecar_wt_a_mu + ecar_wt_a_sigma*draws_ecar_wt)
randcoeff[["ecar_wt_b"]] = -exp(ecar_wt_b_mu + ecar_wt_b_sigma*draws_ecar_wt)
randcoeff[["ebike_ivtt_a"]] = -exp(ebike_ivtt_a_mu + ebike_ivtt_a_sigma*draws_ebike_ivtt)
randcoeff[["ebike_ivtt_b"]] = -exp(ebike_ivtt_b_mu + ebike_ivtt_b_sigma*draws_ebike_ivtt)
randcoeff[["ebike_act_a"]] = -exp(ebike_act_a_mu + ebike_act_a_sigma*draws_ebike_act)
randcoeff[["ebike_act_b"]] = -exp(ebike_act_b_mu + ebike_act_b_sigma*draws_ebike_act)
randcoeff[["ebike_egt_a"]] = -exp(ebike_egt_a_mu + ebike_egt_a_sigma*draws_ebike_egt)
randcoeff[["ebike_egt_b"]] = -exp(ebike_egt_b_mu + ebike_egt_b_sigma*draws_ebike_egt)
randcoeff[["ebike_wt_a"]] = -exp(ebike_wt_a_mu + ebike_wt_a_sigma*draws_ebike_wt)
randcoeff[["ebike_wt_b"]] = -exp(ebike_wt_b_mu + ebike_wt_b_sigma*draws_ebike_wt)
randcoeff[["escoot_ivtt_a"]] = -exp(escoot_ivtt_a_mu + escoot_ivtt_a_sigma*draws_escoot_ivtt)
randcoeff[["escoot_ivtt_b"]] = -exp(escoot_ivtt_b_mu + escoot_ivtt_b_sigma*draws_escoot_ivtt)
randcoeff[["escoot_act_a"]] = -exp(escoot_act_a_mu + escoot_act_a_sigma*draws_escoot_act)
randcoeff[["escoot_act_b"]] = -exp(escoot_act_b_mu + escoot_act_b_sigma*draws_escoot_act)
randcoeff[["escoot_egt_a"]] = -exp(escoot_egt_a_mu + escoot_egt_a_sigma*draws_escoot_egt)
randcoeff[["escoot_egt_b"]] = -exp(escoot_egt_b_mu + escoot_egt_b_sigma*draws_escoot_egt)
randcoeff[["escoot_wt_a"]] = -exp(escoot_wt_a_mu + escoot_wt_a_sigma*draws_escoot_wt)
randcoeff[["escoot_wt_b"]] = -exp(escoot_wt_b_mu + escoot_wt_b_sigma*draws_escoot_wt)
randcoeff[["aebike_ivtt_a"]] = -exp(aebike_ivtt_a_mu + aebike_ivtt_a_sigma*draws_aebike_ivtt)
randcoeff[["aebike_ivtt_b"]] = -exp(aebike_ivtt_b_mu + aebike_ivtt_b_sigma*draws_aebike_ivtt)
randcoeff[["aebike_wk_a"]] = -exp(aebike_wk_a_mu + aebike_wk_a_sigma*draws_aebike_wk)
randcoeff[["aebike_wk_b"]] = -exp(aebike_wk_b_mu + aebike_wk_b_sigma*draws_aebike_wk)
randcoeff[["aebike_wt_a"]] = -exp(aebike_wt_a_mu + aebike_wt_a_sigma*draws_aebike_wt)
randcoeff[["aebike_wt_b"]] = -exp(aebike_wt_b_mu + aebike_wt_b_sigma*draws_aebike_wt)
randcoeff[["aescoot_ivtt_a"]] = -exp(aescoot_ivtt_a_mu + aescoot_ivtt_a_sigma*draws_aescoot_ivtt)
randcoeff[["aescoot_ivtt_b"]] = -exp(aescoot_ivtt_b_mu + aescoot_ivtt_b_sigma*draws_aescoot_ivtt)
randcoeff[["aescoot_wk_a"]] = -exp(aescoot_wk_a_mu + aescoot_wk_a_sigma*draws_aescoot_wk)
randcoeff[["aescoot_wk_b"]] = -exp(aescoot_wk_b_mu + aescoot_wk_b_sigma*draws_aescoot_wk)
randcoeff[["aescoot_wt_a"]] = -exp(aescoot_wt_a_mu + aescoot_wt_a_sigma*draws_aescoot_wt)
randcoeff[["aescoot_wt_b"]] = -exp(aescoot_wt_b_mu + aescoot_wt_b_sigma*draws_aescoot_wt)
randcoeff[["awalk_a"]] = -exp(awalk_a_mu + awalk_a_sigma*draws_awalk)
randcoeff[["awalk_b"]] = -exp(awalk_b_mu + awalk_b_sigma*draws_awalk)
return(randcoeff)
}
## Define latent class components
apollo_lcPars = function(apollo_beta, apollo_inputs){
lcpars = list()
lcpars[["b_car_ivtt"]] = list(car_ivtt_a, car_ivtt_b)
lcpars[["b_car_egt"]] = list(car_egt_a, car_egt_b)
lcpars[["b_car_tc"]] = list(car_tc_a, car_tc_b)
lcpars[["b_car_pc"]] = list(car_pc_a, car_pc_b)
lcpars[["b_pt_ivtt"]] = list(pt_ivtt_a, pt_ivtt_b)
lcpars[["b_pt_act"]] = list(pt_act_a, pt_act_b)
lcpars[["b_pt_egt"]] = list(pt_egt_a, pt_egt_b)
lcpars[["b_pt_wt"]] = list(pt_wt_a, pt_wt_b)
lcpars[["b_pt_tc"]] = list(pt_tc_a, pt_tc_b)
lcpars[["b_ecar_ivtt"]] = list(ecar_ivtt_a, ecar_ivtt_b)
lcpars[["b_ecar_act"]] = list(ecar_act_a, ecar_act_b)
lcpars[["b_ecar_egt"]] = list(ecar_egt_a, ecar_egt_b)
lcpars[["b_ecar_tc"]] = list(ecar_tc_a, ecar_tc_b)
lcpars[["b_ecar_av"]] = list(ecar_av_a, ecar_av_b)
lcpars[["b_ecar_wt"]] = list(ecar_wt_a, ecar_wt_b)
lcpars[["b_ebike_ivtt"]] = list(ebike_ivtt_a, ebike_ivtt_b)
lcpars[["b_ebike_act"]] = list(ebike_act_a, ebike_act_b)
lcpars[["b_ebike_egt"]] = list(ebike_egt_a, ebike_egt_b)
lcpars[["b_ebike_tc"]] = list(ebike_tc_a, ebike_tc_b)
lcpars[["b_ebike_av"]] = list(ebike_av_a, ebike_av_b)
lcpars[["b_ebike_wt"]] = list(ebike_wt_a, ebike_wt_b)
lcpars[["b_escoot_ivtt"]] = list(escoot_ivtt_a, escoot_ivtt_b)
lcpars[["b_escoot_act"]] = list(escoot_act_a, escoot_act_b)
lcpars[["b_escoot_egt"]] = list(escoot_egt_a, escoot_egt_b)
lcpars[["b_escoot_tc"]] = list(escoot_tc_a, escoot_tc_b)
lcpars[["b_escoot_av"]] = list(escoot_av_a, escoot_av_b)
lcpars[["b_escoot_wt"]] = list(escoot_wt_a, escoot_wt_b)
lcpars[["b_aebike_ivtt"]] = list(aebike_ivtt_a, aebike_ivtt_b)
lcpars[["b_aebike_wk"]] = list(aebike_wk_a, aebike_wk_b)
lcpars[["b_aebike_tc"]] = list(aebike_tc_a, aebike_tc_b)
lcpars[["b_aebike_av"]] = list(aebike_av_a, aebike_av_b)
lcpars[["b_aebike_wt"]] = list(aebike_wt_a, aebike_wt_b)
lcpars[["b_aescoot_ivtt"]] = list(aescoot_ivtt_a, aescoot_ivtt_b)
lcpars[["b_aescoot_wk"]] = list(aescoot_wk_a, aescoot_wk_b)
lcpars[["b_aescoot_tc"]] = list(aescoot_tc_a, aescoot_tc_b)
lcpars[["b_aescoot_av"]] = list(aescoot_av_a, aescoot_av_b)
lcpars[["b_aescoot_wt"]] = list(aescoot_wt_a, aescoot_wt_b)
lcpars[["b_awalk"]] = list(awalk_a, awalk_b)
## Utility for latent class segmentation
V = list()
V[["class_a"]] = delta_a + gamma_age1_a*(age==1) + gamma_age2_a*(age==3) + gamma_age3_a*(age==5) + gamma_female_a*female +
gamma_hhinc1_a*(hhinc==1) + gamma_hhinc2_a*(hhinc==3) + gamma_hhinc3_a*(hhinc==5) +
gamma_ncar0_a*(ncar==0) + gamma_ncar1_a*(ncar==1) + gamma_ncar2_a*(ncar==2) +
gamma_nbic0_a*(nbic==0) + gamma_nbic1_a*(nbic==1) + gamma_nbic2_a*(nbic==2)
V[["class_b"]] = delta_b + gamma_age1_b*(age==1) + gamma_age2_b*(age==3) + gamma_age3_b*(age==5) + gamma_female_b*female +
gamma_hhinc1_b*(hhinc==1) + gamma_hhinc2_b*(hhinc==3) + gamma_hhinc3_b*(hhinc==5) +
gamma_ncar0_b*(ncar==0) + gamma_ncar1_b*(ncar==1) + gamma_ncar2_b*(ncar==2) +
gamma_nbic0_b*(nbic==0) + gamma_nbic1_b*(nbic==1) + gamma_nbic2_b*(nbic==2)
classAlloc_settings = list(
classes = c(class_a = 1, class_b = 2),
utilities = V
)
lcpars[["pi_values"]] = apollo_classAlloc(classAlloc_settings)
return(lcpars)
}
## Group and Validate inputs
apollo_inputs = apollo_validateInputs()
## Define model and likelihood function
apollo_probabilities = function(apollo_beta, apollo_inputs, functionality = "estimate"){
## 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()
#Define settings for MNL model component that are generic across classes
mnl_settings = list(
alternatives = c(car=1, pt=2, ecar=3, ebike=4, escoot=5, aebike=6, aescoot=7, awalk=8),
avail = list(car=av_car, pt=av_pt, ecar=av_ecar, ebike=av_ebike, escoot=av_escoot, aebike=av_aebike, aescoot=av_aescoot, awalk=av_awalk),
choiceVar = choice
)
## Loop over classes
for (s in 1:2){
## Compute class-specific utilities in choice sub-model
V = list()
V[["car"]] = asc_car + b_car_ivtt[[s]]*car_ivtt + b_car_egt[[s]]*car_egt + b_car_tc[[s]]*car_tc + b_car_pc[[s]]*car_pc
V[["pt"]] = asc_pt + b_pt_ivtt[[s]]*pt_ivtt + b_pt_act[[s]]*pt_act + b_pt_egt[[s]]*pt_egt + b_pt_wt[[s]]*pt_wt + b_pt_tc[[s]]*pt_tc
V[["ecar"]] = asc_ecar + b_ecar_ivtt[[s]]*ecar_ivtt + b_ecar_act[[s]]*ecar_act + b_ecar_egt[[s]]*ecar_egt + b_ecar_wt[[s]]*ecar_wt + b_ecar_tc[[s]]*ecar_tc + b_ecar_av[[s]]*ecar_av
V[["ebike"]] = asc_ebike + b_ebike_ivtt[[s]]*ebike_ivtt + b_ebike_act[[s]]*ebike_act + b_ebike_egt[[s]]*ebike_egt + b_ebike_wt[[s]]*ebike_wt + b_ebike_tc[[s]]*ebike_tc + b_ebike_av[[s]]*ebike_av
V[["escoot"]] = asc_escoot + b_escoot_ivtt[[s]]*escoot_ivtt + b_escoot_act[[s]]*escoot_act + b_escoot_egt[[s]]*escoot_egt + b_escoot_wt[[s]]*escoot_wt + b_escoot_tc[[s]]*escoot_tc + b_escoot_av[[s]]*escoot_av
V[["aebike"]] = asc_aebike + b_aebike_ivtt[[s]]*aebike_ivtt + b_aebike_wk[[s]]*aebike_wk + b_aebike_wt[[s]]*aebike_wt + b_aebike_tc[[s]]*aebike_tc + b_aebike_av[[s]]*aebike_av
V[["aescoot"]] = asc_aescoot + b_aescoot_ivtt[[s]]*aescoot_ivtt + b_aescoot_wk[[s]]*aescoot_wk + b_aescoot_wt[[s]]*aescoot_wt + b_aescoot_tc[[s]]*aescoot_tc + b_aescoot_av[[s]]*aescoot_av
V[["awalk"]] = asc_awalk + b_awalk[[s]]*awalk
mnl_settings$utilities = V
mnl_settings$componentName = paste0("class_", s)
## Compute within-class choice probabilities using MNL
P[[paste0("class_",s)]] = apollo_mnl(mnl_settings, functionality)
## Product across observations for same ID
P[[paste0("class_",s)]] = apollo_panelProd(P[[paste0("class_",s)]], apollo_inputs, functionality)
## Average across inter-individual draws within class
P[[paste0("class_",s)]] = apollo_avgInterDraws(P[[paste0("class_",s)]], apollo_inputs, functionality)
}
## Latent class model probabilities
lc_settings = list(inClassProb = P, classProb = pi_values)
P[["model"]] = apollo_lc(lc_settings, apollo_inputs, functionality)
## Prepare and return output of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
## Model Estimation
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
## Model Output
apollo_modelOutput(model)
Code: Select all
WARNING: Some eigenvalues of the Hessian are positive, indicating convergence to a saddle point!
Warning message:
In sqrt(diag(varcov)) : NaNs produced
> apollo_modelOutput(model)
Model run by janak using Apollo 0.2.9 on R 4.3.1 for Windows.
www.ApolloChoiceModelling.com
Model name : LC with MMNL
Model description : LC with random coefficients
Model run at : 2024-10-15 20:27:19.327923
Estimation method : bfgs
Model diagnosis : successful convergence
Optimisation diagnosis : Saddle point found
hessian properties : Some eigenvalues are positive and others negative
maximum eigenvalue : 554.338693
Number of individuals : 725
Number of rows in database : 7092
Number of modelled outcomes : 7092
Number of cores used : 7
Number of inter-individual draws : 500 (mlhs)
LL(start) : -27285.15
LL (whole model) at equal shares, LL(0) : -9474.02
LL (whole model) at observed shares, LL(C) : -8023.05
LL(final, whole model) : -5701.56
Rho-squared vs equal shares : 0.3982
Adj.Rho-squared vs equal shares : 0.3832
Rho-squared vs observed shares : 0.2894
Adj.Rho-squared vs observed shares : 0.2734
AIC : 11687.13
BIC : 12662.2
LL(0,class_1) : -9474.02
LL(final,class_1) : -8382.27
LL(0,class_2) : -9474.02
LL(final,class_2) : -6115.98
Estimated parameters : 142
Time taken (hh:mm:ss) : 18:11:49.09
pre-estimation : 01:12:23.3
estimation : 01:54:26.3
initial estimation : 01:25:43.75
estimation after rescaling : 00:28:42.55
post-estimation : 15:04:59.49
Iterations : 65
initial estimation : 51
estimation after rescaling : 14
Unconstrained optimisation.
Estimates:
Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0)
asc_car 0.000000 NA NA NA NA
asc_pt -0.559552 0.388153 -1.441575 3.810979 -0.146826
asc_ecar 0.270679 0.641344 0.422050 1.174931 0.230379
asc_ebike 0.215309 0.812967 0.264843 3.281352 0.065616
asc_escoot 0.311938 1.016481 0.306880 2.135522 0.146071
asc_aebike -0.134839 0.302570 -0.445644 4.918214 -0.027416
asc_aescoot -0.321782 NaN NaN 5.176305 -0.062164
asc_awalk 0.000000 NA NA NA NA
car_ivtt_a_mu -1.123919 NaN NaN 2.706907 -0.415204
car_ivtt_b_mu -1.722631 0.147342 -11.691413 1.045485 -1.647686
car_ivtt_a_sigma -0.736085 0.022982 -32.028065 0.872161 -0.843979
car_ivtt_b_sigma 0.051593 0.103619 0.497911 0.972213 0.053068
car_egt_a_mu -1.495515 0.082778 -18.066631 1.566346 -0.954779
car_egt_b_mu -1.773623 0.092748 -19.123119 1.507998 -1.176144
car_egt_a_sigma 0.478775 NaN NaN 1.773834 0.269910
car_egt_b_sigma -0.101863 NaN NaN 2.108992 -0.048299
car_tc_a 0.355311 NaN NaN 9.263341 0.038357
car_tc_b -0.130168 0.229442 -0.567324 2.133997 -0.060997
car_pc_a -0.172466 0.035610 -4.843192 0.117707 -1.465218
car_pc_b -0.616497 0.024281 -25.390140 0.144708 -4.260288
pt_ivtt_a_mu -1.189720 0.095936 -12.401127 1.116666 -1.065422
pt_ivtt_b_mu -1.505940 0.069511 -21.664871 0.383726 -3.924517
pt_ivtt_a_sigma -0.675797 0.075420 -8.960429 0.780684 -0.865647
pt_ivtt_b_sigma -0.381424 0.020275 -18.812100 0.484188 -0.787759
pt_act_a_mu -2.710823 0.238394 -11.371193 0.304314 -8.907987
pt_act_b_mu -2.021724 0.167124 -12.097172 0.667533 -3.028649
pt_act_a_sigma -0.024981 0.119285 -0.209420 3.792279 -0.006587
pt_act_b_sigma 0.044606 NaN NaN 0.490557 0.090930
pt_egt_a_mu -1.926797 0.172970 -11.139492 0.401997 -4.793064
pt_egt_b_mu -1.655872 0.112105 -14.770770 0.790353 -2.095104
pt_egt_a_sigma -0.048865 0.030145 -1.621029 1.204980 -0.040553
pt_egt_b_sigma 0.060291 NaN NaN 0.967590 0.062310
pt_wt_a_mu -1.999762 0.205843 -9.714993 0.748093 -2.673144
pt_wt_b_mu -1.425550 0.104489 -13.643052 0.286580 -4.974349
pt_wt_a_sigma -0.381220 0.249642 -1.527067 0.585991 -0.650557
pt_wt_b_sigma 0.277644 0.114509 2.424634 1.164051 0.238515
pt_tc_a -0.582416 0.354442 -1.643191 1.544732 -0.377034
pt_tc_b 0.372969 0.181841 2.051078 0.947707 0.393549
ecar_ivtt_a_mu -0.938800 0.136152 -6.895211 1.817712 -0.516473
ecar_ivtt_b_mu -1.108471 0.124437 -8.907912 0.425446 -2.605433
ecar_ivtt_a_sigma 0.939290 0.210402 4.464263 0.622768 1.508249
ecar_ivtt_b_sigma 0.575412 NaN NaN 0.655018 0.878468
ecar_act_a_mu -1.632256 0.206298 -7.912121 1.460961 -1.117249
ecar_act_b_mu -1.556143 0.159552 -9.753224 0.327606 -4.750038
ecar_act_a_sigma 0.163980 NaN NaN 1.911415 0.085790
ecar_act_b_sigma 0.351191 0.193136 1.818358 0.805891 0.435780
ecar_egt_a_mu -0.858893 NaN NaN 3.112324 -0.275965
ecar_egt_b_mu -1.223059 0.049197 -24.860652 1.222405 -1.000535
ecar_egt_a_sigma -0.745832 0.136988 -5.444495 0.540268 -1.380484
ecar_egt_b_sigma 0.540193 NaN NaN 1.574492 0.343090
ecar_tc_a 0.128729 0.139243 0.924494 0.424148 0.303501
ecar_tc_b -0.247580 0.059332 -4.172775 0.364838 -0.678603
ecar_av_a -0.016048 0.008448 -1.899567 0.045810 -0.350318
ecar_av_b 0.009235 0.004203 2.197062 0.007999 1.154476
ecar_wt_a_mu -1.398104 0.334042 -4.185420 0.756747 -1.847519
ecar_wt_b_mu -1.987426 0.236219 -8.413493 0.465673 -4.267854
ecar_wt_a_sigma -0.184632 0.071240 -2.591680 2.591299 -0.071251
ecar_wt_b_sigma -0.545338 0.279162 -1.953482 0.466665 -1.168585
ebike_ivtt_a_mu -0.006671 NaN NaN 8.071735 -8.2647e-04
ebike_ivtt_b_mu -1.336940 0.162497 -8.227451 0.320645 -4.169531
ebike_ivtt_a_sigma -1.050405 NaN NaN 7.795341 -0.134748
ebike_ivtt_b_sigma -0.623008 0.242092 -2.573441 0.651251 -0.956634
ebike_act_a_mu -0.774518 NaN NaN 5.601839 -0.138261
ebike_act_b_mu -1.607767 0.157900 -10.182154 0.430816 -3.731912
ebike_act_a_sigma -0.999065 NaN NaN 4.383897 -0.227894
ebike_act_b_sigma -0.322832 0.300733 -1.073485 0.503951 -0.640603
ebike_egt_a_mu -1.424208 0.175766 -8.102854 2.654876 -0.536450
ebike_egt_b_mu -1.652481 0.165904 -9.960442 0.205883 -8.026319
ebike_egt_a_sigma -0.345930 NaN NaN 2.603798 -0.132856
ebike_egt_b_sigma 0.091961 0.294860 0.311882 2.198462 0.041830
ebike_tc_a 0.236569 0.171782 1.377144 2.859456 0.082732
ebike_tc_b -1.023686 0.160869 -6.363470 0.398480 -2.568980
ebike_av_a -0.009305 0.010822 -0.859765 0.018488 -0.503278
ebike_av_b -0.001317 0.007464 -0.176449 0.022998 -0.057268
ebike_wt_a_mu -0.767967 0.230025 -3.338627 2.321242 -0.330843
ebike_wt_b_mu -0.662219 0.178435 -3.711268 0.383704 -1.725859
ebike_wt_a_sigma -0.010490 0.255247 -0.041096 1.617437 -0.006485
ebike_wt_b_sigma 0.040923 NaN NaN 0.317877 0.128738
escoot_ivtt_a_mu -0.984630 0.264314 -3.725230 2.513267 -0.391773
escoot_ivtt_b_mu -1.856843 0.135605 -13.693041 0.862219 -2.153564
escoot_ivtt_a_sigma 0.275894 0.088059 3.133055 2.192581 0.125831
escoot_ivtt_b_sigma 0.448833 NaN NaN 3.208176 0.139903
escoot_act_a_mu -0.974576 0.182151 -5.350364 1.426286 -0.683296
escoot_act_b_mu -1.272526 0.154815 -8.219650 0.595760 -2.135973
escoot_act_a_sigma 0.321581 0.097467 3.299391 0.773771 0.415603
escoot_act_b_sigma 0.206972 0.200273 1.033447 2.231081 0.092768
escoot_egt_a_mu -0.346319 0.282530 -1.225777 3.865031 -0.089603
escoot_egt_b_mu -0.819755 0.093904 -8.729710 0.173727 -4.718632
escoot_egt_a_sigma 0.621143 0.257302 2.414061 0.428462 1.449706
escoot_egt_b_sigma -0.079481 NaN NaN 0.590328 -0.134639
escoot_tc_a -0.194991 NaN NaN 4.124016 -0.047282
escoot_tc_b 0.253450 0.114518 2.213184 0.487002 0.520430
escoot_av_a -0.007056 NaN NaN 0.234843 -0.030046
escoot_av_b -0.038220 0.009954 -3.839748 0.045362 -0.842543
escoot_wt_a_mu -0.394351 0.292128 -1.349927 1.094547 -0.360287
escoot_wt_b_mu -0.937537 0.275577 -3.402084 0.364649 -2.571065
escoot_wt_a_sigma 0.127213 0.440982 0.288476 3.981660 0.031950
escoot_wt_b_sigma 0.086773 NaN NaN 2.419186 0.035868
aebike_ivtt_a_mu -0.305626 NaN NaN 17.532355 -0.017432
aebike_ivtt_b_mu -0.958205 0.081869 -11.704163 0.106357 -9.009312
aebike_ivtt_a_sigma 0.239730 NaN NaN 13.210627 0.018147
aebike_ivtt_b_sigma 0.032570 0.138689 0.234841 0.303705 0.107242
aebike_wk_a_mu -1.547367 NaN NaN 21.443091 -0.072162
aebike_wk_b_mu -1.455169 0.089948 -16.177904 0.119440 -12.183233
aebike_wk_a_sigma 0.183629 NaN NaN 35.425768 0.005183
aebike_wk_b_sigma 0.292682 0.156128 1.874628 0.316252 0.925471
aebike_tc_a -0.091276 1.346395 -0.067793 30.841062 -0.002960
aebike_tc_b -0.633337 0.238901 -2.651044 0.563968 -1.123000
aebike_av_a -0.143330 NaN NaN 1.531566 -0.093584
aebike_av_b 0.019365 0.003804 5.090502 0.023522 0.823263
aebike_wt_a_mu -0.466448 0.193854 -2.406185 0.536315 -0.869726
aebike_wt_b_mu -0.344546 0.047472 -7.257899 0.365876 -0.941704
aebike_wt_a_sigma 0.163503 NaN NaN 9.247212 0.017681
aebike_wt_b_sigma -0.188076 NaN NaN 0.987465 -0.190464
aescoot_ivtt_a_mu 0.384381 NaN NaN 7.677544 0.050066
aescoot_ivtt_b_mu -0.501620 NaN NaN 0.800177 -0.626887
aescoot_ivtt_a_sigma 0.061542 0.102429 0.600826 0.663548 0.092747
aescoot_ivtt_b_sigma 0.362582 0.081331 4.458126 0.632110 0.573607
aescoot_wk_a_mu -0.535602 NaN NaN 19.128726 -0.028000
aescoot_wk_b_mu -1.375013 NaN NaN 1.222746 -1.124529
aescoot_wk_a_sigma -0.041288 NaN NaN 40.829683 -0.001011
aescoot_wk_b_sigma 0.628484 NaN NaN 0.900583 0.697863
aescoot_tc_a -0.054222 NaN NaN 65.698325 -8.2532e-04
aescoot_tc_b -0.149601 0.161133 -0.928434 0.422307 -0.354248
aescoot_av_a -0.033398 NaN NaN 0.689947 -0.048406
aescoot_av_b 0.028127 0.003615 7.779718 0.025770 1.091452
aescoot_wt_a_mu -0.003528 NaN NaN 7.746645 -4.5546e-04
aescoot_wt_b_mu -0.706853 NaN NaN 0.320134 -2.207993
aescoot_wt_a_sigma -0.011811 NaN NaN 17.119066 -6.8990e-04
aescoot_wt_b_sigma -0.090733 NaN NaN 0.246141 -0.368621
awalk_a_mu -0.183481 NaN NaN 10.420448 -0.017608
awalk_b_mu -1.111697 0.078548 -14.153164 0.303173 -3.666869
awalk_a_sigma -0.383623 NaN NaN 4.947218 -0.077543
awalk_b_sigma 0.976724 0.123691 7.896509 0.449949 2.170746
delta_a -0.315632 0.341708 -0.923688 0.611491 -0.516167
delta_b 0.000000 NA NA NA NA
gamma_age1_a -0.012578 0.306157 -0.041082 1.035440 -0.012147
gamma_age1_b 0.000000 NA NA NA NA
gamma_age2_a 0.024861 0.207783 0.119651 0.502881 0.049438
gamma_age2_b 0.000000 NA NA NA NA
gamma_age3_a 0.000000 NA NA NA NA
gamma_age3_b 0.000000 NA NA NA NA
gamma_female_a -0.108020 0.186365 -0.579618 0.508269 -0.212526
gamma_female_b 0.000000 NA NA NA NA
gamma_hhinc1_a 0.001143 0.403982 0.002828 1.273363 8.9726e-04
gamma_hhinc1_b 0.000000 NA NA NA NA
gamma_hhinc2_a -0.216718 0.223759 -0.968534 0.434850 -0.498375
gamma_hhinc2_b 0.000000 NA NA NA NA
gamma_hhinc3_a 0.000000 NA NA NA NA
gamma_hhinc3_b 0.000000 NA NA NA NA
gamma_ncar0_a 0.000000 NA NA NA NA
gamma_ncar0_b 0.000000 NA NA NA NA
gamma_ncar1_a -0.139439 0.306029 -0.455639 0.372502 -0.374330
gamma_ncar1_b 0.000000 NA NA NA NA
gamma_ncar2_a -0.157932 0.309772 -0.509832 0.765578 -0.206291
gamma_ncar2_b 0.000000 NA NA NA NA
gamma_nbic0_a 0.000000 NA NA NA NA
gamma_nbic0_b 0.000000 NA NA NA NA
gamma_nbic1_a -0.204507 0.208392 -0.981359 0.681324 -0.300162
gamma_nbic1_b 0.000000 NA NA NA NA
gamma_nbic2_a -0.030864 0.253097 -0.121943 0.510071 -0.060508
gamma_nbic2_b 0.000000 NA NA NA NA
Summary of class allocation for model component :
Mean prob.
class_1 0.3511
class_2 0.6489
-
stephanehess
- Site Admin
- Posts: 1354
- Joined: 24 Apr 2020, 16:29
Re: n sqrt(diag(varcov)) : NaNs produced
Hi
you have a huge number of random coefficients. Your model is quite possibly not empirically identified. Did you start with a simpler model? Also, 500 draws is not going to be nearly enough
Stephane
you have a huge number of random coefficients. Your model is quite possibly not empirically identified. Did you start with a simpler model? Also, 500 draws is not going to be nearly enough
Stephane
-
janak12_jp
- Posts: 16
- Joined: 08 Sep 2021, 16:52
Re: n sqrt(diag(varcov)) : NaNs produced
Hi,
Yes, I have tried with simpler model where only IVTT was taken as random, however the issue was coming.
Keeping that apart, should I try with more than 500 draws?
When I used sole IVTT as random with classical estimation, I get an another error-
Error in if (sum(inClassProb[[cc]]) == 0) stop("CALCULATION ISSUE - Within class probabilities for model component \"", : missing value where TRUE/FALSE needed
Further, I am trying the same model (IVTT as random) with Bayesian Estimation. But it produces NaN for rho-squared, AIC and BIC values. I see that ""Likelihood equal to zero for at least one individual in this component". Can you suggest for this as well?
Also, how to see the class allocation probabilities in HB model. I cannot see it in model summary.
Yes, I have tried with simpler model where only IVTT was taken as random, however the issue was coming.
Keeping that apart, should I try with more than 500 draws?
When I used sole IVTT as random with classical estimation, I get an another error-
Error in if (sum(inClassProb[[cc]]) == 0) stop("CALCULATION ISSUE - Within class probabilities for model component \"", : missing value where TRUE/FALSE needed
Further, I am trying the same model (IVTT as random) with Bayesian Estimation. But it produces NaN for rho-squared, AIC and BIC values. I see that ""Likelihood equal to zero for at least one individual in this component". Can you suggest for this as well?
Also, how to see the class allocation probabilities in HB model. I cannot see it in model summary.
Last edited by janak12_jp on 19 Oct 2024, 06:58, edited 2 times in total.
Re: n sqrt(diag(varcov)) : NaNs produced
Hi,
I always recommend starting model estimation with a simple MNL model (no random coefficients at all). Only once you find a satisfactory MNL model I would recommend moving towards more complex models, such as MMNL (mixed MNL). Going from simple to more complex makes it easier to spot where the issues come from.
Concerning the number of draws, there are no hard rules, but in general, the more random coefficients you have, the more draws you need. I usually go for at least 2000 draws for publishable model (a 1000 maybe if 2000 is unfeasible). You should also use mlhs draws if you have many random coefficients to avoid correlation between draws.
About the error you get, I recommend you update to the latest version of Apollo (v0.3.4) and try again.
I do not recall exactly, but when using Bayesian estimation, you will not get all the same indicators of fit as you get when using maximum likelihood estimation. Newer versions of Apollo may include more detail, but I recommend you look at the manual about this.
The message "Likelihood equal to zero for at least one individual in this component" means that the starting values used are not very good, leading to very small likelihoods (choice probabilities) for some individuals. They are so small, that the computer's precision confuses them with zero. When this happens, and depending on the type of estimation you are using, Apollo will either turn zeros into very small probabilities (with a warning), or simply fail. I recommend you look for better starting values, such as the estimated values of simpler models.
Finally, you would normally use apollo_lcUnconditionals to get the class allocation of an estimated model. Unfortunately, this function is not compatible with models estimated using the Bayesian approach. In general, I would recommend not estimating latent class models using Bayesian estimation in Apollo, at least for now (v0.3.4).
Best wishes
David
I always recommend starting model estimation with a simple MNL model (no random coefficients at all). Only once you find a satisfactory MNL model I would recommend moving towards more complex models, such as MMNL (mixed MNL). Going from simple to more complex makes it easier to spot where the issues come from.
Concerning the number of draws, there are no hard rules, but in general, the more random coefficients you have, the more draws you need. I usually go for at least 2000 draws for publishable model (a 1000 maybe if 2000 is unfeasible). You should also use mlhs draws if you have many random coefficients to avoid correlation between draws.
About the error you get, I recommend you update to the latest version of Apollo (v0.3.4) and try again.
I do not recall exactly, but when using Bayesian estimation, you will not get all the same indicators of fit as you get when using maximum likelihood estimation. Newer versions of Apollo may include more detail, but I recommend you look at the manual about this.
The message "Likelihood equal to zero for at least one individual in this component" means that the starting values used are not very good, leading to very small likelihoods (choice probabilities) for some individuals. They are so small, that the computer's precision confuses them with zero. When this happens, and depending on the type of estimation you are using, Apollo will either turn zeros into very small probabilities (with a warning), or simply fail. I recommend you look for better starting values, such as the estimated values of simpler models.
Finally, you would normally use apollo_lcUnconditionals to get the class allocation of an estimated model. Unfortunately, this function is not compatible with models estimated using the Bayesian approach. In general, I would recommend not estimating latent class models using Bayesian estimation in Apollo, at least for now (v0.3.4).
Best wishes
David
-
janak12_jp
- Posts: 16
- Joined: 08 Sep 2021, 16:52
Re: n sqrt(diag(varcov)) : NaNs produced
Hi David,
Thank you for the reply.
Yes, I started with the MNL model only. I got the results, used those estimates for MMNL model with IVTT as random where I got this error.
I will update the apollo and play with increasing draws again to check with both these errors.
I will try to estimate and come back here to post about the outcomes, if I am successful (or else another query!!
).
Thank you for the reply.
Yes, I started with the MNL model only. I got the results, used those estimates for MMNL model with IVTT as random where I got this error.
I will update the apollo and play with increasing draws again to check with both these errors.
I will try to estimate and come back here to post about the outcomes, if I am successful (or else another query!!