Important: Read this before posting to this forum

  1. 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.
  2. 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
  3. Before asking a question on the forum, users are kindly requested to follow these steps:
    1. Check that the same issue has not already been addressed in the forum - there is a search tool.
    2. 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
    3. Check the frequently asked questions section on the Apollo website, which discusses some common issues/failures. Please see http://www.apollochoicemodelling.com/faq.html
    4. Make sure that R is using the latest official release of Apollo.
  4. If the above steps do not resolve the issue, then users should follow these steps when posting a question:
    1. provide full details on the issue, including the entire code and output, including any error messages
    2. posts will not immediately appear on the forum, but will be checked by a moderator first. This may take a day or two at busy times. There is no need to submit the post multiple times.

Error in estimating model with Joint RP-SP and HCM

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
Post Reply
Aditya249
Posts: 11
Joined: 27 Jan 2023, 08:47

Error in estimating model with Joint RP-SP and HCM

Post by Aditya249 »

Dear Sir,

I would like to use the Hybrid choice model with RP/SP data. For this purpose, I have added four items (Likert scale 1 to 5) to the default mode-choice data provided in the manual workbook. The four items (AT_a, AT_b, SN_a, and SN_b) will be used to form two latent variables. Considering this I have framed the code attached below.

However, I am getting this error during model estimation
Error in apollo_mnl(mnl_settings_SP, functionality) :
Duplicated componentName found (MNL). Names must be different for each component.


I have the following request from you:
1. Please suggest if it is possible to integrate the hybrid choice model with the Joint RP/SP model in Apollo?
2. If yes, then please suggest if my code is correct. If not then how can I fix it?

# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS ####
# ################################################################# #

### Clear memory
rm(list = ls())

### Load Apollo library
library(apollo)

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
modelName = "RP_SP_HCM",
modelDescr = "RP-SP_HCM model on mode choice data",
indivID = "ID",
outputDirectory = "Output_RP_SP_HCM"
)

# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #

database = read.csv("RP_SP_HCM.csv")

# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(asc_car = 0,
asc_bus = 0,
asc_air = 0,
asc_rail = 0,
b_tt_car = 0,
b_tt_bus = 0,
b_tt_air = 0,
b_tt_rail = 0,
b_access_bus = 0,
b_access_rail = 0,
b_access_air = 0,
b_cost_car = 0,
b_cost_bus = 0,
b_cost_air = 0,
b_cost_rail = 0,
b_income = 0,
b_female = 0,
b_no_frills = 0,
b_wifi = 0,
b_food = 0,
lamda_AT = 1,
lamda_SN = 1,
zeta_AT_a = 1,
zeta_AT_b = 1,
zeta_SN_a = 1,
zeta_SN_b = 1,
tau__AT_a_1 =-2,
tau__AT_a_2 =-1,
tau__AT_a_3 = 1,
tau__AT_a_4 = 2,
tau__AT_b_1 =-2,
tau__AT_b_2 =-1,
tau__AT_b_3 = 1,
tau__AT_b_4 = 2,
tau__SN_a_1 =-2,
tau__SN_a_2 =-1,
tau__SN_a_3 = 1,
tau__SN_a_4 = 2,
tau__SN_b_1 =-2,
tau__SN_b_2 =-1,
tau__SN_b_3 = 1,
tau__SN_b_4 = 2,
mu_RP = 1,
mu_SP = 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_RP")

# ################################################################# #
#### DEFINE RANDOM COMPONENTS ####
# ################################################################# #

### Set parameters for generating draws
apollo_draws = list(
interDrawsType="halton",
interNDraws=100,
interUnifDraws=c(),
interNormDraws=c("eta_AT","eta_SN"),

intraDrawsType="",
intraNDraws=0,
intraUnifDraws=c(),
intraNormDraws=c()
)

### Create random parameters
apollo_randCoeff=function(apollo_beta, apollo_inputs){
randcoeff = list()

randcoeff[["LV_AT"]] = b_tt_car*time_car + b_tt_bus*time_bus + b_tt_air*time_air + b_tt_rail*time_rail + b_access_bus*access_bus + b_access_rail*access_rail + b_income*income + b_no_frills * ( service_air == 1 ) + b_wifi * ( service_air == 2 ) + b_food * ( service_air == 3 ) + b_female * female + eta_AT

randcoeff[["LV_SN"]] = b_tt_car*time_car + b_tt_bus*time_bus + b_tt_air*time_air + b_tt_rail*time_rail + b_access_bus*access_bus + b_access_rail*access_rail + b_income*income + b_no_frills * ( service_air == 1 ) + b_wifi * ( service_air == 2 ) + b_food * ( service_air == 3 ) + b_female * female + eta_SN

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 = AT_a,
V = zeta_AT_a*LV_AT,
tau = list(tau__AT_a_1, tau__AT_a_2, tau__AT_a_3, tau__AT_a_4),
rows = (task==1),
componentName = "indic_AT_a")

ol_settings2 = list(outcomeOrdered = AT_b,
V = zeta_AT_b*LV_AT,
tau = list(tau__AT_b_1, tau__AT_b_2, tau__AT_b_3, tau__AT_b_4),
rows = (task==1),
componentName = "indic_AT_b")

ol_settings3 = list(outcomeOrdered = SN_a,
V = zeta_SN_a*LV_SN,
tau = list(tau__SN_a_1, tau__SN_a_2, tau__SN_a_3, tau__SN_a_4),
rows = (task==1),
componentName = "indic_SN_a")

ol_settings4 = list(outcomeOrdered = SN_b,
V = zeta_SN_b*LV_SN,
tau = list(tau__SN_b_1, tau__SN_b_2, tau__SN_b_3, tau__SN_b_4),
rows = (task==1),
componentName = "indic_SN_b")

