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.

Parameter b does not influence the log-likelihood of model

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
Post Reply
Chunyu Song
Posts: 5
Joined: 11 Aug 2022, 09:58

Parameter b does not influence the log-likelihood of model

Post by Chunyu Song »

Hi Stephane and David,

After trying to run such a model I get information that the parameter b_revisit_c1 does not influence the log-likelihood of my model. Can you check, please, where the problem could be?

Code: Select all

## scaled variables
apollo_beta = c(asc_car_c1 = 0,
                asc_taxi_c1 = 0,
                asc_bus_c1 = 0,
                asc_metro_c1 = 0,
                b_cost_c1 = 0,
                b_in_veh_c1 = 0,
                b_park_P_c1 = 0,
                b_park_A_c1 = 0,
                b_park_G_c1 = 0,
                b_wait_c1 = 0,
                b_walk_c1 = 0,
                b_transfer_c1 = 0,
                b_crowd_P_c1 = 0,
                b_crowd_A_c1 = 0,
                b_crowd_G_c1 = 0,
                b_carown_c1 = 0,
                b_carmode_c1 = 0,
                b_taximode_c1 = 0,
                b_PTmode_c1 = 0,
                b_green_PT_c1 = 0,
                b_revisit_c1=0,
                lambda_A_c1 = 1,
                lambda_B_c1 = 0.5,
                lambda_C_c1 = 1,
                delta_c1 = 0,
                gamma_education_c1=0,
                gamma_employ_c1=0,
                gamma_income_c1=0,
                gamma_purpose_c1=0,
                gamma_gender_c1=0,
                gamma_days_c1=0,
                gamma_age_c1=0,
                gamma_types_c1=0,
                asc_car_c2 = 0,
                asc_taxi_c2 = 0,
                asc_bus_c2 = 0,
                asc_metro_c2 = 0,
                b_cost_c2 = 0,
                b_in_veh_c2 = 0,
                b_park_P_c2 = 0,
                b_park_A_c2 = 0,
                b_park_G_c2 = 0,
                b_wait_c2 = 0,
                b_walk_c2 = 0,
                b_transfer_c2 = 0,
                b_crowd_P_c2 = 0,
                b_crowd_A_c2 = 0,
                b_crowd_G_c2 = 0,
                b_carown_c2 = 0,
                b_carmode_c2 = 0,
                b_taximode_c2 = 0,
                b_PTmode_c2 = 0,
                b_green_PT_c2 = 0,
                b_revisit_c2=0,
                lambda_A_c2 = 0.5,
                lambda_B_c2 = 1,
                lambda_C_c2 = 1,
                gamma_education_c2=0,
                gamma_employ_c2=0,
                gamma_income_c2=0,
                gamma_purpose_c2=0,
                gamma_gender_c2=0,
                gamma_days_c2=0,
                gamma_age_c2=0,
                gamma_types_c2=0,
                delta_c2 = 0)
apollo_fixed = c("asc_car_c1","asc_car_c2","delta_c2","gamma_education_c2","gamma_employ_c2","gamma_income_c2","gamma_purpose_c2","gamma_gender_c2","gamma_days_c2","gamma_age_c2","gamma_types_c2","b_crowd_P_c1","b_crowd_P_c2","b_park_P_c1","b_park_P_c2","lambda_A_c1","lambda_C_c1","lambda_B_c2","lambda_C_c2")
#"lambda_A_c1","lambda_A_c2"



## Define latent class components
apollo_lcPars = function(apollo_beta, apollo_inputs){
  lcpars = list()
  lcpars[["b_cost"]] = list(b_cost_c1,b_cost_c2)
  lcpars[["b_in_veh"]] = list(b_in_veh_c1,b_in_veh_c2)
  lcpars[["b_park_P"]] = list(b_park_P_c1,b_park_P_c2)
  lcpars[["b_park_A"]] = list(b_park_A_c1,b_park_A_c2)
  lcpars[["b_park_G"]] = list(b_park_G_c1,b_park_G_c2)
  lcpars[["b_wait"]] = list(b_wait_c1,b_wait_c2)
  lcpars[["b_walk"]] = list(b_walk_c1, b_walk_c2)
  lcpars[["b_transfer"]] = list(b_transfer_c1, b_transfer_c2)
  lcpars[["b_crowd_P"]] = list(b_crowd_P_c1,b_crowd_P_c2)
  lcpars[["b_crowd_A"]] = list(b_crowd_A_c1,b_crowd_A_c2)
  lcpars[["b_crowd_G"]] = list(b_crowd_G_c1,b_crowd_G_c2)
  lcpars[["asc_taxi"]] = list(asc_taxi_c1,asc_taxi_c2)
  lcpars[["asc_bus"]] = list(asc_bus_c1,asc_bus_c2)
  lcpars[["asc_metro"]] = list(asc_metro_c1,asc_metro_c2)
  lcpars[["b_carown"]] = list(b_carown_c1,b_carown_c2)
  lcpars[["b_carmode"]] = list(b_carmode_c1,b_carmode_c2)
  lcpars[["b_taximode"]] = list(b_taximode_c1,b_taximode_c2)
  lcpars[["b_PTmode"]] = list(b_PTmode_c1,b_PTmode_c2)
  lcpars[["b_green_PT"]] = list(b_green_PT_c1,b_green_PT_c2)
  lcpars[["b_revisit"]] = list(b_revisit_c1,b_revisit_c2)
  
  
  #Utilities of class allocation model
  V = list()
  V[["class_1"]] = delta_c1+ gamma_education_c1* education+ gamma_employ_c1* employ+ gamma_income_c1* income +gamma_purpose_c1*purpose+ gamma_gender_c1*gender+gamma_days_c1*days+gamma_age_c1*age+gamma_types_c1*types
  V[["class_2"]] = delta_c2+ gamma_education_c2* education+ gamma_employ_c2* employ+ gamma_income_c2* income +gamma_purpose_c2*purpose+ gamma_gender_c2*gender+gamma_days_c2*days+gamma_age_c2*age+gamma_types_c2*types

  


  
  
  classAlloc_settings = list(
    classes      = c(class_1=1, class_2=2), 
    utilities    = V
  )
  
  lcpars[["pi_values"]] = apollo_classAlloc(classAlloc_settings)
  
  return(lcpars)
}

