Re: ICLV model convergence
Posted: 25 Apr 2023, 09:49
by eeshanbhaduri
Hi,
yes, the error happens in the second stage estimation.
Please find the code below.
Best,
Eeshan
Code:::
# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS ####
# ################################################################# #
install.packages("apollo")
install.packages("ggcorrplot")
version
### Load Apollo library
#install.packages("apollo")
library(apollo)
library(readxl)
library(tidyverse)
library(ggcorrplot)
### Clear memory
rm(list = ls())
### Initialise code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName = "MNL_RP_SP_Kolkata",
modelDescr = "Kolkata SP model FINAL",
indivID = "sur_mk_id",
nCores = 4,
outputDirectory = "output"
)
# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #
database <- read_excel("Full_dataset_KOLKATA_merged_MOD_V11.xlsx", sheet="Final Merged_Choice wise")
database <- arrange(database, desc(sur_mk_id))
database <- filter(database, !is.na(mode_choice))
database <- filter(database, !(mode_choice == "Car" & car_count == 0))
database <- filter(database, !(block_id == 5 & set==3))
database <- mutate(database, choice = ifelse(mode_choice == "Car",1,
ifelse(mode_choice == "Ride-hailing",2,
ifelse(mode_choice == "Taxi",3,
ifelse(mode_choice == "Bus",4,
ifelse(mode_choice == "Metro rail",5,6))))))
ifelse(arkshw_crowd == 75,1,0)))
#adding the LV dummy variables
database <- mutate(database, rhsatt_interface_ordered = ifelse(rhsatt_interface == "Strongly agree",7,
ifelse(rhsatt_interface == "Agree",6,
ifelse(rhsatt_interface == "Somewhat agree",5,
ifelse(rhsatt_interface == "Neither agree nor disagree",4,
ifelse(rhsatt_interface == "Somewhat disagree",3,
ifelse(rhsatt_interface == "Disagree",2,1)))))))
database <- mutate(database, rhsatt_payment_ordered = ifelse(rhsatt_payment == "Strongly agree",7,
ifelse(rhsatt_payment == "Agree",6,
ifelse(rhsatt_payment == "Somewhat agree",5,
ifelse(rhsatt_payment == "Neither agree nor disagree",4,
ifelse(rhsatt_payment == "Somewhat disagree",3,
ifelse(rhsatt_payment == "Disagree",2,1)))))))
database <- mutate(database, rhsatt_trustworthy_ordered = ifelse(rhsatt_trustworthy == "Strongly agree",7,
ifelse(rhsatt_trustworthy == "Agree",6,
ifelse(rhsatt_trustworthy == "Somewhat agree",5,
ifelse(rhsatt_trustworthy == "Neither agree nor disagree",4,
ifelse(rhsatt_trustworthy == "Somewhat disagree",3,
ifelse(rhsatt_trustworthy == "Disagree",2,1)))))))
#adding the availability
database <- mutate(database, car_avl = ifelse(car_count == 0,0,1))
### Create new variable with average income
database$mean_income_value = mean(database$income_value)
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(asc_car = 0,
asc_rhs = 0,
asc_taxi = 0,
asc_bus = 0,
asc_metro = 0,
asc_auto = 0,
b_tt_generic = 0,
b_tt_SD_generic = 0,
b_wt_generic = 0,
b_crowd_generic = 0,
b_flex_detour = 0,
b_flex_avlbl = 0,
b_cost = 0,
############# Coefficient for the LV parameter #########################
lambda_rhs_att_car = 0,
############# Covariates for the LV parameter #########################
gamma_female = 0,
############# Indicators for the LV parameter #########################
# LV = Attitude towards Ride-hailing services
zeta_rhsatt_interface = 1,
zeta_rhsatt_payment = 1,
zeta_rhsatt_trustworthy = 1,
############# Thresholds for the LV parameter #########################
# LV = Attitude towards Ride-hailing services
tau_rhsatt_interface_1 =-3,
tau_rhsatt_interface_2 =-2,
tau_rhsatt_interface_3 = -1,
tau_rhsatt_interface_4 = 1,
tau_rhsatt_interface_5 = 2,
tau_rhsatt_interface_6 = 3,
tau_rhsatt_payment_1 =-3,
tau_rhsatt_payment_2 =-2,
tau_rhsatt_payment_3 = -1,
tau_rhsatt_payment_4 = 1,
tau_rhsatt_payment_5 = 2,
tau_rhsatt_payment_6 = 3,
tau_rhsatt_trust_1 =-3,
tau_rhsatt_trust_2 =-2,
tau_rhsatt_trust_3 = -1,
tau_rhsatt_trust_4 = 1,
tau_rhsatt_trust_5 = 2,
tau_rhsatt_trust_6 = 3,
mu_pf = 1,
mu_ps = 1,
mu_fc = 1)
### Vector with names (in quotes) of parameters to be kept fixed at their starting value in apollo_beta, use apollo_beta_fixed = c() if none
apollo_fixed = c("asc_car", "mu_fc")
### Read in starting values for at least some parameters from existing model output file
#apollo_beta = apollo_readBeta(apollo_beta, apollo_fixed, "MNL_SP", overwriteFixed=FALSE)
# ################################################################# #
#### DEFINE RANDOM COMPONENTS ####
# ################################################################# #
### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "halton",
interNDraws = 500,
interUnifDraws = c(),
interNormDraws = c("eta"),
intraDrawsType = "",
intraNDraws = 0,
intraUnifDraws = c(),
intraNormDraws = c()
)
### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()
randcoeff[["LV_rhs_att"]] = gamma_female * gender_dummy + eta
return(randcoeff)
}
# ################################################################# #
#### 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()
### Likelihood of indicators
ol_settings1 = list(outcomeOrdered = rhsatt_interface_ordered ,
V = zeta_rhsatt_interface*LV_rhs_att,
tau = list(tau_rhsatt_interface_1, tau_rhsatt_interface_2, tau_rhsatt_interface_3,
tau_rhsatt_interface_4, tau_rhsatt_interface_5, tau_rhsatt_interface_6),
rows = (pref_first==1),
componentName = "rhsatt_interface")
ol_settings2 = list(outcomeOrdered = rhsatt_payment_ordered ,
V = zeta_rhsatt_payment*LV_rhs_att,
tau = list(tau_rhsatt_payment_1, tau_rhsatt_payment_2, tau_rhsatt_payment_3,
tau_rhsatt_payment_4, tau_rhsatt_payment_5, tau_rhsatt_payment_6),
rows = (pref_first==1),
componentName = "rhsatt_payment")
ol_settings3 = list(outcomeOrdered = rhsatt_trustworthy_ordered ,
V = zeta_rhsatt_trustworthy*LV_rhs_att,
tau = list(tau_rhsatt_trust_1, tau_rhsatt_trust_2, tau_rhsatt_trust_3,
tau_rhsatt_trust_4, tau_rhsatt_trust_5, tau_rhsatt_trust_6),
rows = (pref_first==1),
componentName = "rhsatt_trustworthy")
P[["rhsatt_interface"]] = apollo_ol(ol_settings1, functionality)
P[["rhsatt_payment"]] = apollo_ol(ol_settings2, functionality)
P[["rhsatt_trustworthy"]] = apollo_ol(ol_settings3, functionality)
### Likelihood of choices
### List of utilities: these must use the same names as in mnl_settings, order is irrelevant
V = list()
V[['car']] = asc_car + b_cost *car_cost + b_tt_generic * car_tt + b_tt_SD_generic * car_tt_SD +
b_flex_detour * car_flex_D2 + b_flex_avlbl * car_flex_D3 +
lambda_rhs_att_car * LV_rhs_att
V[['rhs']] = asc_rhs + b_cost * rhs_cost + b_tt_generic * rhs_tt + b_tt_SD_generic * rhs_tt_SD +
b_wt_generic * rhs_wt + b_flex_detour * rhs_flex_D2
V[['taxi']] = asc_taxi + b_cost * taxi_cost + b_tt_generic * taxi_tt + b_tt_SD_generic * taxi_tt_SD +
b_wt_generic * taxi_wt + b_flex_detour * taxi_flex_D2
V[['bus']] = asc_bus + b_cost * bus_cost + b_tt_generic * bus_tt + b_tt_SD_generic * bus_tt_SD +
b_wt_generic * bus_wt + b_crowd_generic * bus_crowd
V[['metro']] = asc_metro + b_cost * metro_cost + b_tt_generic * metro_tt + b_tt_SD_generic * metro_tt_SD +
b_wt_generic * metro_wt + b_crowd_generic * metro_crowd
V[['auto']] = asc_auto + b_cost * arkshw_cost + b_tt_generic * arkshw_tt + b_tt_SD_generic * arkshw_tt_SD +
b_wt_generic * arkshw_wt + b_flex_detour * arkshw_flex_D2
### Compute probabilities for the first preference part of the data using MNL model
mnl_settings_pref_first = list(
alternatives = c(car=1, rhs=2, taxi=3),
avail = list(car=car_avl, rhs=1, taxi=1),
choiceVar = choice,
utilities = list(car = mu_pf*V[["car"]],
rhs = mu_pf*V[["rhs"]],
taxi = mu_pf*V[["taxi"]]),
rows = (pref_first ==1),
componentName='pref_first'
)
### Compute probabilities using MNL model
P[["pref_first"]] = apollo_mnl(mnl_settings_pref_first, functionality)
### Compute probabilities for the second preference part of the data using MNL model
mnl_settings_pref_second = list(
alternatives = c(bus=4, metro=5, auto=6),
avail = list(bus=1, metro=1, auto=1),
choiceVar = choice,
utilities = list(bus = mu_ps*V[["bus"]],
metro = mu_ps*V[["metro"]],
auto = mu_ps*V[["auto"]]),
rows = (pref_second ==1),
componentName='pref_second'
)
### Compute probabilities using MNL model
P[["pref_second"]] = apollo_mnl(mnl_settings_pref_second, functionality)
### Compute probabilities for the final choice part of the data using MNL model
mnl_settings_final_choice = list(
alternatives = c(car=1, rhs=2, taxi=3, bus=4, metro=5, auto=6),
avail = list(car=car_avl, rhs=1, taxi=1, bus=1, metro=1, auto=1),
choiceVar = choice,
utilities = list(car = mu_fc*V[["car"]],
rhs = mu_fc*V[["rhs"]],
taxi = mu_fc*V[["taxi"]],
bus = mu_fc*V[["bus"]],
metro = mu_fc*V[["metro"]],
auto = mu_fc*V[["auto"]]),
rows = (final_choice ==1),
componentName='final_choice'
)
### Compute probabilities using MNL model
P[["final_choice"]] = apollo_mnl(mnl_settings_final_choice, functionality)
### Average across intra-individual draws
#P = apollo_avgIntraDraws(P, apollo_inputs, functionality)
### Combined model
P = apollo_combineModels(P, apollo_inputs, functionality)
### Take product across observation for same individual
P = apollo_panelProd(P, apollo_inputs, functionality)
### Average across inter-individual draws
P = apollo_avgInterDraws(P, apollo_inputs, functionality)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
# ################################################################# #
#### MODEL ESTIMATION ####
# ################################################################# #
#apollo_beta=apollo_searchStart(apollo_beta, apollo_fixed,apollo_probabilities, apollo_inputs)
### Optional: calculate LL before model estimation
#apollo_llCalc(apollo_beta, apollo_probabilities, apollo_inputs)
model = apollo_estimate(apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs, estimate_settings=list(hessianRoutine="maxLik"))
# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #
apollo_modelOutput(model,modelOutput_settings=list(printOutliers=10))
# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS ####
# ################################################################# #
install.packages("apollo")
install.packages("ggcorrplot")
version
### Load Apollo library
#install.packages("apollo")
library(apollo)
library(readxl)
library(tidyverse)
library(ggcorrplot)
### Clear memory
rm(list = ls())
### Initialise code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName = "MNL_RP_SP_Kolkata",
modelDescr = "Kolkata SP model FINAL",
indivID = "sur_mk_id",
nCores = 4,
outputDirectory = "output"
)
# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #
database <- read_excel("Full_dataset_KOLKATA_merged_MOD_V11.xlsx", sheet="Final Merged_Choice wise")
database <- arrange(database, desc(sur_mk_id))
database <- filter(database, !is.na(mode_choice))
database <- filter(database, !(mode_choice == "Car" & car_count == 0))
database <- filter(database, !(block_id == 5 & set==3))
database <- mutate(database, choice = ifelse(mode_choice == "Car",1,
ifelse(mode_choice == "Ride-hailing",2,
ifelse(mode_choice == "Taxi",3,
ifelse(mode_choice == "Bus",4,
ifelse(mode_choice == "Metro rail",5,6))))))
ifelse(arkshw_crowd == 75,1,0)))
#adding the LV dummy variables
database <- mutate(database, rhsatt_interface_ordered = ifelse(rhsatt_interface == "Strongly agree",7,
ifelse(rhsatt_interface == "Agree",6,
ifelse(rhsatt_interface == "Somewhat agree",5,
ifelse(rhsatt_interface == "Neither agree nor disagree",4,
ifelse(rhsatt_interface == "Somewhat disagree",3,
ifelse(rhsatt_interface == "Disagree",2,1)))))))
database <- mutate(database, rhsatt_payment_ordered = ifelse(rhsatt_payment == "Strongly agree",7,
ifelse(rhsatt_payment == "Agree",6,
ifelse(rhsatt_payment == "Somewhat agree",5,
ifelse(rhsatt_payment == "Neither agree nor disagree",4,
ifelse(rhsatt_payment == "Somewhat disagree",3,
ifelse(rhsatt_payment == "Disagree",2,1)))))))
database <- mutate(database, rhsatt_trustworthy_ordered = ifelse(rhsatt_trustworthy == "Strongly agree",7,
ifelse(rhsatt_trustworthy == "Agree",6,
ifelse(rhsatt_trustworthy == "Somewhat agree",5,
ifelse(rhsatt_trustworthy == "Neither agree nor disagree",4,
ifelse(rhsatt_trustworthy == "Somewhat disagree",3,
ifelse(rhsatt_trustworthy == "Disagree",2,1)))))))
#adding the availability
database <- mutate(database, car_avl = ifelse(car_count == 0,0,1))
### Create new variable with average income
database$mean_income_value = mean(database$income_value)
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(asc_car = 0,
asc_rhs = 0,
asc_taxi = 0,
asc_bus = 0,
asc_metro = 0,
asc_auto = 0,
b_tt_generic = 0,
b_tt_SD_generic = 0,
b_wt_generic = 0,
b_crowd_generic = 0,
b_flex_detour = 0,
b_flex_avlbl = 0,
b_cost = 0,
############# Coefficient for the LV parameter #########################
lambda_rhs_att_car = 0,
############# Covariates for the LV parameter #########################
gamma_female = 0,
############# Indicators for the LV parameter #########################
# LV = Attitude towards Ride-hailing services
zeta_rhsatt_interface = 1,
zeta_rhsatt_payment = 1,
zeta_rhsatt_trustworthy = 1,
############# Thresholds for the LV parameter #########################
# LV = Attitude towards Ride-hailing services
tau_rhsatt_interface_1 =-3,
tau_rhsatt_interface_2 =-2,
tau_rhsatt_interface_3 = -1,
tau_rhsatt_interface_4 = 1,
tau_rhsatt_interface_5 = 2,
tau_rhsatt_interface_6 = 3,
tau_rhsatt_payment_1 =-3,
tau_rhsatt_payment_2 =-2,
tau_rhsatt_payment_3 = -1,
tau_rhsatt_payment_4 = 1,
tau_rhsatt_payment_5 = 2,
tau_rhsatt_payment_6 = 3,
tau_rhsatt_trust_1 =-3,
tau_rhsatt_trust_2 =-2,
tau_rhsatt_trust_3 = -1,
tau_rhsatt_trust_4 = 1,
tau_rhsatt_trust_5 = 2,
tau_rhsatt_trust_6 = 3,
mu_pf = 1,
mu_ps = 1,
mu_fc = 1)
### Vector with names (in quotes) of parameters to be kept fixed at their starting value in apollo_beta, use apollo_beta_fixed = c() if none
apollo_fixed = c("asc_car", "mu_fc")
### Read in starting values for at least some parameters from existing model output file
#apollo_beta = apollo_readBeta(apollo_beta, apollo_fixed, "MNL_SP", overwriteFixed=FALSE)
# ################################################################# #
#### DEFINE RANDOM COMPONENTS ####
# ################################################################# #
### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "halton",
interNDraws = 500,
interUnifDraws = c(),
interNormDraws = c("eta"),
intraDrawsType = "",
intraNDraws = 0,
intraUnifDraws = c(),
intraNormDraws = c()
)
### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()
randcoeff[["LV_rhs_att"]] = gamma_female * gender_dummy + eta
return(randcoeff)
}
# ################################################################# #
#### 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()
### Likelihood of indicators
ol_settings1 = list(outcomeOrdered = rhsatt_interface_ordered ,
V = zeta_rhsatt_interface*LV_rhs_att,
tau = list(tau_rhsatt_interface_1, tau_rhsatt_interface_2, tau_rhsatt_interface_3,
tau_rhsatt_interface_4, tau_rhsatt_interface_5, tau_rhsatt_interface_6),
rows = (pref_first==1),
componentName = "rhsatt_interface")
ol_settings2 = list(outcomeOrdered = rhsatt_payment_ordered ,
V = zeta_rhsatt_payment*LV_rhs_att,
tau = list(tau_rhsatt_payment_1, tau_rhsatt_payment_2, tau_rhsatt_payment_3,
tau_rhsatt_payment_4, tau_rhsatt_payment_5, tau_rhsatt_payment_6),
rows = (pref_first==1),
componentName = "rhsatt_payment")
ol_settings3 = list(outcomeOrdered = rhsatt_trustworthy_ordered ,
V = zeta_rhsatt_trustworthy*LV_rhs_att,
tau = list(tau_rhsatt_trust_1, tau_rhsatt_trust_2, tau_rhsatt_trust_3,
tau_rhsatt_trust_4, tau_rhsatt_trust_5, tau_rhsatt_trust_6),
rows = (pref_first==1),
componentName = "rhsatt_trustworthy")
P[["rhsatt_interface"]] = apollo_ol(ol_settings1, functionality)
P[["rhsatt_payment"]] = apollo_ol(ol_settings2, functionality)
P[["rhsatt_trustworthy"]] = apollo_ol(ol_settings3, functionality)
### Likelihood of choices
### List of utilities: these must use the same names as in mnl_settings, order is irrelevant
V = list()
V[['car']] = asc_car + b_cost *car_cost + b_tt_generic * car_tt + b_tt_SD_generic * car_tt_SD +
b_flex_detour * car_flex_D2 + b_flex_avlbl * car_flex_D3 +
lambda_rhs_att_car * LV_rhs_att
V[['rhs']] = asc_rhs + b_cost * rhs_cost + b_tt_generic * rhs_tt + b_tt_SD_generic * rhs_tt_SD +
b_wt_generic * rhs_wt + b_flex_detour * rhs_flex_D2
V[['taxi']] = asc_taxi + b_cost * taxi_cost + b_tt_generic * taxi_tt + b_tt_SD_generic * taxi_tt_SD +
b_wt_generic * taxi_wt + b_flex_detour * taxi_flex_D2
V[['bus']] = asc_bus + b_cost * bus_cost + b_tt_generic * bus_tt + b_tt_SD_generic * bus_tt_SD +
b_wt_generic * bus_wt + b_crowd_generic * bus_crowd
V[['metro']] = asc_metro + b_cost * metro_cost + b_tt_generic * metro_tt + b_tt_SD_generic * metro_tt_SD +
b_wt_generic * metro_wt + b_crowd_generic * metro_crowd
V[['auto']] = asc_auto + b_cost * arkshw_cost + b_tt_generic * arkshw_tt + b_tt_SD_generic * arkshw_tt_SD +
b_wt_generic * arkshw_wt + b_flex_detour * arkshw_flex_D2
### Compute probabilities for the first preference part of the data using MNL model
mnl_settings_pref_first = list(
alternatives = c(car=1, rhs=2, taxi=3),
avail = list(car=car_avl, rhs=1, taxi=1),
choiceVar = choice,
utilities = list(car = mu_pf*V[["car"]],
rhs = mu_pf*V[["rhs"]],
taxi = mu_pf*V[["taxi"]]),
rows = (pref_first ==1),
componentName='pref_first'
)
### Compute probabilities using MNL model
P[["pref_first"]] = apollo_mnl(mnl_settings_pref_first, functionality)
### Compute probabilities for the second preference part of the data using MNL model
mnl_settings_pref_second = list(
alternatives = c(bus=4, metro=5, auto=6),
avail = list(bus=1, metro=1, auto=1),
choiceVar = choice,
utilities = list(bus = mu_ps*V[["bus"]],
metro = mu_ps*V[["metro"]],
auto = mu_ps*V[["auto"]]),
rows = (pref_second ==1),
componentName='pref_second'
)
### Compute probabilities using MNL model
P[["pref_second"]] = apollo_mnl(mnl_settings_pref_second, functionality)
### Compute probabilities for the final choice part of the data using MNL model
mnl_settings_final_choice = list(
alternatives = c(car=1, rhs=2, taxi=3, bus=4, metro=5, auto=6),
avail = list(car=car_avl, rhs=1, taxi=1, bus=1, metro=1, auto=1),
choiceVar = choice,
utilities = list(car = mu_fc*V[["car"]],
rhs = mu_fc*V[["rhs"]],
taxi = mu_fc*V[["taxi"]],
bus = mu_fc*V[["bus"]],
metro = mu_fc*V[["metro"]],
auto = mu_fc*V[["auto"]]),
rows = (final_choice ==1),
componentName='final_choice'
)
### Compute probabilities using MNL model
P[["final_choice"]] = apollo_mnl(mnl_settings_final_choice, functionality)
### Average across intra-individual draws
#P = apollo_avgIntraDraws(P, apollo_inputs, functionality)
### Combined model
P = apollo_combineModels(P, apollo_inputs, functionality)
### Take product across observation for same individual
P = apollo_panelProd(P, apollo_inputs, functionality)
### Average across inter-individual draws
P = apollo_avgInterDraws(P, apollo_inputs, functionality)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
# ################################################################# #
#### MODEL ESTIMATION ####
# ################################################################# #
#apollo_beta=apollo_searchStart(apollo_beta, apollo_fixed,apollo_probabilities, apollo_inputs)
### Optional: calculate LL before model estimation
#apollo_llCalc(apollo_beta, apollo_probabilities, apollo_inputs)
model = apollo_estimate(apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs, estimate_settings=list(hessianRoutine="maxLik"))
# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #
apollo_modelOutput(model,modelOutput_settings=list(printOutliers=10))
Re: ICLV model convergence
Posted: 25 Apr 2023, 12:51
by eeshanbhaduri
Hi Stephane,
Apologies. I tried to simplify the model reducing number of variables but the problem still persists (with "rhsatt_interface").
I am attaching the results for the updated code. Please have a look.
Thanks!
Result:
Model run by eurg using Apollo 0.2.8 on R 4.2.1 for Linux.
www.ApolloChoiceModelling.com
Model name : MNL_RP_SP_Kolkata
Model description : Kolkata SP model FINAL
Model run at : 2023-04-25 11:01:42
Estimation method : bfgs
Model diagnosis : successful convergence
Number of individuals : 1478
Number of rows in database : 11027
Number of modelled outcomes : 21026
rhsatt_interface : 3333
rhsatt_payment : 3333
rhsatt_trustworthy : 3333
pref_first : 3333
pref_second : 4021
final_choice : 3673
Number of cores used : 75
Number of inter-individual draws : 500 (halton)
LL(start) : -29869.51
LL (whole model) at equal shares, LL(0) : -32839.59
LL (whole model) at observed shares, LL(C) : -26462.6
LL(final, whole model) : -20409.1
Rho-squared vs equal shares : 0.3785
Adj.Rho-squared vs equal shares : 0.3774
Rho-squared vs observed shares : 0.2288
Adj.Rho-squared vs observed shares : 0.2274
AIC : 40892.19
BIC : 41118.32
LL(0,rhsatt_interface) : -6485.72
LL(final,rhsatt_interface) : -2068.55
LL(0,rhsatt_payment) : -6485.72
LL(final,rhsatt_payment) : -3398.38
LL(0,rhsatt_trustworthy) : -6485.72
LL(final,rhsatt_trustworthy) : -3578.26
LL(0,pref_first) : -2823.17
LL(final,pref_first) : -1687.25
LL(0,pref_second) : -4417.52
LL(final,pref_second) : -4128.23
LL(0,final_choice) : -6141.74
LL(final,final_choice) : -5275.1
Estimated parameters : 37
Time taken (hh:mm:ss) : 00:26:45.85
pre-estimation : 00:04:27.84
estimation : 00:07:4.19
post-estimation : 00:15:13.82
Iterations : 119
Min abs eigenvalue of Hessian : 1.412592
Some eigenvalues of Hessian are positive, indicating potential problems!
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_car 0.00000 NA NA NA NA
asc_rhs -0.72995 0.061193 -11.929 0.224585 -3.2502
asc_taxi -0.62744 0.037158 -16.885 0.231819 -2.7066
asc_bus -0.88868 NaN NaN 0.613085 -1.4495
asc_metro -0.64334 NaN NaN 0.700297 -0.9187
asc_auto -1.16182 NaN NaN 0.330376 -3.5166
b_tt_generic -0.08687 0.003867 -22.467 0.004976 -17.4573
b_tt_SD_generic -0.04398 0.005883 -7.477 0.017632 -2.4946
b_wt_generic -0.04300 0.002292 -18.760 0.009542 -4.5068
b_crowd_generic -0.01093 2.5203e-04 -43.366 0.002975 -3.6737
b_flex_detour 0.30069 NaN NaN 0.145782 2.0626
b_flex_avlbl 0.21943 0.067205 3.265 0.186989 1.1735
b_cost -0.01680 5.9111e-04 -28.418 0.001524 -11.0233
lambda_rhs_att_car -0.22712 NaN NaN 0.159305 -1.4257
gamma_female 0.12117 NaN NaN 0.014526 8.3418
zeta_rhsatt_interface 135.60999 13.485271 10.056 28.310398 4.7901
zeta_rhsatt_payment 2.60168 0.072020 36.125 0.175666 14.8104
zeta_rhsatt_trustworthy 2.49447 0.070473 35.396 0.179212 13.9191
tau_rhsatt_interface_1 -340.88868 35.569536 -9.584 69.880196 -4.8782
tau_rhsatt_interface_2 -198.00833 22.639807 -8.746 28.330757 -6.9892
tau_rhsatt_interface_3 -160.75923 17.014042 -9.449 31.054458 -5.1767
tau_rhsatt_interface_4 -83.37484 7.874655 -10.588 20.405833 -4.0858
tau_rhsatt_interface_5 -10.24663 NaN NaN 15.954228 -0.6423
tau_rhsatt_interface_6 192.04068 20.646455 9.301 37.616547 5.1052
tau_rhsatt_payment_1 -8.09702 0.363001 -22.306 0.547125 -14.7992
tau_rhsatt_payment_2 -5.60930 0.158427 -35.406 0.274309 -20.4488
tau_rhsatt_payment_3 -4.44350 0.114495 -38.809 0.229676 -19.3468
tau_rhsatt_payment_4 -2.18494 0.058557 -37.313 0.179128 -12.1977
tau_rhsatt_payment_5 -0.20694 0.044404 -4.660 0.170015 -1.2172
tau_rhsatt_payment_6 4.13437 0.106865 38.688 0.258289 16.0068
tau_rhsatt_trust_1 -7.89241 0.351857 -22.431 0.486134 -16.2350
tau_rhsatt_trust_2 -4.92955 0.136304 -36.166 0.239513 -20.5816
tau_rhsatt_trust_3 -3.91755 0.096652 -40.533 0.218588 -17.9220
tau_rhsatt_trust_4 -1.53729 0.050289 -30.569 0.163256 -9.4165
tau_rhsatt_trust_5 0.15224 0.049807 3.057 0.118548 1.2842
tau_rhsatt_trust_6 4.56511 0.117034 39.007 0.241992 18.8648
mu_pf 1.43086 0.056888 25.152 0.093594 15.2879
mu_ps 1.11410 0.041466 26.868 0.232951 4.7826
mu_fc 1.00000 NA NA NA NA