P[["indic_AT_a"]] = apollo_ol(ol_settings1, functionality)
P[["indic_AT_b"]] = apollo_ol(ol_settings2, functionality)
P[["indic_SN_a"]] = apollo_ol(ol_settings3, functionality)
P[["indic_SN_b"]] = apollo_ol(ol_settings4, 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_tt_car * time_car + b_cost_car * cost_car + b_income * income + b_female * female + lamda_AT * LV_AT + lamda_SN * LV_SN

V[["bus"]] = asc_bus + b_tt_bus * time_bus + b_cost_bus * cost_bus + b_income * income + b_access_bus * access_bus + b_female * female + lamda_AT * LV_AT + lamda_SN * LV_SN

V[["air"]] = asc_air + b_tt_air * time_air + b_cost_air * cost_air + b_income * income + b_access_air * access_air + b_female * female + lamda_AT * LV_AT + lamda_SN * LV_SN + b_no_frills * ( service_air == 1 ) + b_wifi * ( service_air == 2 ) + b_food * ( service_air == 3 )

V[["rail"]] = asc_rail + b_tt_rail * time_rail + b_cost_rail * cost_rail + b_income*income + b_access_rail*access_rail + b_female*female + lamda_AT * LV_AT + lamda_SN*LV_SN + b_no_frills * ( service_air == 1 ) + b_wifi * ( service_air == 2 ) + b_food * ( service_air == 3 )



### Compute probabilities for the RP part of the data using MNL model
mnl_settings_RP = list(
alternatives = c(car=1, bus=2, air=3, rail=4),
avail = list(car=av_car, bus=av_bus, air=av_air, rail=av_rail),
choiceVar = choice,
utilities = list(car = mu_RP*V[["car"]],
bus = mu_RP*V[["bus"]],
air = mu_RP*V[["air"]],
rail = mu_RP*V[["rail"]]),
rows = (RP==1)
)

P[["RP"]] = apollo_mnl(mnl_settings_RP, functionality)

### Compute probabilities for the SP part of the data using MNL model
mnl_settings_SP = list(
alternatives = c(car=1, bus=2, air=3, rail=4),
avail = list(car=av_car, bus=av_bus, air=av_air, rail=av_rail),
choiceVar = choice,
utilities = list(car = mu_SP*V[["car"]],
bus = mu_SP*V[["bus"]],
air = mu_SP*V[["air"]],
rail = mu_SP*V[["rail"]]),
rows = (SP==1)
)

P[["SP"]] = apollo_mnl(mnl_settings_SP, 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 ####
# ################################################################# #

model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)

# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #

# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #

apollo_modelOutput(Output_RP_SP_HCM)


Thanking you in advance,
Aditya
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Error in estimating model with Joint RP-SP and HCM

Post by stephanehess »

Hi

can you please confirm that you are using the newest version of Apollo as this could be an old error message

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Aditya249
Posts: 11
Joined: 27 Jan 2023, 08:47

Re: Error in estimating model with Joint RP-SP and HCM

Post by Aditya249 »

Thank you Prof. Hess for your swift response.

Currently, I am using apollo version 0.2.8.

Additionally, I would also like to bring to your notice that I have been working on improving this code and rectifying the problem since the time I requested your help. Based on the FAQ page and Forum queries I have modified the code and now it does not show the same problem, instead, it shows an error after calculating the Initial function value; iterations, and final LL Value. The results and errors are attached below the code . Please suggest if I can share the dataset with you over mail.

The revised code is as follows:

Code: Select all

# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS                       ####
# ################################################################# #

### Clear memory
rm(list = ls())

### Load Apollo library
library(apollo)

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
  modelName       = "RP_SP_HCM",
  modelDescr      = "RP-SP_HCM model on mode choice data",
  indivID         = "ID", 
  mixing          = TRUE,
  nCores          = 1,
  outputDirectory = "output",
  workInLogs      = TRUE
)

# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS                     ####
# ################################################################# #

database = read.csv("RP_SP_HCM.csv")

