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. We check the forum at least twice a week. It may thus take a couple of days for your post to appear and before we reply. There is no need to submit the post multiple times.

HCM model rho square not applicable problem

Ask questions about the results reported after estimation. If the output includes errors, please include your model code if possible.
Post Reply
XunqianChen
Posts: 1
Joined: 21 Mar 2025, 11:30

HCM model rho square not applicable problem

Post by XunqianChen »

Dear Sir,
I recently applied Apollo to estimate the HCM model. Since there are many latent variables, I processed the latent variables into a normal distribution. However, in the final estimation, the model rho square is "not applicable" and LL(0) is NA. Although the final likelihood value of the selection model is obtained, it is not much different from the MNL model.
I would be very grateful if you can answer my doubts.

The following is the code

Code: Select all


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

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


library(apollo)


apollo_initialise()


apollo_control = list(
  modelName       = "HCM model",
  modelDescr      = "",
  indivID         = "ID",
  nCores          = 4,
  outputDirectory = "HCMoutput"
)


database <- read.csv("C:/Users/chen1/Desktop/3.18/data v0.csv")


database['workplace1'] <- 0
database['workplace2'] <- 0
database['workplace3'] <- 0
database['workplace4'] <- 0
database$workplace1[which(database$workplace == 1)] <- 1
database$workplace2[which(database$workplace == 2)] <- 1
database$workplace3[which(database$workplace == 3)] <- 1
database$workplace4[which(database$workplace == 4)] <- 1

