Model run using Apollo for R, version 0.2.3 on Darwin by stephane.hess www.ApolloChoiceModelling.com Model name : Apollo_example_18 Model description : Simple LC model on Swiss route choice data Model run at : 2021-02-04 18:28:44 Estimation method : bfgs Model diagnosis : successful convergence Number of individuals : 388 Number of rows in database : 3492 Number of modelled outcomes : 3492 Number of cores used : 2 Model without mixing LL(start) : -1755.505 LL(0, whole model) : -2420.47 LL(final, whole model) : -1564.099 Rho-square (0) : 0.3538 Adj.Rho-square (0) : 0.3497 AIC : 3148.2 BIC : 3209.78 LL(0,Class_1) : -2420.47 LL(final,Class_1) : -1780.846 LL(0,Class_2) : -2420.47 LL(final,Class_2) : -2324.142 Estimated parameters : 10 Time taken (hh:mm:ss) : 00:00:15.8 pre-estimation : 00:00:3.56 estimation : 00:00:6.97 post-estimation : 00:00:5.26 Iterations : 25 Min abs eigenvalue of Hessian : 10.79777 Estimates: Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0) asc_1 -0.04479 0.048012 -0.9330 0.052739 -0.84937 asc_2 0.00000 NA NA NA NA beta_tt_a -0.07353 0.008561 -8.5896 0.018036 -4.07689 beta_tt_b -0.09782 0.014163 -6.9070 0.030562 -3.20074 beta_tc_a -0.09568 0.016254 -5.8868 0.024270 -3.94241 beta_tc_b -0.53393 0.093835 -5.6901 0.257705 -2.07185 beta_hw_a -0.03964 0.003895 -10.1749 0.007959 -4.97978 beta_hw_b -0.04747 0.005679 -8.3590 0.010500 -4.52068 beta_ch_a -0.76405 0.105070 -7.2718 0.284204 -2.68838 beta_ch_b -2.16720 0.184807 -11.7268 0.289828 -7.47755 delta_a 0.03946 0.267931 0.1473 0.687433 0.05740 delta_b 0.00000 NA NA NA NA Summary of class allocation for LC model component : Mean prob. Class_1 0.5099 Class_2 0.4901 Overview of choices for MNL model component Class_1: alt1 alt2 Times available 3492.00 3492.00 Times chosen 1734.00 1758.00 Percentage chosen overall 49.66 50.34 Percentage chosen when available 49.66 50.34 Overview of choices for MNL model component Class_2: alt1 alt2 Times available 3492.00 3492.00 Times chosen 1734.00 1758.00 Percentage chosen overall 49.66 50.34 Percentage chosen when available 49.66 50.34 Classical covariance matrix: asc_1 beta_tt_a beta_tt_b beta_tc_a beta_tc_b beta_hw_a beta_hw_b beta_ch_a asc_1 0.002305 1.911e-05 -1.906e-05 1.026e-05 -2.6750e-04 -5.738e-06 1.045e-05 -3.0911e-04 beta_tt_a 1.911e-05 7.328e-05 -5.308e-05 1.0775e-04 -4.2040e-04 4.109e-06 -2.364e-06 -9.632e-05 beta_tt_b -1.906e-05 -5.308e-05 2.0058e-04 -7.284e-05 0.001025 7.761e-06 -1.847e-06 1.8102e-04 beta_tc_a 1.026e-05 1.0775e-04 -7.284e-05 2.6419e-04 -4.3273e-04 4.497e-06 1.461e-06 1.452e-06 beta_tc_b -2.6750e-04 -4.2040e-04 0.001025 -4.3273e-04 0.008805 8.212e-05 -8.682e-06 0.005106 beta_hw_a -5.738e-06 4.109e-06 7.761e-06 4.497e-06 8.212e-05 1.517e-05 -1.255e-05 1.8481e-04 beta_hw_b 1.045e-05 -2.364e-06 -1.847e-06 1.461e-06 -8.682e-06 -1.255e-05 3.225e-05 -1.4476e-04 beta_ch_a -3.0911e-04 -9.632e-05 1.8102e-04 1.452e-06 0.005106 1.8481e-04 -1.4476e-04 0.011040 beta_ch_b -5.623e-05 -6.2506e-04 9.0013e-04 -3.9338e-04 0.008574 -8.973e-05 3.7173e-04 0.003702 delta_a 8.4234e-04 7.8351e-04 -7.0912e-04 3.6226e-04 -0.015285 -2.7072e-04 1.6995e-04 -0.020218 beta_ch_b delta_a asc_1 -5.623e-05 8.4234e-04 beta_tt_a -6.2506e-04 7.8351e-04 beta_tt_b 9.0013e-04 -7.0912e-04 beta_tc_a -3.9338e-04 3.6226e-04 beta_tc_b 0.008574 -0.01529 beta_hw_a -8.973e-05 -2.7072e-04 beta_hw_b 3.7173e-04 1.6995e-04 beta_ch_a 0.003702 -0.02022 beta_ch_b 0.034154 -0.02409 delta_a -0.024090 0.07179 Robust covariance matrix: asc_1 beta_tt_a beta_tt_b beta_tc_a beta_tc_b beta_hw_a beta_hw_b beta_ch_a asc_1 0.002781 8.267e-05 -1.7114e-04 4.219e-05 -0.002624 -9.731e-05 1.1585e-04 -0.003368 beta_tt_a 8.267e-05 3.2531e-04 -3.5743e-04 3.5878e-04 -0.003551 -4.896e-05 5.697e-05 -0.002400 beta_tt_b -1.7114e-04 -3.5743e-04 9.3406e-04 -4.4290e-04 0.005589 1.0402e-04 -1.3132e-04 0.002397 beta_tc_a 4.219e-05 3.5878e-04 -4.4290e-04 5.8905e-04 -0.003276 -4.520e-05 6.576e-05 -0.001495 beta_tc_b -0.002624 -0.003551 0.005589 -0.003276 0.066412 0.001343 -0.001457 0.059639 beta_hw_a -9.731e-05 -4.896e-05 1.0402e-04 -4.520e-05 0.001343 6.335e-05 -6.844e-05 0.001594 beta_hw_b 1.1585e-04 5.697e-05 -1.3132e-04 6.576e-05 -0.001457 -6.844e-05 1.1025e-04 -0.001664 beta_ch_a -0.003368 -0.002400 0.002397 -0.001495 0.059639 0.001594 -0.001664 0.080772 beta_ch_b 8.365e-05 -0.003244 0.003400 -0.002412 0.038716 2.0014e-04 2.6323e-04 0.028771 delta_a 0.006915 0.007799 -0.006956 0.005286 -0.152974 -0.003456 0.003549 -0.182264 beta_ch_b delta_a asc_1 8.365e-05 0.006915 beta_tt_a -0.003244 0.007799 beta_tt_b 0.003400 -0.006956 beta_tc_a -0.002412 0.005286 beta_tc_b 0.038716 -0.152974 beta_hw_a 2.0014e-04 -0.003456 beta_hw_b 2.6323e-04 0.003549 beta_ch_a 0.028771 -0.182264 beta_ch_b 0.084000 -0.107295 delta_a -0.107295 0.472563 Classical correlation matrix: asc_1 beta_tt_a beta_tt_b beta_tc_a beta_tc_b beta_hw_a beta_hw_b beta_ch_a asc_1 1.000000 0.04650 -0.02803 0.01315 -0.05938 -0.03068 0.03833 -0.06127 beta_tt_a 0.046499 1.00000 -0.43781 0.77441 -0.52334 0.12322 -0.04862 -0.10708 beta_tt_b -0.028032 -0.43781 1.00000 -0.31642 0.77107 0.14068 -0.02297 0.12165 beta_tc_a 0.013150 0.77441 -0.31642 1.00000 -0.28373 0.07102 0.01583 8.5029e-04 beta_tc_b -0.059376 -0.52334 0.77107 -0.28373 1.00000 0.22465 -0.01629 0.51791 beta_hw_a -0.030682 0.12322 0.14068 0.07102 0.22465 1.00000 -0.56725 0.45153 beta_hw_b 0.038329 -0.04862 -0.02297 0.01583 -0.01629 -0.56725 1.00000 -0.24263 beta_ch_a -0.061274 -0.10708 0.12165 8.5029e-04 0.51791 0.45153 -0.24263 1.00000 beta_ch_b -0.006337 -0.39509 0.34391 -0.13096 0.49444 -0.12463 0.35422 0.19065 delta_a 0.065481 0.34160 -0.18687 0.08318 -0.60798 -0.25938 0.11170 -0.71816 beta_ch_b delta_a asc_1 -0.006337 0.06548 beta_tt_a -0.395092 0.34160 beta_tt_b 0.343907 -0.18687 beta_tc_a -0.130961 0.08318 beta_tc_b 0.494441 -0.60798 beta_hw_a -0.124634 -0.25938 beta_hw_b 0.354215 0.11170 beta_ch_a 0.190645 -0.71816 beta_ch_b 1.000000 -0.48650 delta_a -0.486504 1.00000 Robust correlation matrix: asc_1 beta_tt_a beta_tt_b beta_tc_a beta_tc_b beta_hw_a beta_hw_b beta_ch_a asc_1 1.000000 0.08691 -0.1062 0.03296 -0.1931 -0.23182 0.20921 -0.2247 beta_tt_a 0.086913 1.00000 -0.6484 0.81959 -0.7639 -0.34107 0.30081 -0.4682 beta_tt_b -0.106176 -0.64842 1.0000 -0.59709 0.7097 0.42761 -0.40923 0.2760 beta_tc_a 0.032961 0.81959 -0.5971 1.00000 -0.5238 -0.23400 0.25806 -0.2167 beta_tc_b -0.193057 -0.76393 0.7097 -0.52379 1.0000 0.65478 -0.53840 0.8143 beta_hw_a -0.231819 -0.34107 0.4276 -0.23400 0.6548 1.00000 -0.81888 0.7048 beta_hw_b 0.209205 0.30081 -0.4092 0.25806 -0.5384 -0.81888 1.00000 -0.5575 beta_ch_a -0.224701 -0.46818 0.2760 -0.21675 0.8143 0.70478 -0.55751 1.0000 beta_ch_b 0.005473 -0.62056 0.3838 -0.34293 0.5184 0.08676 0.08650 0.3493 delta_a 0.190734 0.62898 -0.3311 0.31686 -0.8635 -0.63160 0.49170 -0.9329 beta_ch_b delta_a asc_1 0.005473 0.1907 beta_tt_a -0.620560 0.6290 beta_tt_b 0.383794 -0.3311 beta_tc_a -0.342930 0.3169 beta_tc_b 0.518355 -0.8635 beta_hw_a 0.086758 -0.6316 beta_hw_b 0.086497 0.4917 beta_ch_a 0.349294 -0.9329 beta_ch_b 1.000000 -0.5385 delta_a -0.538528 1.0000 20 worst outliers in terms of lowest average per choice prediction: ID Avg prob per choice 22580 0.2768536 23205 0.2984703 14802 0.3143901 16489 0.3259515 16617 0.3263200 16178 0.3403193 15174 0.3422700 22961 0.3447648 18219 0.3490716 22278 0.3523954 20063 0.3576561 21922 0.3634034 20010 0.3660278 14074 0.3697341 13214 0.3728264 20100 0.3735647 76862 0.3760683 21623 0.3836299 13863 0.3953466 22820 0.4080081 Changes in parameter estimates from starting values: Initial Estimate Difference asc_1 0.00000 -0.04479 -0.044794 asc_2 0.00000 0.00000 0.000000 beta_tt_a 0.00000 -0.07353 -0.073533 beta_tt_b 0.00000 -0.09782 -0.097822 beta_tc_a 0.00000 -0.09568 -0.095684 beta_tc_b 0.00000 -0.53393 -0.533926 beta_hw_a -0.03960 -0.03964 -3.604e-05 beta_hw_b -0.04790 -0.04747 4.3249e-04 beta_ch_a -0.76240 -0.76405 -0.001648 beta_ch_b -2.17250 -2.16720 0.005299 delta_a 0.03290 0.03946 0.006557 delta_b 0.00000 0.00000 0.000000 Settings and functions used in model definition: apollo_control -------------- Value modelName "Apollo_example_18" modelDescr "Simple LC model on Swiss route choice data" indivID "ID" nCores "2" noDiagnostics "TRUE" debug "FALSE" workInLogs "FALSE" seed "13" mixing "FALSE" HB "FALSE" noValidation "FALSE" panelData "TRUE" analyticGrad "TRUE" Hessian routines attempted -------------- numerical second derivative of LL (using numDeriv) Scaling used in computing Hessian -------------- Value asc_1 0.04479433 beta_tt_a 0.07353256 beta_tt_b 0.09782218 beta_tc_a 0.09568384 beta_tc_b 0.53392640 beta_hw_a 0.03963604 beta_hw_b 0.04746751 beta_ch_a 0.76404806 beta_ch_b 2.16720142 delta_a 0.03945716 apollo_lcPars ------------- function(apollo_beta, apollo_inputs){ lcpars = list() lcpars[["beta_tt"]] = list(beta_tt_a, beta_tt_b) lcpars[["beta_tc"]] = list(beta_tc_a, beta_tc_b) lcpars[["beta_hw"]] = list(beta_hw_a, beta_hw_b) lcpars[["beta_ch"]] = list(beta_ch_a, beta_ch_b) V=list() V[["class_a"]] = delta_a V[["class_b"]] = delta_b mnl_settings = list( alternatives = c(class_a=1, class_b=2), avail = 1, choiceVar = NA, V = V ) lcpars[["pi_values"]] = apollo_mnl(mnl_settings, functionality="raw") lcpars[["pi_values"]] = apollo_firstRow(lcpars[["pi_values"]], apollo_inputs) return(lcpars) 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(alt1=1, alt2=2), avail = list(alt1=1, alt2=1), choiceVar = choice ) ### Loop over classes s=1 while(s<=2){ ### Compute class-specific utilities V=list() V[['alt1']] = asc_1 + beta_tc[[s]]*tc1 + beta_tt[[s]]*tt1 + beta_hw[[s]]*hw1 + beta_ch[[s]]*ch1 V[['alt2']] = asc_2 + beta_tc[[s]]*tc2 + beta_tt[[s]]*tt2 + beta_hw[[s]]*hw2 + beta_ch[[s]]*ch2 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) s=s+1 } ### 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)