# ################################################################# #
#### DEFINE MODEL PARAMETERS                                     ####
# ################################################################# #

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(asc_car                 = 0,
              asc_bus                 = 0,
              asc_air                 = 0,
              asc_rail                = 0,
              b_tt_car                = 0,
              b_tt_bus                = 0,
              b_tt_air                = 0,
              b_tt_rail               = 0,
              b_access_bus            = 0,
              b_access_rail           = 0,
              b_access_air            = 0,
              b_cost_car              = 0,
              b_cost_bus              = 0,
              b_cost_air              = 0,
              b_cost_rail             = 0, 
              b_income                = 0,
              b_female                = 0,
              b_no_frills             = 0,
              b_wifi                  = 0,
              b_food                  = 0,
              lambda_AT               = 1,
              lambda_SN               = 1,
              zeta_AT_a               = 1,
              zeta_AT_b               = 1,
              zeta_SN_a               = 1,
              zeta_SN_b               = 1,
              tau__AT_a_1             =-2,
              tau__AT_a_2             =-1,
              tau__AT_a_3             = 1,
              tau__AT_a_4             = 2,
              tau__AT_b_1             =-2,
              tau__AT_b_2             =-1,
              tau__AT_b_3             = 1,
              tau__AT_b_4             = 2,
              tau__SN_a_1             =-2,
              tau__SN_a_2             =-1,
              tau__SN_a_3             = 1,
              tau__SN_a_4             = 2,
              tau__SN_b_1             =-2,
              tau__SN_b_2             =-1,
              tau__SN_b_3             = 1,
              tau__SN_b_4             = 2,
              mu_RP                   = 1,
              mu_SP                   = 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_RP")

# ################################################################# #
#### DEFINE RANDOM COMPONENTS                                    ####
# ################################################################# #

### Set parameters for generating draws
apollo_draws = list(
  interDrawsType="halton", 
  interNDraws=100,          
  interUnifDraws=c(),      
  interNormDraws=c("eta_AT","eta_SN"), 
  
  intraDrawsType="",
  intraNDraws=0,          
  intraUnifDraws=c(),     
  intraNormDraws=c()      
)

### Create random parameters
apollo_randCoeff=function(apollo_beta, apollo_inputs){
  randcoeff = list()

randcoeff[["LV_AT"]] = b_tt_car*time_car +  b_tt_bus*time_bus + b_tt_air*time_air + b_tt_rail*time_rail + b_access_bus*access_bus + b_access_rail*access_rail + b_income*income +      + eta_AT 

randcoeff[["LV_SN"]] = b_tt_car*time_car +  b_tt_bus*time_bus + b_tt_air*time_air + b_tt_rail*time_rail + b_access_bus*access_bus + b_access_rail*access_rail + b_income*income + +  b_female * female + eta_SN 
  
  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 = AT_a,
                          V              = zeta_AT_a*LV_AT,
                          tau            = list(tau__AT_a_1, tau__AT_a_2, tau__AT_a_3, tau__AT_a_4),
                          rows           = (task==1),
                          componentName  = "indic_AT_a")

      ol_settings2 = list(outcomeOrdered = AT_b,
                          V              = zeta_AT_b*LV_AT,
                          tau            = list(tau__AT_b_1, tau__AT_b_2, tau__AT_b_3, tau__AT_b_4),
                          rows           = (task==1),
                          componentName  = "indic_AT_b")

      ol_settings3 = list(outcomeOrdered = SN_a,
                          V              = zeta_SN_a*LV_SN,
                          tau            = list(tau__SN_a_1, tau__SN_a_2, tau__SN_a_3, tau__SN_a_4),
                          rows           = (task==1),
                          componentName  = "indic_SN_a")

      ol_settings4 = list(outcomeOrdered = SN_b,
                          V              = zeta_SN_b*LV_SN,
                          tau            = list(tau__SN_b_1, tau__SN_b_2, tau__SN_b_3, tau__SN_b_4),
                          rows           = (task==1),
                          componentName  = "indic_SN_b")
    
     P[["indic_AT_a"]]                   = apollo_ol(ol_settings1, functionality)
     P[["indic_AT_b"]]                   = apollo_ol(ol_settings2, functionality)
     P[["indic_SN_a"]]                   = apollo_ol(ol_settings3, functionality)
     P[["indic_SN_b"]]                   = apollo_ol(ol_settings4, 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_tt_car * time_car + b_cost_car * cost_car +  b_income * income + b_female * female + lambda_AT * LV_AT + lambda_SN * LV_SN) 
 
V[["bus"]]  = (asc_bus + b_tt_bus * time_bus + b_cost_bus * cost_bus +  b_income * income + b_access_bus * access_bus + b_female * female +  lambda_AT * LV_AT + lambda_SN * LV_SN) 

V[["air"]]  = asc_air + b_tt_air * time_air + b_cost_air * cost_air +  b_income * income + b_access_air * access_air + b_female * female +  lambda_SN * LV_SN +                    b_no_frills * ( service_air == 1 )  + b_wifi * ( service_air == 2 )  + b_food * ( service_air == 3 )

V[["rail"]] =  asc_rail + b_tt_rail * time_rail + b_cost_rail * cost_rail +  b_income*income + b_access_rail*access_rail + b_female*female  + b_no_frills * ( service_air == 1 )  +     b_wifi * ( service_air == 2 )  + b_food * ( service_air == 3) 



### Compute probabilities for the RP part of the data using MNL model
  mnl_settings_RP = list(
       alternatives  = c(car=1, bus=2, air=3, rail=4), 
       avail         = list(car=av_car, bus=av_bus, air=av_air, rail=av_rail), 
       choiceVar     = choice, 
       utilities     = list(car  = mu_RP*V[["car"]],
                            bus  = mu_RP*V[["bus"]],
                            air  = mu_RP*V[["air"]],
                            rail = mu_RP*V[["rail"]]),
       rows          = (RP==1)
  )
  
  P[["RP"]] = apollo_mnl(mnl_settings_RP, functionality)

  ### Compute probabilities for the SP part of the data using MNL model
  mnl_settings_SP = list(
       alternatives  = c(car=1, bus=2, air=3, rail=4), 
       avail         = list(car=av_car, bus=av_bus, air=av_air, rail=av_rail), 
       choiceVar     = choice, 
       utilities     = list(car  = mu_SP*V[["car"]],
                            bus  = mu_SP*V[["bus"]],
                            air  = mu_SP*V[["air"]],
                            rail = mu_SP*V[["rail"]]),
       rows          = (SP==1)
  )
  
  P[["SP"]] = apollo_mnl(mnl_settings_SP, 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                                            ####
# ################################################################# #

model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)


######## OR USE THIS CODE IN THE CASE OF COVERGENCE ISSUE, RUN IT TWICE FOR JOINT RP-SP & HCM  MODEL ########

apollo_estimate(
  apollo_beta,
  apollo_fixed,
  apollo_probabilities,
  apollo_inputs,
  estimate_settings = list(scaleAfterConvergence=FALSE))



# ################################################################# #
#### MODEL OUTPUTS                                               ####
# ################################################################# #

# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN)                               ----
# ----------------------------------------------------------------- #

apollo_modelOutput(Output_RP_SP_HCM)  



Here is the output and Error message


Code: Select all

########################################################################################################################################
WARNING: You can use multiple processor cores to speed up estimation. To do so, specify the desired number of cores using
  the setting nCores inside "apollo_control", for example "nCores=2". This computer has 12 available cores. We recommend
  using no more than 11 cores.

... current process will resume in 5 seconds unless interrupted by the user
########################################################################################################################################
Preparing user-defined functions.
CAUTION: In models using mixing and workInLogs=TRUE, Apollo assumes (and does not check) that the call to apollo_panelProd
  is immediately followed by a call to apollo_avgInterDraws.

Testing likelihood function...
No coding provided for Ordered model component "indic_AT_a", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for model component indic_AT_a:
                              1     2     3     4     5
Times chosen               7.00 10.00 11.00 11.00 12.00
Percentage chosen overall 13.73 19.61 21.57 21.57 23.53
No coding provided for Ordered model component "indic_AT_b", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for model component indic_AT_b:
                              1     2     3     4     5
Times chosen              12.00  9.00 15.00  7.00  8.00
Percentage chosen overall 23.53 17.65 29.41 13.73 15.69
No coding provided for Ordered model component "indic_SN_a", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for model component indic_SN_a:
                              1     2     3     4     5
Times chosen              10.00 13.00 16.00  6.00  6.00
Percentage chosen overall 19.61 25.49 31.37 11.76 11.76
No coding provided for Ordered model component "indic_SN_b", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for model component indic_SN_b:
                              1     2     3     4     5
Times chosen              18.00  8.00 11.00  6.00  8.00
Percentage chosen overall 35.29 15.69 21.57 11.76 15.69
Apollo found a model component of type MNL without a componentName. The name was set to "RP" by default.

Overview of choices for MNL model component RP:
                                   car   bus   air   rail
Times available                  60.00 84.00 80.00 102.00
Times chosen                     23.00 16.00 27.00  36.00
Percentage chosen overall        22.55 15.69 26.47  35.29
Percentage chosen when available 38.33 19.05 33.75  35.29
Apollo found a model component of type MNL without a componentName. The name was set to "SP" by default.

Overview of choices for MNL model component SP:
                                    car    bus    air   rail
Times available                  420.00 588.00 558.00 712.00
Times chosen                     108.00  40.00 155.00 409.00
Percentage chosen overall         15.17   5.62  21.77  57.44
Percentage chosen when available  25.71   6.80  27.78  57.44

Pre-processing likelihood function...

Testing influence of parameters..........................................
Starting main estimation
Initial function value: -1177.429 
Initial gradient value:
      asc_bus       asc_air      asc_rail      b_tt_car      b_tt_bus      b_tt_air     b_tt_rail  b_access_bus b_access_rail 
-6.929443e+01  7.111378e+00  2.889264e+01 -8.302123e+02 -4.284124e+04 -2.270145e+03 -4.370621e+03 -2.281198e+03 -1.693426e+02 
 b_access_air    b_cost_car    b_cost_bus    b_cost_air   b_cost_rail      b_income      b_female   b_no_frills        b_wifi 
 3.939544e+02  1.218952e+03 -1.761754e+03 -1.776782e+03 -2.096749e+02 -2.567380e+06 -1.134112e+01  1.790485e+01  6.203801e+00 
       b_food     lambda_AT     lambda_SN     zeta_AT_a     zeta_AT_b     zeta_SN_a     zeta_SN_b   tau__AT_a_1   tau__AT_a_2 
 1.017873e+01  1.605598e+01 -4.513952e+00 -8.189908e+00 -5.126836e+00  1.115041e-03  6.797534e+00 -3.169224e+00  5.715075e+00 
  tau__AT_a_3   tau__AT_a_4   tau__AT_b_1   tau__AT_b_2   tau__AT_b_3   tau__AT_b_4   tau__SN_a_1   tau__SN_a_2   tau__SN_a_3 
-1.037801e+01 -2.834771e+00  1.259307e+00  2.532360e+00 -3.057095e+00 -2.071682e+00 -3.545065e+00  6.475458e+00 -2.060020e+00 
  tau__SN_a_4   tau__SN_b_1   tau__SN_b_2   tau__SN_b_3   tau__SN_b_4         mu_SP 
-1.044190e+00  6.335850e+00  3.534641e+00 -3.736178e+00 -2.660174e+00  2.844365e+01 
initial  value 1177.429119 
iter   2 value 1164.350772
iter   3 value 1141.102812
iter   4 value 1133.699270
iter   5 value 1090.863176
iter   6 value 1076.196778
iter   7 value 1074.657402
iter   8 value 1071.689647
iter   9 value 1064.196125
iter  10 value 1058.502224
iter  11 value 1056.441064
iter  12 value 1055.918081
iter  13 value 1044.633223
iter  14 value 1044.100550
iter  15 value 1023.250076
iter  16 value 999.871397
iter  17 value 991.442889
iter  18 value 984.501958
iter  19 value 980.045232
iter  20 value 977.929050
iter  21 value 975.138906
iter  22 value 971.455012
iter  23 value 967.647625
iter  24 value 964.847400
iter  25 value 962.543882
iter  26 value 961.430727
iter  27 value 958.882173
iter  28 value 957.908083
iter  29 value 956.995298
iter  30 value 956.137024
iter  31 value 955.104016
iter  32 value 953.468998
iter  33 value 952.380348
iter  34 value 949.809410
iter  35 value 949.676445
iter  36 value 948.548963
iter  37 value 945.459638
iter  38 value 943.274193
iter  39 value 940.964828
iter  40 value 939.385435
iter  41 value 938.207865
iter  42 value 937.437214
iter  43 value 936.589021
iter  44 value 935.843564
iter  45 value 934.955162
iter  46 value 934.453212
iter  47 value 933.913620
iter  48 value 933.479792
iter  49 value 932.361072
iter  50 value 931.500836
iter  51 value 930.496923
iter  52 value 929.817153
iter  53 value 929.114629
iter  54 value 928.048305
iter  55 value 927.489065
iter  56 value 927.058299
iter  57 value 926.372616
iter  58 value 925.618592
iter  59 value 924.853274
iter  60 value 924.465544
iter  61 value 924.051068
iter  62 value 923.435861
iter  63 value 923.021245
iter  64 value 922.578136
iter  65 value 922.082606
iter  66 value 921.540059
iter  67 value 921.250872
iter  68 value 920.936561
iter  69 value 920.710342
iter  70 value 920.539499
iter  71 value 920.407961
iter  72 value 920.293413
iter  73 value 920.166001
iter  74 value 920.027700
iter  75 value 919.945453
iter  76 value 919.882752
iter  77 value 919.831718
iter  78 value 919.765539
iter  79 value 919.760701
iter  80 value 919.693814
iter  81 value 919.681836
iter  82 value 919.635899
iter  83 value 919.613942
iter  84 value 919.555363
iter  85 value 919.548115
iter  86 value 919.509084
iter  87 value 919.508770
iter  88 value 919.508690
iter  89 value 919.508643
iter  90 value 919.508522
iter  91 value 919.508490
iter  92 value 919.505855
iter  93 value 919.505533
iter  94 value 919.505059
iter  95 value 919.504999
iter  96 value 919.504936
iter  97 value 919.504921
iter  98 value 919.504636
iter  99 value 919.504556
iter 100 value 919.504262
iter 101 value 919.502575
iter 102 value 919.501264
iter 103 value 919.499223
iter 104 value 919.497066
iter 105 value 919.495368
iter 106 value 919.486673
iter 107 value 919.486367
iter 108 value 919.478079
iter 109 value 919.473227
iter 110 value 919.468876
iter 111 value 919.459517
iter 112 value 919.456936
iter 113 value 919.454427
iter 114 value 919.453615
iter 115 value 919.448191
iter 116 value 919.443807
iter 117 value 919.441677
iter 118 value 919.437370
iter 119 value 919.433070
iter 120 value 919.426737
iter 121 value 919.419274
iter 122 value 919.413022
iter 123 value 919.392066
iter 124 value 919.377918
iter 125 value 919.370206
iter 126 value 919.358445
iter 127 value 919.354457
iter 128 value 919.351813
iter 129 value 919.351143
iter 130 value 919.350336
iter 131 value 919.348662
iter 132 value 919.345171
iter 133 value 919.338290
iter 134 value 919.325352
iter 135 value 919.302563
iter 136 value 919.263459
iter 137 value 919.191880
iter 138 value 919.068695
iter 139 value 919.012157
iter 140 value 918.846565
iter 141 value 918.824697
iter 142 value 918.694590
iter 143 value 918.677389
iter 144 value 918.586892
iter 145 value 918.535650
iter 146 value 918.484861
iter 147 value 918.448481
iter 148 value 918.420456
iter 149 value 918.400118
iter 150 value 918.359767
iter 150 value 918.359767
final  value 918.359767 
converged
Additional convergence test using scaled estimation. Parameters will be scaled by their current estimates and additional
  iterations will be performed.
initial  value 918.359767 
iter   2 value 918.324269
iter   3 value 918.321573
iter   4 value 918.288807
iter   5 value 918.287186
iter   6 value 918.286414
iter   7 value 918.280661
iter   8 value 918.271895
iter   9 value 918.270615
iter  10 value 918.268949
iter  11 value 918.262892
iter  12 value 918.256642
iter  13 value 918.252010
iter  14 value 918.244871
iter  15 value 918.242613
iter  16 value 918.240188
iter  17 value 918.236981
iter  18 value 918.225863
iter  19 value 918.220143
iter  20 value 918.206828
iter  21 value 918.181921
iter  22 value 918.177813
iter  23 value 918.167507
iter  24 value 918.164401
iter  25 value 918.154202
iter  26 value 918.132895
iter  27 value 918.126159
iter  28 value 918.086205
iter  29 value 918.046699
iter  30 value 918.025666
iter  31 value 918.003741
iter  32 value 917.973014
iter  33 value 917.964965
iter  34 value 917.933753
iter  35 value 917.912360
iter  36 value 917.898590
iter  37 value 917.871304
iter  38 value 917.852744
iter  39 value 917.827127
iter  40 value 917.811914
iter  41 value 917.791563
iter  42 value 917.783951
iter  43 value 917.770186
iter  44 value 917.747218
iter  45 value 917.720222
iter  46 value 917.708428
iter  47 value 917.687265
iter  48 value 917.680419
iter  49 value 917.673121
iter  50 value 917.666586
iter  51 value 917.662257
iter  52 value 917.656832
iter  53 value 917.650461
iter  54 value 917.647312
iter  55 value 917.638831
iter  56 value 917.635134
iter  57 value 917.627182
iter  58 value 917.622468
iter  59 value 917.612676
iter  60 value 917.611325
iter  61 value 917.601791
iter  62 value 917.597390
iter  63 value 917.593545
iter  64 value 917.590250
iter  65 value 917.587543
iter  66 value 917.585090
iter  67 value 917.582015
iter  68 value 917.578304
iter  69 value 917.573543
iter  70 value 917.573018
iter  71 value 917.571666
iter  72 value 917.568429
iter  73 value 917.568272
iter  74 value 917.566578
iter  75 value 917.566176
iter  76 value 917.565507
iter  77 value 917.564949
iter  78 value 917.564149
iter  79 value 917.563221
iter  80 value 917.562821
iter  81 value 917.561664
iter  82 value 917.561111
iter  83 value 917.559913
iter  84 value 917.559374
iter  85 value 917.558762
iter  86 value 917.558597
iter  87 value 917.558499
iter  88 value 917.558147
iter  89 value 917.557864
iter  90 value 917.557671
iter  91 value 917.557639
iter  92 value 917.557613
iter  93 value 917.557598
iter  94 value 917.557507
iter  95 value 917.557449
iter  96 value 917.556834
iter  97 value 917.556761
iter  98 value 917.556610
iter  99 value 917.556476
iter 100 value 917.555486
iter 101 value 917.553013
iter 102 value 917.552984
iter 103 value 917.552443
iter 104 value 917.552214
iter 105 value 917.551746
iter 106 value 917.551444
iter 107 value 917.551317
iter 108 value 917.551273
iter 109 value 917.551041
iter 110 value 917.549379
iter 111 value 917.548954
iter 112 value 917.548794
iter 113 value 917.548779
iter 114 value 917.548565
iter 115 value 917.548191
iter 116 value 917.547787
iter 117 value 917.547580
iter 118 value 917.546719
iter 119 value 917.546116
iter 120 value 917.545307
iter 121 value 917.544960
iter 122 value 917.544290
iter 123 value 917.543199
iter 124 value 917.542558
iter 125 value 917.541923
iter 126 value 917.540288
iter 127 value 917.539947
iter 128 value 917.539495
iter 129 value 917.539057
iter 130 value 917.538466
iter 131 value 917.538188
iter 132 value 917.537797
iter 133 value 917.536895
iter 134 value 917.536083
iter 135 value 917.534847
iter 136 value 917.534542
iter 137 value 917.534259
iter 138 value 917.533793
iter 139 value 917.533290
iter 140 value 917.532970
iter 141 value 917.532726
iter 142 value 917.532541
iter 143 value 917.532187
iter 144 value 917.531812
iter 145 value 917.530926
iter 146 value 917.530764
iter 147 value 917.530036
iter 148 value 917.529543
iter 149 value 917.529253
iter 150 value 917.528846
iter 151 value 917.528581
iter 152 value 917.528278
iter 153 value 917.528112
iter 154 value 917.527912
iter 155 value 917.527834
iter 156 value 917.527779
iter 157 value 917.527684
iter 158 value 917.527648
iter 159 value 917.527593
iter 160 value 917.527541
iter 161 value 917.527491
iter 162 value 917.527468
iter 163 value 917.527409
iter 164 value 917.527378
iter 164 value 917.527367
iter 164 value 917.527366
final  value 917.527366 
converged
Estimated parameters:
                 Estimate
asc_car          0.000000
asc_bus         -0.071376
asc_air          0.721388
asc_rail        -0.217514
b_tt_car        -0.001567
b_tt_bus        -0.002062
b_tt_air        -0.005252
b_tt_rail     -2.4879e-04
b_access_bus    -0.009036
b_access_rail   -0.002977
b_access_air    -0.012332
b_cost_car      -0.011399
b_cost_bus      -0.010961
b_cost_air      -0.012187
b_cost_rail     -0.012015
b_income       -9.370e-06
b_female         0.162307
b_no_frills     -0.034673
b_wifi          -0.151997
b_food          -0.160192
lambda_AT        0.152079
lambda_SN       -0.025653
zeta_AT_a       -0.798684
zeta_AT_b       -0.654671
zeta_SN_a      -2.324e+04
zeta_SN_b       -2.375898
tau__AT_a_1     -0.692532
tau__AT_a_2      0.625287
tau__AT_a_3      1.685463
tau__AT_a_4      2.797474
tau__AT_b_1     -0.157780
tau__AT_b_2      0.729656
tau__AT_b_3      2.116988
tau__AT_b_4      3.008227
tau__SN_a_1     2.141e+04
tau__SN_a_2     3.703e+04
tau__SN_a_3     5.845e+04
tau__SN_a_4     7.351e+04
tau__SN_b_1      2.991696
tau__SN_b_2      4.004819
tau__SN_b_3      5.764644
tau__SN_b_4      7.375376
mu_RP            1.000000
mu_SP            5.962946

Final LL: -917.5274

Calculating log-likelihood at equal shares (LL(0)) for applicable models...
Calculating log-likelihood at observed shares from estimation data (LL(c)) for applicable models...
Calculating LL of each model component...
Calculating other model fit measures
Your model took more than 10 minutes to estimate, so it was saved to file output/RP_SP_HCM_model.rds before calculating
  its covariance matrix. If calculation of the covariance matrix fails or is stopped before finishing, you can load the
  model up to this point using apollo_loadModel.

Computing covariance matrix using numerical methods (numDeriv).
 0%....25%....50%....75%....100%

[b]ERROR: Singular Hessian, cannot calculate s.e.
Hessian written to output/RP_SP_HCM_hessian.csv
WARNING: Some eigenvalues of the Hessian are positive, indicating convergence to a saddle point!
Computing score matrix...
There were 50 or more warnings (use warnings() to see the first 50) [/b]      
Sir, I would request you to suggest
(i) If my approach correct to estimate such a model? If yes then how can I fix this code and get model fit indices
(ii) Using the same dataset, I am also planning to add two random variables for estimating mixed logit model with RP-SP data and HCM. Is it advisable to do so?
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Error in estimating model with Joint RP-SP and HCM

Post by stephanehess »

Hi

this is not an error. It is only a warning message telling you about convergence issues. So next look at your model results

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Aditya249
Posts: 11
Joined: 27 Jan 2023, 08:47

Re: Error in estimating model with Joint RP-SP and HCM

Post by Aditya249 »

Okay Sir,

Sorry to bother you again, but it shows ERROR: Singular Hessian, cannot calculate s.e. and after this I am not getting any results for indices (rho square, robust t stat, etc.). Is it the issue with the coding part or the data? How can I resolve it?
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Error in estimating model with Joint RP-SP and HCM

Post by stephanehess »

Hi

your model is clearly not identified, see e.g.

tau__SN_a_1 2.141e+04
tau__SN_a_2 3.703e+04
tau__SN_a_3 5.845e+04
tau__SN_a_4 7.351e+04

But what exactly are you trying to do here. You are putting the attributes of the car alternative into the LVs and you putting those LVs into the utility functions. That makes no sense

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Aditya249
Posts: 11
Joined: 27 Jan 2023, 08:47

Re: Error in estimating model with Joint RP-SP and HCM

Post by Aditya249 »

Thank you Prof. Hess for highlighting this silly mistake on my end. Sincere apologies.

I have revised the code and modified the attributes to be used with LVs and utility functions. The results are much better now.

I request you to please suggest if the codes are fine now.

Please find the attached code

Code: Select all

# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS                       ####
# ################################################################# #

### Clear memory
rm(list = ls())

### Load Apollo library
library(apollo)

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
  modelName       = "RP_SP_HCM",
  modelDescr      = "RP-SP_HCM model on mode choice data",
  indivID         = "ID", 
  mixing          = TRUE,
  nCores          = 1,
  outputDirectory = "output",
)

# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS                     ####
# ################################################################# #

database = read.csv("RP_SP_HCM.csv")

# ################################################################# #
#### DEFINE MODEL PARAMETERS                                     ####
# ################################################################# #

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(asc_car         = 0,
              asc_bus                 = 0,
              asc_air                  = 0,
              asc_rail                 = 0,
              b_tt_car                = 0,
              b_tt_bus                = 0,
              b_tt_air                 = 0,
              b_tt_rail                = 0,
              b_access_bus         = 0,
              b_access_rail         = 0,
              b_access_air          = 0,
              b_cost_car             = 0,
              b_cost_bus             = 0,
              b_cost_air              = 0,
              b_cost_rail             = 0,
              b_female_car         = 0,
              b_female_bus         = 0,
              b_business_air        = 0,
              b_business_rail       = 0,
              b_no_frills              = 0,
              b_wifi                     = 0,
              b_food                    = 0,
              AT_gamma_female         = 0,
              SN_gamma_female         = 0,
              AT_gamma_business       = 0,
              SN_gamma_business       = 0,
              lambda_AT               = 1,
              lambda_SN               = 1,
              zeta_AT_a               = 1,
              zeta_AT_b               = 1,
              zeta_SN_a               = 1,
              zeta_SN_b               = 1,
              tau__AT_a_1             =-2,
              tau__AT_a_2             =-1, 
              tau__AT_a_3             = 1,
              tau__AT_a_4             = 2,
              tau__AT_b_1             =-2,
              tau__AT_b_2             =-1,
              tau__AT_b_3             = 1,
              tau__AT_b_4             = 2,
              tau__SN_a_1             =-2,
              tau__SN_a_2             =-1,
              tau__SN_a_3             = 1,
              tau__SN_a_4             = 2,
              tau__SN_b_1             =-2,
              tau__SN_b_2             =-1,
              tau__SN_b_3             = 1,
              tau__SN_b_4             = 2,
              mu_RP                   = 1,
              mu_SP                   = 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_RP")

# ################################################################# #
#### DEFINE RANDOM COMPONENTS                                    ####
# ################################################################# #

### Set parameters for generating draws
apollo_draws = list(
  interDrawsType="halton", 
  interNDraws=100,          
  interUnifDraws=c(),      
  interNormDraws=c("eta_AT","eta_SN"), 
  
  intraDrawsType="",
  intraNDraws=0,          
  intraUnifDraws=c(),     
  intraNormDraws=c()      
)

### Create random parameters
apollo_randCoeff=function(apollo_beta, apollo_inputs){
  randcoeff = list()

randcoeff[["LV_AT"]] = AT_gamma_female*female  + AT_gamma_business*business + eta_AT 

randcoeff[["LV_SN"]] = SN_gamma_female*female  + SN_gamma_business*business + eta_SN 
  
  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 = AT_a,
                          V              = zeta_AT_a*LV_AT,
                          tau            = list(tau__AT_a_1, tau__AT_a_2, tau__AT_a_3, tau__AT_a_4),
                          rows           = (task==1),
                          componentName  = "indic_AT_a")

      ol_settings2 = list(outcomeOrdered = AT_b,
                          V              = zeta_AT_b*LV_AT,
                          tau            = list(tau__AT_b_1, tau__AT_b_2, tau__AT_b_3, tau__AT_b_4),
                          rows           = (task==1),
                          componentName  = "indic_AT_b")

      ol_settings3 = list(outcomeOrdered = SN_a,
                          V              = zeta_SN_a*LV_SN,
                          tau            = list(tau__SN_a_1, tau__SN_a_2, tau__SN_a_3, tau__SN_a_4),
                          rows           = (task==1),
                          componentName  = "indic_SN_a")

      ol_settings4 = list(outcomeOrdered = SN_b,
                          V              = zeta_SN_b*LV_SN,
                          tau            = list(tau__SN_b_1, tau__SN_b_2, tau__SN_b_3, tau__SN_b_4),
                          rows           = (task==1),
                          componentName  = "indic_SN_b")
    
     P[["indic_AT_a"]]                   = apollo_ol(ol_settings1, functionality)
     P[["indic_AT_b"]]                   = apollo_ol(ol_settings2, functionality)
     P[["indic_SN_a"]]                   = apollo_ol(ol_settings3, functionality)
     P[["indic_SN_b"]]                   = apollo_ol(ol_settings4, 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_tt_car * time_car + b_cost_car * cost_car +  b_female_car*female + lambda_AT * LV_AT + lambda_SN * LV_SN) 
 
V[["bus"]]  = (asc_bus + b_tt_bus * time_bus + b_cost_bus * cost_bus +  b_access_bus * access_bus + b_female_bus*female + lambda_AT * LV_AT + lambda_SN * LV_SN) 

V[["air"]]  = asc_air + b_tt_air * time_air + b_cost_air * cost_air +  b_access_air * access_air  +  b_no_frills * ( service_air == 1 )  + b_wifi * ( service_air == 2 )  +             b_food * ( service_air == 3 ) + b_business_air*business

V[["rail"]] =  asc_rail + b_tt_rail * time_rail + b_cost_rail * cost_rail + b_business_rail*business + b_access_rail*access_rail + b_no_frills * ( service_air == 1 )  + b_wifi * ( service_air == 2 )  +  b_food * ( service_air == 3) + lambda_SN * LV_SN



### Compute probabilities for the RP part of the data using MNL model
  mnl_settings_RP = list(
       alternatives  = c(car=1, bus=2, air=3, rail=4), 
       avail         = list(car=av_car, bus=av_bus, air=av_air, rail=av_rail), 
       choiceVar     = choice, 
       utilities     = list(car  = mu_RP*V[["car"]],
                            bus  = mu_RP*V[["bus"]],
                            air  = mu_RP*V[["air"]],
                            rail = mu_RP*V[["rail"]]),
       rows          = (RP==1)
  )
  
  P[["RP"]] = apollo_mnl(mnl_settings_RP, functionality)

  ### Compute probabilities for the SP part of the data using MNL model
  mnl_settings_SP = list(
       alternatives  = c(car=1, bus=2, air=3, rail=4), 
       avail         = list(car=av_car, bus=av_bus, air=av_air, rail=av_rail), 
       choiceVar     = choice, 
       utilities     = list(car  = mu_SP*V[["car"]],
                            bus  = mu_SP*V[["bus"]],
                            air  = mu_SP*V[["air"]],
                            rail = mu_SP*V[["rail"]]),
       rows          = (SP==1)
  )
  
  P[["SP"]] = apollo_mnl(mnl_settings_SP, 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                                            ####
# ################################################################# #


######## USE THIS CODE IN THE CASE OF COVERGENCE ISSUE, RUN IT TWICE FOR JOINT RP-SP & HCM  MODEL ########

apollo_estimate(
  apollo_beta,
  apollo_fixed,
  apollo_probabilities,
  apollo_inputs,
  estimate_settings = list(scaleAfterConvergence=FALSE))


# ################################################################# #
#### MODEL OUTPUTS                                               ####
# ################################################################# #

# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN)                               ----
# ----------------------------------------------------------------- #

apollo_modelOutput(model)

# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO FILE, using model name)               ----
# ----------------------------------------------------------------- #

apollo_saveOutput(model)

The Output from the model is as follows

Code: Select all

###################################################################################################################################################################################
WARNING: You can use multiple processor cores to speed up estimation. To do so, specify the desired number of cores using the setting nCores inside
  "apollo_control", for example "nCores=2". This computer has 12 available cores. We recommend using no more than 11 cores.

... current process will resume in 5 seconds unless interrupted by the user
###################################################################################################################################################################################
Preparing user-defined functions.

Testing likelihood function...
No coding provided for Ordered model component "indic_AT_a", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for model component indic_AT_a:
                              1     2     3     4     5
Times chosen               7.00 10.00 11.00 11.00 12.00
Percentage chosen overall 13.73 19.61 21.57 21.57 23.53
No coding provided for Ordered model component "indic_AT_b", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for model component indic_AT_b:
                              1     2     3     4     5
Times chosen              12.00  9.00 15.00  7.00  8.00
Percentage chosen overall 23.53 17.65 29.41 13.73 15.69
No coding provided for Ordered model component "indic_SN_a", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for model component indic_SN_a:
                              1     2     3     4     5
Times chosen              10.00 13.00 16.00  6.00  6.00
Percentage chosen overall 19.61 25.49 31.37 11.76 11.76
No coding provided for Ordered model component "indic_SN_b", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for model component indic_SN_b:
                              1     2     3     4     5
Times chosen              18.00  8.00 11.00  6.00  8.00
Percentage chosen overall 35.29 15.69 21.57 11.76 15.69
Apollo found a model component of type MNL without a componentName. The name was set to "RP" by default.

Overview of choices for MNL model component RP:
                                   car   bus   air   rail
Times available                  60.00 84.00 80.00 102.00
Times chosen                     23.00 16.00 27.00  36.00
Percentage chosen overall        22.55 15.69 26.47  35.29
Percentage chosen when available 38.33 19.05 33.75  35.29
Apollo found a model component of type MNL without a componentName. The name was set to "SP" by default.

Overview of choices for MNL model component SP:
                                    car    bus    air   rail
Times available                  420.00 588.00 558.00 712.00
Times chosen                     108.00  40.00 155.00 409.00
Percentage chosen overall         15.17   5.62  21.77  57.44
Percentage chosen when available  25.71   6.80  27.78  57.44

Pre-processing likelihood function...

Testing influence of parameters
Starting main estimation
Initial function value: -1211.051 
Initial gradient value:
          asc_bus           asc_air          asc_rail          b_tt_car          b_tt_bus          b_tt_air         b_tt_rail      b_access_bus     b_access_rail      b_access_air 
    -8.102314e+01     -3.274524e+01      8.397472e+01      8.400762e+03     -3.067769e+04     -2.177215e+03      1.260743e+04     -1.366260e+03      1.052217e+03     -1.401436e+03 
       b_cost_car        b_cost_bus        b_cost_air       b_cost_rail      b_female_car      b_female_bus    b_business_air   b_business_rail       b_no_frills            b_wifi 
     1.079566e+03     -2.057638e+03     -4.883825e+03      2.824100e+03      1.492953e+01     -2.974303e+01      3.185506e+00      3.002179e+01      2.292861e+01      1.031336e+01 
           b_food   AT_gamma_female   SN_gamma_female AT_gamma_business SN_gamma_business         lambda_AT         lambda_SN         zeta_AT_a         zeta_AT_b         zeta_SN_a 
     1.356311e+01     -1.386623e+01      3.931084e+00     -1.720498e+01     -1.474270e+00      2.335007e+01     -3.619221e+00     -1.243970e+01     -9.717756e+00     -4.209825e+00 
        zeta_SN_b       tau__AT_a_1       tau__AT_a_2       tau__AT_a_3       tau__AT_a_4       tau__AT_b_1       tau__AT_b_2       tau__AT_b_3       tau__AT_b_4       tau__SN_a_1 
    -3.895791e+00     -3.565051e+00      4.935656e+00     -1.131788e+01     -3.567152e+00      9.339628e-01      1.249953e+00     -4.071909e+00     -2.661542e+00     -1.043912e+00 
      tau__SN_a_2       tau__SN_a_3       tau__SN_a_4       tau__SN_b_1       tau__SN_b_2       tau__SN_b_3       tau__SN_b_4             mu_SP 
     1.027864e+01      8.960018e-01      6.452820e-02      9.913622e+00      5.661437e+00     -2.505268e+00     -1.525383e+00      2.872121e+01 
initial  value 1211.051410 
iter   2 value 1142.522321
iter   3 value 1136.556010
iter   4 value 1124.693723
iter   5 value 1028.260769
iter   6 value 1022.536284
iter   7 value 1012.802718
iter   8 value 1011.000890
iter   9 value 1009.995596
iter  10 value 1009.257776
iter  11 value 1008.281512
iter  12 value 988.094798
iter  13 value 986.613965
iter  14 value 978.682144
iter  15 value 941.997945
iter  16 value 921.860543
iter  17 value 917.352275
iter  18 value 916.534083
iter  19 value 911.452968
iter  20 value 908.795821
iter  21 value 904.702693
iter  22 value 900.502445
iter  23 value 895.814767
iter  24 value 890.699086
iter  25 value 886.124857
iter  26 value 885.094700
iter  27 value 883.476337
iter  28 value 880.915993
iter  29 value 877.352614
iter  30 value 876.424812
iter  31 value 875.558190
iter  32 value 873.697742
iter  33 value 872.586283
iter  34 value 871.688302
iter  35 value 870.362610
iter  36 value 869.411144
iter  37 value 868.307543
iter  38 value 867.637980
iter  39 value 867.081455
iter  40 value 866.222437
iter  41 value 865.754431
iter  42 value 865.271876
iter  43 value 864.887423
iter  44 value 864.615745
iter  45 value 864.449955
iter  46 value 864.252099
iter  47 value 864.082592
iter  48 value 863.945863
iter  49 value 863.795598
iter  50 value 863.659015
iter  51 value 863.564316
iter  52 value 863.314800
iter  53 value 863.293874
iter  54 value 863.215682
iter  55 value 863.139631
iter  56 value 862.993754
iter  57 value 862.966239
iter  58 value 862.934428
iter  59 value 862.902321
iter  60 value 862.879719
iter  61 value 862.867060
iter  62 value 862.836994
iter  63 value 862.829650
iter  64 value 862.805558
iter  65 value 862.796827
iter  66 value 862.778488
iter  67 value 862.771948
iter  68 value 862.764163
iter  69 value 862.760461
iter  70 value 862.753555
iter  71 value 862.749951
iter  72 value 862.743775
iter  73 value 862.734140
iter  74 value 862.726104
iter  75 value 862.720449
iter  76 value 862.715526
iter  77 value 862.710378
iter  78 value 862.704579
iter  79 value 862.700339
iter  80 value 862.697360
iter  81 value 862.695555
iter  82 value 862.694121
iter  83 value 862.693053
iter  84 value 862.692406
iter  85 value 862.691474
iter  86 value 862.689282
iter  87 value 862.687035
iter  88 value 862.682994
iter  89 value 862.674051
iter  90 value 862.659757
iter  91 value 862.635059
iter  92 value 862.604680
iter  93 value 862.557625
iter  94 value 862.493736
iter  95 value 862.473922
iter  96 value 862.422413
iter  97 value 862.405687
iter  98 value 862.352339
iter  99 value 862.352199
iter 100 value 862.352040
iter 100 value 862.352036
iter 101 value 862.351601
iter 102 value 862.351564
iter 103 value 862.351541
iter 104 value 862.351084
iter 105 value 862.350509
iter 106 value 862.349978
iter 107 value 862.349818
iter 108 value 862.349248
iter 109 value 862.348786
iter 110 value 862.342754
iter 111 value 862.337003
iter 112 value 862.335952
iter 113 value 862.334902
iter 114 value 862.333717
iter 115 value 862.332775
iter 116 value 862.331041
iter 117 value 862.328807
iter 118 value 862.325957
iter 119 value 862.324174
iter 120 value 862.322912
iter 121 value 862.317163
iter 122 value 862.315542
iter 123 value 862.312794
iter 124 value 862.310006
iter 125 value 862.306446
iter 126 value 862.298124
iter 127 value 862.289273
iter 128 value 862.282309
iter 129 value 862.277438
iter 130 value 862.275628
iter 131 value 862.265530
iter 132 value 862.258694
iter 133 value 862.248362
iter 134 value 862.241795
iter 135 value 862.237522
iter 136 value 862.233615
iter 137 value 862.225411
iter 138 value 862.220470
iter 139 value 862.217900
iter 140 value 862.214691
iter 141 value 862.213678
iter 142 value 862.212765
iter 143 value 862.211965
iter 144 value 862.211349
iter 145 value 862.211032
iter 146 value 862.210652
iter 147 value 862.210151
iter 148 value 862.209823
iter 149 value 862.208760
iter 150 value 862.207075
iter 151 value 862.203056
iter 152 value 862.193619
iter 153 value 862.185759
iter 154 value 862.169606
iter 155 value 862.148173
iter 156 value 862.123654
iter 157 value 862.096524
iter 158 value 862.073814
iter 159 value 862.042068
iter 160 value 861.996237
iter 161 value 861.959132
iter 162 value 861.895697
iter 163 value 861.856470
iter 164 value 861.798255
iter 165 value 861.757593
iter 166 value 861.729693
iter 167 value 861.697960
iter 168 value 861.663026
iter 169 value 861.615433
iter 170 value 861.597779
iter 171 value 861.532491
iter 172 value 861.471019
iter 173 value 861.409178
iter 174 value 861.397213
iter 174 value 861.397213
final  value 861.397213 
converged
Estimated parameters:
                     Estimate
asc_car              0.000000
asc_bus             -0.958331
asc_air              1.836850
asc_rail            -1.653392
b_tt_car            -0.005763
b_tt_bus            -0.006905
b_tt_air            -0.018547
b_tt_rail            0.001171
b_access_bus        -0.020039
b_access_rail       -0.011749
b_access_air        -0.037205
b_cost_car          -0.032474
b_cost_bus          -0.021459
b_cost_air          -0.039877
b_cost_rail         -0.033279
b_female_car        -0.369689
b_female_bus         0.344262
b_business_air       1.748119
b_business_rail      0.933503
b_no_frills          0.535340
b_wifi               0.145185
b_food               0.183298
AT_gamma_female     -0.939285
SN_gamma_female     -0.275812
AT_gamma_business    0.467739
SN_gamma_business   -0.494359
lambda_AT            0.050274
lambda_SN            0.024114
zeta_AT_a            1.267765
zeta_AT_b            2.659581
zeta_SN_a           -2.679753
zeta_SN_b         -174.250391
tau__AT_a_1         -2.791004
tau__AT_a_2         -1.380852
tau__AT_a_3         -0.065843
tau__AT_a_4          1.418395
tau__AT_b_1         -3.470979
tau__AT_b_2         -1.793407
tau__AT_b_3          1.200860
tau__AT_b_4          3.058964
tau__SN_a_1         -1.674133
tau__SN_a_2          0.401341
tau__SN_a_3          3.025582
tau__SN_a_4          4.819699
tau__SN_b_1         -3.293685
tau__SN_b_2         54.107504
tau__SN_b_3        130.782976
tau__SN_b_4        241.894329
mu_RP                1.000000
mu_SP                2.139869

Final LL: -861.3972

Calculating log-likelihood at equal shares (LL(0)) for applicable models...
Calculating log-likelihood at observed shares from estimation data (LL(c)) for applicable models...
Calculating LL of each model component...
Calculating other model fit measures
Computing covariance matrix using analytical gradient.
 0%....25%....50%....75%....100% (192 NA values)
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...
Maximum Likelihood estimation
BFGS maximization, 467 iterations
Return code 0: successful convergence 
Log-Likelihood: -861.3972 (48 free parameter(s))
Estimate(s): 0 -0.9583315 1.83685 -1.653392 -0.005763466 -0.006905275 -0.01854697 0.001171308 -0.02003884 -0.01174943 -0.03720503 -0.03247361 -0.02145936 -0.03987679 -0.03327852 -0.369689 0.3442616 1.748119 0.9335026 0.5353402 0.1451854 0.1832976 -0.939285 -0.2758123 0.467739 -0.4943591 0.05027421 0.02411417 1.267765 2.659581 -2.679753 -174.2504 -2.791004 -1.380852 -0.06584326 1.418395 -3.470979 -1.793407 1.20086 3.058964 -1.674133 0.4013405 3.025582 4.819699 -3.293685 54.1075 130.783 241.8943 1 2.139869 
There were 50 or more warnings (use warnings() to see the first 50)
> 
> # ################################################################# #
> #### MODEL OUTPUTS                                               ####
> # ################################################################# #
> 
> # ----------------------------------------------------------------- #
> #---- FORMATTED OUTPUT (TO SCREEN)                               ----
> # ----------------------------------------------------------------- #
> 
> apollo_modelOutput(model)
Error in apollo_modelOutput(model) : object 'model' not found
> 
> # ----------------------------------------------------------------- #
> #---- FORMATTED OUTPUT (TO FILE, using model name)               ----
> # ----------------------------------------------------------------- #
> 
> apollo_saveOutput(model)
Error in apollo_saveOutput(model) : object 'model' not found
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Error in estimating model with Joint RP-SP and HCM

Post by stephanehess »

Hi

it's difficult for me to say whether your code makes sense as it's not clear what your indicators are or the role of your latent variables is. You seem to just have added things to our existing data, so it's not likely that there is an interpretation. Sorry, just not sure what you're trying to do

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Post Reply