Page 1 of 1

n sqrt(diag(varcov)) : NaNs produced

Posted: 16 Dec 2021, 09:30
by MPFMAS001
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.