#V[["class_1"]] = delta_c1 + gamma_gender_c1 * gender
#V[["class_2"]] = delta_c2 + gamma_gender_c2 * gender

### 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()
 
  ### Specify nests for NL model
  nlNests = list()
  nlNests[[1]] = list(root=1, A_c1=lambda_A_c1, B_c1 = lambda_B_c1, C_c1 = lambda_C_c1)
  nlNests[[2]] = list(root=1,A_c2=lambda_A_c2, B_c2 = lambda_B_c2, C_c2 = lambda_C_c2)

  
  nlStructure = list()
  nlStructure[[1]] = list()
  nlStructure[[2]] = list()
 
  
  nlStructure[[1]][["root"]] = c("A_c1","B_c1","C_c1")
  nlStructure[[2]][["root"]] = c("A_c2","B_c2","C_c2")

  
  
  nlStructure[[1]][["A_c1"]] = c("bus")
  nlStructure[[1]][["B_c1"]] = c("car","metro")
  nlStructure[[1]][["C_c1"]] = c("taxi")
  


  nlStructure[[2]][["A_c2"]] = c("car","bus")
  nlStructure[[2]][["B_c2"]] = c("taxi")
  nlStructure[[2]][["C_c2"]] = c("metro")
  
  nl_settings <- list(
    alternatives = c(car=1, taxi=2, bus=3, metro=4),
    avail = list(car=av_car, taxi=av_taxi, bus=av_bus, metro=av_metro),
    choiceVar = choice,
    nlNests = nlNests,
    nlStructure = nlStructure
  )
  
  
  
  ### Loop over classes
  s=1
  while(s<=2){
    ### Compute class-specific utilities
    V=list()
    V[['car']] =                    b_cost[[s]] * cost_car +     b_crowd_A[[s]] * (crowd_car==2) +b_crowd_G[[s]] * (crowd_car==3) +     b_in_veh[[s]] * in_veh_car     + b_park_A[[s]] * (park_car==2)+ b_park_G[[s]] * (park_car==3)                                                                                                     + b_carown[[s]] * (carown==1)   + b_carmode[[s]] * (mianmode==1)  + b_revisit[[s]] * (times==1)                                                                       
    V[['taxi']] = asc_taxi[[s]]   + b_cost[[s]] * cost_taxi +    b_crowd_A[[s]] * (crowd_taxi==2) +b_crowd_G[[s]] * (crowd_taxi==3) +    b_in_veh[[s]] * in_veh_taxi +    b_wait[[s]] * wait_taxi                                                                                                                                       + b_taximode[[s]] * (mianmode==2)  + b_revisit[[s]] * (times==1)                                   
    V[['bus']] =  asc_bus[[s]]   +  b_cost[[s]] * cost_bus +     b_crowd_A[[s]] * (crowd_bus==2) +b_crowd_G[[s]] * (crowd_bus==3) +     b_in_veh[[s]] * in_veh_bus +     b_wait[[s]] * wait_bus   +  b_walk[[s]] * walk_bus   +  b_transfer[[s]] * transfer_bus       +b_green_PT[[s]] * (green==1)                                      + b_PTmode[[s]] * (mianmode==3)   + b_revisit[[s]] * (times==1)   
    V[['metro']] =  asc_metro[[s]] +b_cost[[s]] * cost_metro +   b_crowd_A[[s]] * (crowd_metro==2) +b_crowd_G[[s]] * (crowd_metro==3) +   b_in_veh[[s]] * in_veh_metro+    b_wait[[s]] * wait_metro +  b_walk[[s]] * walk_metro +  b_transfer[[s]] * transfer_metro +b_green_PT[[s]] * (green==1)                                      + b_PTmode[[s]] * (mianmode==3)     + b_revisit[[s]] * (times==1) 
    nl_settings$V = V
    nl_settings$nlNests = nlNests[[s]]
    nl_settings$nlStructure = nlStructure[[s]]
    P[[s]] = apollo_nl(nl_settings, functionality)
    P[[s]] = apollo_panelProd(P[[s]],apollo_inputs,functionality)
    
    s=s+1
  }
  lc_settings = list(inClassProb = P, classProb=pi_values)
  P[["model"]] = apollo_lc(lc_settings,apollo_inputs,functionality)
  
  
  ### Prepare and return outputs of function
  P = apollo_prepareProb(P, apollo_inputs, functionality)
  return(P)
}

#apollo_control$worklnLogs=TRUE
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities,apollo_inputs)
apollo_modelOutput(model,modelOutput_settings = list(printPVal=TRUE))
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: Parameter b does not influence the log-likelihood of model

Post by stephanehess »

Hi

apologies for the slow reply, David and I have been away.

Your model is not identified. You have included

Code: Select all

+ b_revisit[[s]] * (times==1) 
in all utility functions. Only differences in utility matter, so this term would drop out

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