database['age2'] <- 0
database['age3'] <- 0
database['age4'] <- 0
database['age5'] <- 0
database$age2[which(database$age == 2)] <- 1
database$age3[which(database$age == 3)] <- 1
database$age4[which(database$age == 4)] <- 1
database$age5[which(database$age == 5)] <- 1

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(asc_bus = 0,
                asc_subway = 0,
                asc_car = 0,
                asc_noncar = 0,
                
                age_bus = 0,
                # age_bus2 = 0,
                # age_bus3 = 0,
                # age_bus4 = 0,
                # age_bus5 = 0,
                gender_bus = 0,
                marriage_bus = 0,
                education_bus = 0,
                # workplace_bus = 0,
                workplace1_bus = 0,
                workplace2_bus = 0,
                workplace3_bus = 0,
                workplace4_bus = 0,
                domicile_bus = 0,
                # occupation_bus = 0,
                pincome_bus = 0,
                fincome_bus = 0,
                Numvehicles_bus = 0,
                time_bus = 0,
                cost_bus = 0,
                # subwaystations_bus = 0,
                busstops_bus = 0,
                parkinglots_bus = 0,
                
                age_noncar = 0,
                # age_noncar2 = 0,
                # age_noncar3 = 0,
                # age_noncar4 = 0,
                # age_noncar5 = 0,
                gender_noncar = 0,
                marriage_noncar = 0,
                education_noncar = 0,
                # workplace_subway = 0,
                workplace1_noncar = 0,
                workplace2_noncar = 0,
                workplace3_noncar = 0,
                workplace4_noncar = 0,
                domicile_noncar = 0,
                # occupation_noncar = 0,
                pincome_noncar = 0,
                fincome_noncar = 0,
                Numvehicles_noncar = 0,
                time_noncar = 0,
                cost_noncar = 0,
                # subwaystations_noncar = 0,
                busstops_noncar = 0,
                parkinglots_noncar = 0,
                
                age_car = 0,
                # age_car2 = 0,
                # age_car3 = 0,
                # age_car4 = 0,
                # age_car5 = 0,
                gender_car = 0,
                marriage_car = 0,
                education_car = 0,
                # workplace_car = 0,
                workplace1_car = 0,
                workplace2_car = 0,
                workplace3_car = 0,
                workplace4_car = 0,
                domicile_car = 0,
                # occupation_car = 0,
                pincome_car = 0,
                fincome_car = 0,
                Numvehicles_car = 0,
                time_car = 0,
                cost_car = 0,
                # subwaystations_car = 0,
                busstops_car = 0,
                parkinglots_car = 0,
                
                zeta_LA1 = 1,
                zeta_LA2 = 1,
                zeta_LA3 = 1,
                zeta_AR1 = 1,
                zeta_AR2 = 1,
                zeta_AR3 = 1,
                zeta_SN1 = 1,
                zeta_SN2 = 1,
                zeta_SN3 = 1,
                zeta_AT1 = 1,
                zeta_AT2 = 1,
                zeta_AT3 = 1,
                zeta_TH1 = 1,
                zeta_TH2 = 1,
                zeta_TH3 = 1,
                zeta_PS1 = 1,
                zeta_PS2 = 1,
                zeta_PS3 = 1,
                zeta_CIPI1 = 1,
                zeta_CIPI2 = 1,
                zeta_CIPI3 = 1,
                zeta_BI1 = 1,
                
                sigma_LA1 = 1,
                sigma_LA2 = 1,
                sigma_LA3 = 1,
                sigma_AR1 = 1,
                sigma_AR2 = 1,
                sigma_AR3 = 1,
                sigma_SN1 = 1,
                sigma_SN2 = 1,
                sigma_SN3 = 1,
                sigma_AT1 = 1,
                sigma_AT2 = 1,
                sigma_AT3 = 1,
                sigma_TH1 = 1,
                sigma_TH2 = 1,
                sigma_TH3 = 1,
                sigma_PS1 = 1,
                sigma_PS2 = 1,
                sigma_PS3 = 1,
                sigma_CIPI1 = 1,
                sigma_CIPI2 = 1,
                sigma_CIPI3 = 1,
                sigma_BI1 = 1,

                
                age_LA = 0,
                gender_LA = 0,
                marriage_LA = 0,
                education_LA = 0,
                workplace_LA = 0,
                domicile_LA = 0,
                pincome_LA = 0,
                fincome_LA = 0,
                Numvehicles_LA = 0,
                
                age_AR = 0,
                gender_AR = 0,
                marriage_AR = 0,
                education_AR = 0,
                workplace_AR = 0,
                domicile_AR = 0,
                pincome_AR = 0,
                fincome_AR = 0,
                Numvehicles_AR = 0,
                
                age_SN = 0,
                gender_SN = 0,
                marriage_SN = 0,
                education_SN = 0,
                workplace_SN = 0,
                domicile_SN = 0,
                pincome_SN = 0,
                fincome_SN = 0,
                Numvehicles_SN = 0,
                
                age_AT = 0,
                gender_AT = 0,
                marriage_AT = 0,
                education_AT = 0,
                workplace_AT = 0,
                domicile_AT = 0,
                pincome_AT = 0,
                fincome_AT = 0,
                Numvehicles_AT = 0,
                
                age_TH = 0,
                gender_TH = 0,
                marriage_TH = 0,
                education_TH = 0,
                workplace_TH = 0,
                domicile_TH = 0,
                pincome_TH = 0,
                fincome_TH = 0,
                Numvehicles_TH = 0,
                
                age_PS = 0,
                gender_PS = 0,
                marriage_PS = 0,
                education_PS = 0,
                workplace_PS = 0,
                domicile_PS = 0,
                pincome_PS = 0,
                fincome_PS = 0,
                Numvehicles_PS = 0,
                
                age_CIPI = 0,
                gender_CIPI = 0,
                marriage_CIPI = 0,
                education_CIPI = 0,
                workplace_CIPI = 0,
                domicile_CIPI = 0,
                pincome_CIPI = 0,
                fincome_CIPI = 0,
                Numvehicles_CIPI = 0,
                
                age_BI = 0,
                gender_BI = 0,
                marriage_BI = 0,
                education_BI = 0,
                workplace_BI = 0,
                domicile_BI = 0,
                pincome_BI = 0,
                fincome_BI = 0,
                Numvehicles_BI = 0,
                
                b_LA_bus = 1,
                b_AR_bus = 1,
                b_SN_bus = 1,
                b_AT_bus = 1,
                b_TH_bus = 1,
                b_PS_bus = 1,
                b_CIPI_bus = 1,
                b_BI_bus = 1,
                
                b_LA_noncar = 1,
                b_AR_noncar = 1,
                b_SN_noncar = 1,
                b_AT_noncar = 1,
                b_TH_noncar = 1,
                b_PS_noncar = 1,
                b_CIPI_noncar = 1,
                b_BI_noncar = 1,
                
                b_LA_car = 1,
                b_AR_car = 1,
                b_SN_car = 1,
                b_AT_car = 1,
                b_TH_car = 1,
                b_PS_car = 1,
                b_CIPI_car = 1,
                b_BI_car = 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_subway', "zeta_BI1")

### Set parameters for generating draws
apollo_draws = list(
  interDrawsType="halton", 
  interNDraws=100,          
  interUnifDraws=c(),      
  interNormDraws=c("eta1",'eta2','eta3','eta4','eta5','eta6','eta7','eta8'), 
  
  intraDrawsType="",
  intraNDraws=0,          
  intraUnifDraws=c(),     
  intraNormDraws=c()      
)


### Create random parameters
apollo_randCoeff=function(apollo_beta, apollo_inputs){
  randcoeff = list()
  
  randcoeff[["LA"]] =  age_LA * age + 
    gender_LA * gender +
    marriage_LA * marriage +
    education_LA * education + 
    workplace_LA * workplace +
    domicile_LA * domicile +
    pincome_LA * pincome + 
    fincome_LA * fincome + 
    Numvehicles_LA * Numvehicles + 
    eta1
  
  randcoeff[["AR"]] = age_AR * age + 
    gender_AR * gender +
    marriage_AR * marriage +
    education_AR * education + 
    workplace_AR * workplace +
    domicile_AR * domicile +
    pincome_AR * pincome + 
    fincome_AR * fincome + 
    Numvehicles_AR * Numvehicles + 
    eta2
  
  randcoeff[["SN"]] = age_SN * age + 
    gender_SN * gender +
    marriage_SN * marriage +
    education_SN * education + 
    workplace_SN * workplace +
    domicile_SN * domicile +
    pincome_SN * pincome + 
    fincome_SN * fincome + 
    Numvehicles_SN * Numvehicles + 
    eta3
  
  randcoeff[["AT"]] =  age_AT * age + 
    gender_AT * gender +
    marriage_AT * marriage +
    education_AT * education + 
    workplace_AT * workplace +
    domicile_AT * domicile +
    pincome_AT * pincome + 
    fincome_AT * fincome + 
    Numvehicles_AT * Numvehicles + 
    eta4
  
  randcoeff[["TH"]] = age_TH * age + 
    gender_TH * gender +
    marriage_TH * marriage +
    education_TH * education + 
    workplace_TH * workplace +
    domicile_TH * domicile +
    pincome_TH * pincome + 
    fincome_TH * fincome + 
    Numvehicles_TH * Numvehicles + 
    eta5
  
  randcoeff[["PS"]] = age_PS * age + 
    gender_PS * gender +
    marriage_PS * marriage +
    education_PS * education + 
    workplace_PS * workplace +
    domicile_PS * domicile +
    pincome_PS * pincome + 
    fincome_PS * fincome + 
    Numvehicles_PS * Numvehicles + 
    eta6
  
  randcoeff[["CIPI"]] = age_CIPI * age + 
    gender_CIPI * gender +
    marriage_CIPI * marriage +
    education_CIPI * education + 
    workplace_CIPI * workplace +
    domicile_CIPI * domicile +
    pincome_CIPI * pincome + 
    fincome_CIPI * fincome + 
    Numvehicles_CIPI * Numvehicles + 
    eta7
  
  randcoeff[["BI"]] = age_BI * age + 
    gender_BI * gender +
    marriage_BI * marriage +
    education_BI * education + 
    workplace_BI * workplace +
    domicile_BI * domicile +
    pincome_BI * pincome + 
    fincome_BI * fincome + 
    Numvehicles_BI * Numvehicles + 
    eta8
  
  return(randcoeff)
}


apollo_inputs = apollo_validateInputs()


apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
  
  
  apollo_attach(apollo_beta, apollo_inputs)
  on.exit(apollo_detach(apollo_beta, apollo_inputs))
  
  P = list()
  V = list()
  ### Likelihood of indicators
  normalDensity_settings1 = list(outcomeNormal = LA1, 
                                 xNormal       = zeta_LA1*LA, 
                                 mu            = 3, 
                                 sigma         = sigma_LA1, 
                                 # rows          = (task==1),
                                 componentName = "indic_LA1")
  normalDensity_settings2 = list(outcomeNormal = LA2, 
                                 xNormal       = zeta_LA2*LA, 
                                 mu            = 3, 
                                 sigma         = sigma_LA2, 
                                 # rows          = (task==1),
                                 componentName = "indic_LA2")
  normalDensity_settings3 = list(outcomeNormal = LA3, 
                                 xNormal       = zeta_LA3*LA, 
                                 mu            = 3, 
                                 sigma         = sigma_LA3, 
                                 # rows          = (task==1),
                                 componentName = "indic_LA3")
  normalDensity_settings4 = list(outcomeNormal = AR1, 
                                 xNormal       = zeta_AR1*AR, 
                                 mu            = 3, 
                                 sigma         = sigma_AR1, 
                                 # rows          = (task==1),
                                 componentName = "indic_AR1")
  normalDensity_settings5 = list(outcomeNormal = AR2, 
                                 xNormal       = zeta_AR2*AR, 
                                 mu            = 3, 
                                 sigma         = sigma_AR2, 
                                 # rows          = (task==1),
                                 componentName = "indic_AR2")
  normalDensity_settings6 = list(outcomeNormal = AR3, 
                                 xNormal       = zeta_AR3*AR, 
                                 mu            = 3, 
                                 sigma         = sigma_AR3, 
                                 # rows          = (task==1),
                                 componentName = "indic_AR3")
  normalDensity_settings7 = list(outcomeNormal = SN1, 
                                 xNormal       = zeta_SN1*SN, 
                                 mu            = 3, 
                                 sigma         = sigma_SN1, 
                                 # rows          = (task==1),
                                 componentName = "indic_SN1")
  normalDensity_settings8 = list(outcomeNormal = SN2, 
                                 xNormal       = zeta_SN2*SN, 
                                 mu            = 3, 
                                 sigma         = sigma_SN2, 
                                 # rows          = (task==1),
                                 componentName = "indic_SN2")
  normalDensity_settings9 = list(outcomeNormal = SN3, 
                                 xNormal       = zeta_SN3*SN, 
                                 mu            = 3, 
                                 sigma         = sigma_SN3, 
                                 # rows          = (task==1),
                                 componentName = "indic_SN3")
  normalDensity_settings10 = list(outcomeNormal = AT1, 
                                 xNormal       = zeta_AT1*AT, 
                                 mu            = 3, 
                                 sigma         = sigma_AT1, 
                                 # rows          = (task==1),
                                 componentName = "indic_AT1")
  normalDensity_settings11 = list(outcomeNormal = AT2, 
                                  xNormal       = zeta_AT2*AT, 
                                  mu            = 3, 
                                  sigma         = sigma_AT2, 
                                  # rows          = (task==1),
                                  componentName = "indic_AT2")
  normalDensity_settings12 = list(outcomeNormal = AT3, 
                                  xNormal       = zeta_AT3*AT, 
                                  mu            = 3, 
                                  sigma         = sigma_AT3, 
                                  # rows          = (task==1),
                                  componentName = "indic_AT3")
  normalDensity_settings13 = list(outcomeNormal = TH1, 
                                  xNormal       = zeta_TH1*TH, 
                                  mu            = 3, 
                                  sigma         = sigma_TH1, 
                                  # rows          = (task==1),
                                  componentName = "indic_TH1")
  normalDensity_settings14 = list(outcomeNormal = TH2, 
                                  xNormal       = zeta_TH2*TH, 
                                  mu            = 3, 
                                  sigma         = sigma_TH2, 
                                  # rows          = (task==1),
                                  componentName = "indic_TH2")
  normalDensity_settings15 = list(outcomeNormal = TH3, 
                                  xNormal       = zeta_TH3*TH, 
                                  mu            = 3, 
                                  sigma         = sigma_TH3, 
                                  # rows          = (task==1),
                                  componentName = "indic_TH3")
  normalDensity_settings16 = list(outcomeNormal = PS1, 
                                  xNormal       = zeta_PS1*PS, 
                                  mu            = 3, 
                                  sigma         = sigma_PS1, 
                                  # rows          = (task==1),
                                  componentName = "indic_PS1")
  normalDensity_settings17 = list(outcomeNormal = PS2, 
                                  xNormal       = zeta_PS2*PS, 
                                  mu            = 3, 
                                  sigma         = sigma_PS2, 
                                  # rows          = (task==1),
                                  componentName = "indic_PS2")
  normalDensity_settings18 = list(outcomeNormal = PS3, 
                                  xNormal       = zeta_PS3*PS, 
                                  mu            = 3, 
                                  sigma         = sigma_PS3, 
                                  # rows          = (task==1),
                                  componentName = "indic_PS3")
  normalDensity_settings19 = list(outcomeNormal = CIPI1, 
                                  xNormal       = zeta_CIPI1*CIPI, 
                                  mu            = 3, 
                                  sigma         = sigma_CIPI1, 
                                  # rows          = (task==1),
                                  componentName = "indic_CIPI1")
  normalDensity_settings20 = list(outcomeNormal = CIPI2, 
                                  xNormal       = zeta_CIPI2*CIPI, 
                                  mu            = 3, 
                                  sigma         = sigma_CIPI2, 
                                  # rows          = (task==1),
                                  componentName = "indic_CIPI2")
  normalDensity_settings21 = list(outcomeNormal = CIPI3, 
                                  xNormal       = zeta_CIPI3*CIPI, 
                                  mu            = 3, 
                                  sigma         = sigma_CIPI3, 
                                  # rows          = (task==1),
                                  componentName = "indic_CIPI3")
  normalDensity_settings22 = list(outcomeNormal = BI1, 
                                  xNormal       = zeta_BI1*BI, 
                                  mu            = 3, 
                                  sigma         = sigma_BI1, 
                                  # rows          = (task==1),
                                  componentName = "indic_BI1")
  

  P[["indic_LA1"]]     = apollo_normalDensity(normalDensity_settings1, functionality)
  P[["indic_LA2"]]     = apollo_normalDensity(normalDensity_settings2, functionality)
  P[["indic_LA3"]]     = apollo_normalDensity(normalDensity_settings3, functionality)
  P[["indic_AR1"]]     = apollo_normalDensity(normalDensity_settings4, functionality)
  P[["indic_AR2"]]     = apollo_normalDensity(normalDensity_settings5, functionality)
  P[["indic_AR3"]]     = apollo_normalDensity(normalDensity_settings6, functionality)
  P[["indic_SN1"]]     = apollo_normalDensity(normalDensity_settings7, functionality)
  P[["indic_SN2"]]     = apollo_normalDensity(normalDensity_settings8, functionality)
  P[["indic_SN3"]]     = apollo_normalDensity(normalDensity_settings9, functionality)
  P[["indic_AT1"]]     = apollo_normalDensity(normalDensity_settings10, functionality)
  P[["indic_AT2"]]     = apollo_normalDensity(normalDensity_settings11, functionality)
  P[["indic_AT3"]]     = apollo_normalDensity(normalDensity_settings12, functionality)
  P[["indic_TH1"]]     = apollo_normalDensity(normalDensity_settings13, functionality)
  P[["indic_TH2"]]     = apollo_normalDensity(normalDensity_settings14, functionality)
  P[["indic_TH3"]]     = apollo_normalDensity(normalDensity_settings15, functionality)
  P[["indic_PS1"]]     = apollo_normalDensity(normalDensity_settings16, functionality)
  P[["indic_PS2"]]     = apollo_normalDensity(normalDensity_settings17, functionality)
  P[["indic_PS3"]]     = apollo_normalDensity(normalDensity_settings18, functionality)
  P[["indic_CIPI1"]]     = apollo_normalDensity(normalDensity_settings19, functionality)
  P[["indic_CIPI2"]]     = apollo_normalDensity(normalDensity_settings20, functionality)
  P[["indic_CIPI3"]]     = apollo_normalDensity(normalDensity_settings21, functionality)
  P[["indic_BI1"]]     = apollo_normalDensity(normalDensity_settings22, functionality)
 
  ### Likelihood of choices
  V[["noncar"]] = asc_noncar +
    age_noncar * age +
    # age_noncar2 * age2 + 
    # age_noncar3 * age3 + 
    # age_noncar4 * age4 + 
    # age_noncar5 * age5 + 
    gender_noncar * gender +
    marriage_noncar * marriage +
    education_noncar * education + 
    # workplace_noncar * workplace +
    workplace1_noncar * workplace1 +
    workplace2_noncar * workplace2 +
    workplace3_noncar * workplace3 +
    workplace4_noncar * workplace4 +
    domicile_noncar * domicile +
    # occupation_noncar * occupation + 
    pincome_noncar * pincome + 
    fincome_noncar * fincome + 
    Numvehicles_noncar * Numvehicles + 
    time_noncar * time + 
    cost_noncar * cost +
    # subwaystations_noncar * subwaystations +
    busstops_noncar * busstops + 
    parkinglots_noncar * parkinglots +
    
    b_LA_noncar * LA + 
    b_AR_noncar * AR + 
    b_SN_noncar * SN + 
    b_AT_noncar * AT + 
    b_TH_noncar * TH +
    b_PS_noncar * PS +
    b_CIPI_noncar * CIPI +
    b_BI_noncar * BI
  
  
  V[["bus"]] = asc_bus +
    age_bus * age +
    # age_bus2 * age2 + 
    # age_bus3 * age3 + 
    # age_bus4 * age4 + 
    # age_bus5 * age5 + 
    gender_bus * gender +
    marriage_bus * marriage +
    education_bus * education + 
    # workplace_bus * workplace +
    workplace1_bus * workplace1 +
    workplace2_bus * workplace2 +
    workplace3_bus * workplace3 +
    workplace4_bus * workplace4 +
    domicile_bus * domicile +
    # occupation_bus * occupation + 
    pincome_bus * pincome + 
    fincome_bus * fincome + 
    Numvehicles_bus * Numvehicles + 
    time_bus * time + 
    cost_bus * cost +
    # subwaystations_bus * subwaystations +
    busstops_bus * busstops + 
    parkinglots_bus * parkinglots +
    
    b_LA_bus * LA + 
    b_AR_bus * AR + 
    b_SN_bus * SN + 
    b_AT_bus * AT + 
    b_TH_bus * TH +
    b_PS_bus * PS +
    b_CIPI_bus * CIPI +
    b_BI_bus * BI
  
  
  V[["subway"]] = asc_subway
    
    
  
  V[["car"]] = asc_car +
    age_car * age +
    # age_car2 * age2 + 
    # age_car3 * age3 + 
    # age_car4 * age4 + 
    # age_car5 * age5 + 
    gender_car * gender +
    marriage_car * marriage +
    education_car * education +
    # workplace_car * workplace +
    workplace1_car * workplace1 +
    workplace2_car * workplace2 +
    workplace3_car * workplace3 +
    workplace4_car * workplace4 +
    domicile_car * domicile +
    # occupation_car * occupation + 
    pincome_car * pincome + 
    fincome_car * fincome + 
    Numvehicles_car * Numvehicles + 
    time_car * time + 
    cost_car * cost +
    # subwaystations_car * subwaystations +
    busstops_car * busstops + 
    parkinglots_car * parkinglots +
    
    b_LA_car * LA + 
    b_AR_car * AR + 
    b_SN_car * SN + 
    b_AT_car * AT + 
    b_TH_car * TH +
    b_PS_car * PS +
    b_CIPI_car * CIPI +
    b_BI_car * BI
  
  ### Define settings for MNL model component
  mnl_settings <- list(
    alternatives = c(noncar = 'noncar', bus = 'bus', subway = 'subway', car = 'car'),
    choiceVar    = choice,
    utilities    = V,
    componentName = "choice"
  )
  ### Compute probabilities for MNL model component
  P[["choice"]] = apollo_mnl(mnl_settings, functionality)
  ### Likelihood of the whole model
  P = apollo_combineModels(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 <- apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs,
                         estimate_settings = list(estimationRoutine = "bfgs",
                                                  hessianRoutine = 'analytic',
                                                  maxIterations = 1000
                         ))
  

apollo_modelOutput(model)

apollo_saveOutput(model)

Below is the model output

Code: Select all

Model run by chen1 using Apollo 0.3.5 on R 4.3.3 for Windows.
Please acknowledge the use of Apollo by citing Hess & Palma (2019)
  DOI 10.1016/j.jocm.2019.100170
  www.ApolloChoiceModelling.com

Model name                                  : HCM model
Model description                           : 
Model run at                                : 2025-03-21 16:14:16.357367
Estimation method                           : bfgs
Model diagnosis                             : successful convergence
Optimisation diagnosis                      : Maximum found
     hessian properties                     : Negative definite
     maximum eigenvalue                     : -0.560043
     reciprocal of condition number         : 2.22631e-07
Number of individuals                       : 861
Number of rows in database                  : 861
Number of modelled outcomes                 : 19803
                       indic_LA1 : 861
                       indic_LA2 : 861
                       indic_LA3 : 861
                       indic_AR1 : 861
                       indic_AR2 : 861
                       indic_AR3 : 861
                       indic_SN1 : 861
                       indic_SN2 : 861
                       indic_SN3 : 861
                       indic_AT1 : 861
                       indic_AT2 : 861
                       indic_AT3 : 861
                       indic_TH1 : 861
                       indic_TH2 : 861
                       indic_TH3 : 861
                       indic_PS1 : 861
                       indic_PS2 : 861
                       indic_PS3 : 861
                     indic_CIPI1 : 861
                     indic_CIPI2 : 861
                     indic_CIPI3 : 861
                       indic_BI1 : 861
                          choice : 861

Number of cores used                        :  4 
Number of inter-individual draws            : 100 (halton)
WARNING: Inter-individual draws were used
         without a panel data structure.

LL(start)                                   : -34970.24
LL (whole model) at equal shares, LL(0)     : NA
LL (whole model) at observed shares, LL(C)  : NA
LL(final, whole model)                      : -31396.26
Rho-squared vs equal shares                  :  Not applicable 
Adj.Rho-squared vs equal shares              :  Not applicable 
Rho-squared vs observed shares               :  Not applicable 
Adj.Rho-squared vs observed shares           :  Not applicable 
AIC                                         :  63172.53 
BIC                                         :  64076.56 

LL(0,indic_LA1)                  : Not applicable
LL(final,indic_LA1)              : -1440.92
LL(0,indic_LA2)                  : Not applicable
LL(final,indic_LA2)              : -1427.63
LL(0,indic_LA3)                  : Not applicable
LL(final,indic_LA3)              : -1362.91
LL(0,indic_AR1)                  : Not applicable
LL(final,indic_AR1)              : -1433.98
LL(0,indic_AR2)                  : Not applicable
LL(final,indic_AR2)              : -1497.45
LL(0,indic_AR3)                  : Not applicable
LL(final,indic_AR3)              : -1457.21
LL(0,indic_SN1)                  : Not applicable
LL(final,indic_SN1)              : -1523.4
LL(0,indic_SN2)                  : Not applicable
LL(final,indic_SN2)              : -1543.31
LL(0,indic_SN3)                  : Not applicable
LL(final,indic_SN3)              : -1554.48
LL(0,indic_AT1)                  : Not applicable
LL(final,indic_AT1)              : -1550.09
LL(0,indic_AT2)                  : Not applicable
LL(final,indic_AT2)              : -1553.13
LL(0,indic_AT3)                  : Not applicable
LL(final,indic_AT3)              : -1520.15
LL(0,indic_TH1)                  : Not applicable
LL(final,indic_TH1)              : -1664.08
LL(0,indic_TH2)                  : Not applicable
LL(final,indic_TH2)              : -1671.58
LL(0,indic_TH3)                  : Not applicable
LL(final,indic_TH3)              : -1640.25
LL(0,indic_PS1)                  : Not applicable
LL(final,indic_PS1)              : -1347.68
LL(0,indic_PS2)                  : Not applicable
LL(final,indic_PS2)              : -1439.63
LL(0,indic_PS3)                  : Not applicable
LL(final,indic_PS3)              : -1462.77
LL(0,indic_CIPI1)                : Not applicable
LL(final,indic_CIPI1)            : -1541.65
LL(0,indic_CIPI2)                : Not applicable
LL(final,indic_CIPI2)            : -1383.75
LL(0,indic_CIPI3)                : Not applicable
LL(final,indic_CIPI3)            : -1506.2
LL(0,indic_BI1)                  : Not applicable
LL(final,indic_BI1)              : -1406.99
LL(0,choice)                     : -1193.6
LL(final,choice)                 : -837.93

Estimated parameters                        : 190
Time taken (hh:mm:ss)                       :  02:27:0.64 
     pre-estimation                         :  00:00:32.34 
     estimation                             :  00:23:23.77 
     post-estimation                        :  02:03:4.53 
Iterations                                  :  206  

Unconstrained optimisation.

Estimates:
                      Estimate        s.e.   t.rat.(0)    Rob.s.e. Rob.t.rat.(0)
asc_bus              -1.240274    1.165594   -1.064071    1.162322     -1.067066
asc_subway            0.000000          NA          NA          NA            NA
asc_car              -1.576290    0.813604   -1.937416    0.817365     -1.928501
asc_noncar            3.745601    0.816100    4.589635    0.787492      4.756367
age_bus               0.221859    0.204861    1.082972    0.198567      1.117297
gender_bus           -0.027355    0.327781   -0.083455    0.316366     -0.086466
marriage_bus          0.108957    0.418119    0.260589    0.372152      0.292777
education_bus         0.376751    0.196847    1.913929    0.193380      1.948239
workplace1_bus       -0.909601    0.639526   -1.422305    0.682272     -1.333194
workplace2_bus       -0.327924    0.475919   -0.689032    0.479738     -0.683546
workplace3_bus       -0.817313    0.728153   -1.122447    0.694588     -1.176687
workplace4_bus       -0.348258    0.393139   -0.885840    0.398093     -0.874816
domicile_bus         -0.020547    0.341461   -0.060173    0.354001     -0.058041
pincome_bus          -0.026131    0.173782   -0.150366    0.171920     -0.151995
fincome_bus          -0.123389    0.152758   -0.807744    0.159548     -0.773367
Numvehicles_bus      -0.265667    0.222919   -1.191766    0.207809     -1.278415
time_bus             -0.035694    0.162542   -0.219599    0.144915     -0.246311
cost_bus             -0.508761    0.216470   -2.350260    0.233491     -2.178927
busstops_bus          0.019172    0.009086    2.110180    0.009027      2.123842
parkinglots_bus      -0.002211    0.004627   -0.477823    0.004640     -0.476512
age_noncar           -0.018196    0.150501   -0.120904    0.162577     -0.111924
gender_noncar        -0.342311    0.228923   -1.495316    0.228252     -1.499711
marriage_noncar       0.425102    0.302618    1.404745    0.312883      1.358661
education_noncar     -0.046327    0.136293   -0.339906    0.132422     -0.349841
workplace1_noncar     0.039811    0.407621    0.097666    0.412541      0.096501
workplace2_noncar     0.060822    0.341925    0.177881    0.358616      0.169602
workplace3_noncar    -0.742958    0.509846   -1.457223    0.520519     -1.427342
workplace4_noncar    -0.208506    0.282432   -0.738254    0.290446     -0.717883
domicile_noncar       0.084262    0.244719    0.344322    0.245919      0.342641
pincome_noncar       -0.085268    0.119711   -0.712280    0.119928     -0.710990
fincome_noncar       -0.080936    0.107968   -0.749628    0.107228     -0.754804
Numvehicles_noncar   -0.411240    0.147730   -2.783723    0.152658     -2.693863
time_noncar          -1.577250    0.150682  -10.467415    0.154737    -10.193099
cost_noncar          -0.130385    0.131762   -0.989551    0.137207     -0.950282
busstops_noncar       0.010630    0.007094    1.498381    0.006490      1.637835
parkinglots_noncar    0.004189    0.003360    1.246769    0.003059      1.369246
age_car              -0.048807    0.143721   -0.339592    0.144198     -0.338469
gender_car           -0.112477    0.222601   -0.505286    0.225579     -0.498615
marriage_car         -0.135654    0.280212   -0.484112    0.272194     -0.498373
education_car         0.213527    0.132527    1.611197    0.133480      1.599688
workplace1_car       -0.784429    0.419605   -1.869444    0.426672     -1.838484
workplace2_car       -0.527900    0.342388   -1.541821    0.357475     -1.476746
workplace3_car       -0.170881    0.418597   -0.408223    0.418126     -0.408682
workplace4_car       -0.088372    0.275436   -0.320843    0.283562     -0.311648
domicile_car         -0.020204    0.233786   -0.086422    0.236907     -0.085283
pincome_car           0.252343    0.120132    2.100544    0.123747      2.039187
fincome_car          -0.179754    0.108032   -1.663893    0.113253     -1.587190
Numvehicles_car      -0.017618    0.142222   -0.123877    0.138184     -0.127497
time_car              0.285781    0.107753    2.652188    0.101239      2.822840
cost_car              0.109561    0.111002    0.987019    0.109064      1.004564
busstops_car          0.011495    0.007057    1.628892    0.006612      1.738476
parkinglots_car       0.005673    0.003345    1.696063    0.003218      1.763145
zeta_LA1              0.846522    0.056882   14.881969    0.178684      4.737547
zeta_LA2              0.752628    0.055332   13.602085    0.175925      4.278131
zeta_LA3              0.643719    0.048754   13.203331    0.152681      4.216102
zeta_AR1              0.875217    0.043203   20.258370    0.085501     10.236282
zeta_AR2              0.851183    0.045398   18.749337    0.082450     10.323663
zeta_AR3              0.779553    0.042745   18.237441    0.078025      9.991093
zeta_SN1              1.062733    0.041713   25.476998    0.084196     12.622058
zeta_SN2              1.124246    0.042873   26.222744    0.098461     11.418149
zeta_SN3              1.117781    0.045196   24.731679    0.105809     10.564133
zeta_AT1              0.999017    0.045626   21.895919    0.086129     11.599054
zeta_AT2              0.985438    0.044805   21.994116    0.084007     11.730428
zeta_AT3              0.973085    0.043036   22.610734    0.078613     12.378219
zeta_TH1              1.357267    0.047292   28.699783    0.066367     20.450845
zeta_TH2              1.375590    0.045747   30.069307    0.059274     23.207509
zeta_TH3              1.305645    0.048291   27.036970    0.072223     18.077948
zeta_PS1              0.599787    0.057415   10.446492    0.183659      3.265759
zeta_PS2              0.542041    0.055278    9.805752    0.174649      3.103592
zeta_PS3              0.545486    0.055959    9.747945    0.176263      3.094727
zeta_CIPI1            0.950685    0.042730   22.248809    0.075043     12.668461
zeta_CIPI2            0.902273    0.034940   25.823402    0.055732     16.189514
zeta_CIPI3            0.960854    0.040173   23.918123    0.063520     15.126879
zeta_BI1              1.000000          NA          NA          NA            NA
sigma_LA1             1.057623    0.036413   29.045087    0.077871     13.581702
sigma_LA2             1.019757    0.037519   27.179702    0.091944     11.091043
sigma_LA3             0.982391    0.032850   29.904956    0.072979     13.461241
sigma_AR1             0.983432    0.032974   29.824636    0.057707     17.041815
sigma_AR2             1.098805    0.033954   32.361689    0.049411     22.238197
sigma_AR3             1.078547    0.032068   33.633242    0.045994     23.449748
sigma_SN1             1.002193    0.031637   31.678048    0.055204     18.154291
sigma_SN2             0.899233    0.033932   26.501376    0.074202     12.118670
sigma_SN3             0.952210    0.035783   26.610744    0.084167     11.313357
sigma_AT1             1.066784    0.037264   28.628044    0.066395     16.067232
sigma_AT2             1.071233    0.035524   30.155256    0.063492     16.872010
sigma_AT3             1.063983    0.034487   30.851707    0.057200     18.600959
sigma_TH1             1.018403    0.032208   31.619716    0.040609     25.078261
sigma_TH2             1.006797    0.032326   31.145499    0.040702     24.735617
sigma_TH3             1.025303    0.033789   30.344588    0.048004     21.358703
sigma_PS1             1.038986    0.035375   29.370295    0.086702     11.983445
sigma_PS2             1.147927    0.036575   31.385711    0.084544     13.577903
sigma_PS3             1.188359    0.037138   31.998858    0.083105     14.299571
sigma_CIPI1           1.047348    0.034870   30.035855    0.058475     17.911024
sigma_CIPI2           0.905638    0.028977   31.254041    0.044902     20.169272
sigma_CIPI3           1.019343    0.031904   31.949978    0.043444     23.463312
sigma_BI1             1.227480    0.037669   32.586315    0.045871     26.759569
age_LA                0.281043    0.049899    5.632267    0.097359      2.886680
gender_LA             0.024683    0.075215    0.328160    0.126821      0.194626
marriage_LA          -0.387568    0.102063   -3.797335    0.173210     -2.237563
education_LA          0.282857    0.037635    7.515769    0.087658      3.226834
workplace_LA          0.145164    0.023408    6.201386    0.042328      3.429487
domicile_LA          -0.188992    0.078790   -2.398665    0.123794     -1.526661
pincome_LA           -0.147813    0.039899   -3.704678    0.068452     -2.159373
fincome_LA            0.019204    0.038937    0.493202    0.071849      0.267280
Numvehicles_LA       -0.043329    0.054355   -0.797156    0.109630     -0.395234
age_AR                0.090693    0.040488    2.239994    0.075493      1.201334
gender_AR             0.096190    0.071490    1.345492    0.121737      0.790146
marriage_AR          -0.045334    0.091585   -0.494994    0.160917     -0.281722
education_AR          0.098899    0.030961    3.194274    0.053885      1.835370
workplace_AR          0.026783    0.021061    1.271675    0.035155      0.761860
domicile_AR           0.087073    0.076457    1.138855    0.144375      0.603101
pincome_AR            0.021313    0.038615    0.551930    0.067720      0.314717
fincome_AR            0.054058    0.036022    1.500719    0.062904      0.859382
Numvehicles_AR       -0.071301    0.049551   -1.438931    0.091901     -0.775841
age_SN                0.179193    0.038571    4.645742    0.092691      1.933229
gender_SN             0.090124    0.064629    1.394487    0.144566      0.623406
marriage_SN          -0.228929    0.087180   -2.625945    0.205280     -1.115203
education_SN          0.010335    0.029937    0.345242    0.074863      0.138058
workplace_SN          0.070388    0.019018    3.701093    0.041839      1.682362
domicile_SN          -0.188394    0.068515   -2.749667    0.152209     -1.237738
pincome_SN            0.131502    0.035846    3.668573    0.087795      1.497824
fincome_SN           -0.074884    0.030226   -2.477415    0.064567     -1.159784
Numvehicles_SN        0.065493    0.045661    1.434324    0.111793      0.585838
age_AT                0.081127    0.038435    2.110730    0.068144      1.190527
gender_AT             0.047893    0.065520    0.730976    0.116354      0.411617
marriage_AT           0.109589    0.085150    1.287011    0.159515      0.687017
education_AT          0.125975    0.028597    4.405186    0.053389      2.359581
workplace_AT          0.052111    0.019136    2.723208    0.033068      1.575896
domicile_AT          -0.275584    0.068902   -3.999677    0.122913     -2.242113
pincome_AT           -0.075836    0.035700   -2.124249    0.072390     -1.047604
fincome_AT            0.069294    0.031682    2.187145    0.061032      1.135373
Numvehicles_AT        0.033309    0.043842    0.759750    0.082775      0.402408
age_TH               -0.018347    0.031497   -0.582518    0.059591     -0.307887
gender_TH             0.198359    0.055353    3.583488    0.097428      2.035945
marriage_TH          -0.077053    0.071841   -1.072556    0.130889     -0.588690
education_TH         -0.004962    0.023908   -0.207564    0.046671     -0.106326
workplace_TH         -0.008958    0.016442   -0.544840    0.030847     -0.290412
domicile_TH           0.112589    0.061300    1.836695    0.121905      0.923575
pincome_TH            0.040386    0.028932    1.395884    0.056361      0.716558
fincome_TH            0.050200    0.027415    1.831086    0.054949      0.913575
Numvehicles_TH       -0.165829    0.039087   -4.242560    0.079805     -2.077927
age_PS                0.143112    0.054323    2.634448    0.078642      1.819781
gender_PS             0.136555    0.093904    1.454195    0.149807      0.911539
marriage_PS          -0.032442    0.122363   -0.265130    0.181892     -0.178359
education_PS          0.171962    0.044608    3.854928    0.089541      1.920491
workplace_PS          0.188308    0.031766    5.928055    0.069186      2.721747
domicile_PS           0.205237    0.096240    2.132558    0.139697      1.469158
pincome_PS            0.133068    0.050265    2.647338    0.078489      1.695376
fincome_PS           -0.022893    0.045618   -0.501847    0.072078     -0.317619
Numvehicles_PS        0.129476    0.062954    2.056687    0.095644      1.353734
age_CIPI             -0.161916    0.035483   -4.563249    0.063580     -2.546627
gender_CIPI           0.097108    0.062243    1.560146    0.110092      0.882064
marriage_CIPI         0.249329    0.085911    2.902185    0.156900      1.589094
education_CIPI        0.162688    0.027470    5.922279    0.049273      3.301778
workplace_CIPI        0.097790    0.019134    5.110814    0.038491      2.540603
domicile_CIPI         0.064304    0.067418    0.953818    0.133101      0.483124
pincome_CIPI         -0.035856    0.034353   -1.043737    0.060954     -0.588239
fincome_CIPI          0.095322    0.031753    3.001962    0.058361      1.633329
Numvehicles_CIPI     -0.058082    0.047741   -1.216618    0.108117     -0.537219
age_BI               -0.002592    0.058583   -0.044237    0.066685     -0.038862
gender_BI            -0.129825    0.098631   -1.316265    0.104755     -1.239318
marriage_BI           0.133084    0.127935    1.040246    0.135714      0.980623
education_BI          0.093443    0.043579    2.144252    0.051978      1.797760
workplace_BI          0.114023    0.028759    3.964769    0.032935      3.462057
domicile_BI           0.021279    0.102021    0.208574    0.113288      0.187829
pincome_BI            0.048812    0.051952    0.939553    0.052424      0.931098
fincome_BI            0.023842    0.047499    0.501948    0.048805      0.488516
Numvehicles_BI     -1.7006e-04    0.065250   -0.002606    0.073601     -0.002311
b_LA_bus              0.002372    0.203033    0.011684    0.214346      0.011067
b_AR_bus             -0.184875    0.203281   -0.909456    0.250778     -0.737204
b_SN_bus             -0.011009    0.180454   -0.061006    0.167265     -0.065817
b_AT_bus             -0.263078    0.176472   -1.490763    0.190973     -1.377566
b_TH_bus              0.425801    0.185509    2.295309    0.185686      2.293126
b_PS_bus             -0.010953    0.205372   -0.053332    0.238698     -0.045886
b_CIPI_bus            0.284312    0.193157    1.471920    0.216118      1.315542
b_BI_bus             -0.027194    0.256236   -0.106128    0.301337     -0.090244
b_LA_noncar           0.121098    0.145819    0.830471    0.161834      0.748289
b_AR_noncar          -0.042746    0.143065   -0.298784    0.150325     -0.284355
b_SN_noncar           0.101069    0.128482    0.786641    0.140246      0.720655
b_AT_noncar          -0.137401    0.126830   -1.083348    0.143155     -0.959807
b_TH_noncar           0.110251    0.124578    0.884995    0.136500      0.807701
b_PS_noncar           0.183015    0.145399    1.258709    0.169731      1.078265
b_CIPI_noncar         0.088205    0.128484    0.686504    0.137334      0.642267
b_BI_noncar          -0.085065    0.160210   -0.530959    0.170799     -0.498040
b_LA_car              0.043122    0.136760    0.315316    0.152890      0.282049
b_AR_car             -0.316738    0.134836   -2.349064    0.134944     -2.347171
b_SN_car              0.021990    0.120155    0.183012    0.134294      0.163744
b_AT_car             -0.116481    0.123426   -0.943729    0.137727     -0.845734
b_TH_car              0.245223    0.118595    2.067731    0.122731      1.998055
b_PS_car             -0.036933    0.140525   -0.262820    0.174691     -0.211417
b_CIPI_car            0.049678    0.124879    0.397807    0.130131      0.381750
b_BI_car             -0.102071    0.159494   -0.639970    0.185248     -0.550998
stephanehess
Site Admin
Posts: 1355
Joined: 24 Apr 2020, 16:29

Re: HCM model rho square not applicable problem

Post by stephanehess »

Hi

rho2 is a metric for discrete choice. So if you use a continuous measurement model for your indicators, then rho2 cannot be calculated

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