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 of Specification Issue - Parameter doesnt influence the log-likelihood of your model

Ask questions about model specifications. Ideally include a mathematical explanation of your proposed model.
Post Reply
rahardiantot
Posts: 2
Joined: 16 Jun 2023, 20:40

Error of Specification Issue - Parameter doesnt influence the log-likelihood of your model

Post by rahardiantot »

Dear developers,

I want to use "Simple MNL model on mode choice SP data" to do estimation. Below is the code and I got following error:

Testing influence of parameters.............................Error in apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, :
SPECIFICATION ISSUE - Parameter b_drizzle does not influence the log-likelihood of your model!

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       = "MNL_RP_SP",
  modelDescr      = "Simple MNL model on mode choice SP data",
  indivID         = "ID", 
  outputDirectory = "/Users/rahardiantotripradipta/Downloads/thesis-sprp"
)

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

### Loading data from package
### if data is to be loaded from a file (e.g. called data.csv), 
### the code would be: database = read.csv("data.csv",header=TRUE)
database = read.csv("/Users/rahardiantotripradipta/Downloads/4. Apollo_SP_Tesis_income_weather_ori.csv", header=TRUE)
### for data dictionary, use ?apollo_modeChoiceData

### Use only SP data
database = subset(database,database$SP==1)

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

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(asc_mc       = 0,
              asc_car      = 0,
              asc_ojek     = 0,
              asc_taxi     = 0,
              asc_bus      = 0,
              asc_angkot   = 0,
              asc_car_shift_female = 0,
              asc_ojek_shift_female = 0,
              asc_taxi_shift_female = 0,
              asc_bus_shift_female = 0,
              asc_angkot_shift_female = 0,
              b_tt_mc                 = 0,
              b_tt_car                = 0,
              b_tt_ojek               = 0,
              b_tt_taxi                = 0,
              b_tt_bus                = 0,
              b_tt_angkot             = 0,
              b_tt_shift_facilities   = 0,
              b_cost_mc                 = 0,
              b_cost_car                = 0,
              b_cost_ojek               = 0,
              b_cost_taxi                = 0,
              b_cost_bus                = 0,
              b_cost_angkot             = 0,
              b_waitingtime_ojek           = 0,
              b_waitingtime_taxi           = 0,
              b_waitingtime_bus           = 0,
              b_waitingtime_angkot           = 0,
              b_park_mc                  = 0,
              b_park_car                  = 0,
              b_sunny                  = 0,
              b_drizzle                 = 0,
              b_rain                  = 0)

### 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_mc","b_sunny")

# ################################################################# #
#### 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()
  
  ### Create alternative specific constants and coefficients using interactions with socio-demographics and weather
  asc_car_value       = asc_car + asc_car_shift_female * female
  asc_ojek_value      = asc_ojek + asc_ojek_shift_female * female
  asc_taxi_value      = asc_taxi + asc_taxi_shift_female * female
  asc_bus_value       = asc_bus + asc_bus_shift_female * female
  asc_angkot_value    = asc_angkot + asc_angkot_shift_female * female
  b_tt_bus_value      = b_tt_bus + b_tt_shift_facilities * facilities
  b_tt_angkot_value   = b_tt_angkot + b_tt_shift_facilities * facilities
  
  ### List of utilities: these must use the same names as in mnl_settings, order is irrelevant
  V = list()
  V[["mc"]]      = asc_mc            + b_tt_mc           * time_mc       + b_cost_mc     * cost_mc       + b_park_mc * park_mc                          + b_sunny * ( weather == 1 ) + b_drizzle * ( weather == 2 ) + b_rain * ( weather == 3 ) 
  V[["car"]]     = asc_car_value      + b_tt_car          * time_car      + b_cost_car    * cost_car      + b_park_car * park_car                       + b_sunny * ( weather == 1 ) + b_drizzle * ( weather == 2 ) + b_rain * ( weather == 3 ) 
  V[["ojek"]]    = asc_ojek_value    + b_tt_ojek         * time_ojek     + b_cost_ojek   * cost_ojek     + b_waitingtime_ojek * waitingtime_ojek        + b_sunny * ( weather == 1 ) + b_drizzle * ( weather == 2 ) + b_rain * ( weather == 3 ) 
  V[["taxi"]]    = asc_taxi_value     + b_tt_taxi         * time_taxi     + b_cost_taxi   * cost_taxi    + b_waitingtime_taxi * waitingtime_taxi        + b_sunny * ( weather == 1 )  + b_drizzle * ( weather == 2 ) + b_rain * ( weather == 3 )
  V[["bus"]]     = asc_bus_value     + b_tt_bus_value    * time_bus      + b_cost_bus    * cost_bus      + b_waitingtime_bus * waitingtime_bus          + b_sunny * ( weather == 1 ) + b_drizzle * ( weather == 2 ) + b_rain * ( weather == 3 ) 
  V[["angkot"]]  = asc_angkot_value  + b_tt_angkot_value * time_angkot   + b_cost_angkot * cost_angkot   + b_waitingtime_angkot * waitingtime_angkot    + b_sunny * ( weather == 1 ) + b_drizzle * ( weather == 2 ) + b_rain * ( weather == 3 )

  ### Define settings for MNL model component
  mnl_settings = list(
    alternatives  = c(mc=1, car=2, ojek=3, taxi=4, bus=5, angkot=6), 
    avail         = list(mc=av_mc, car=av_car, ojek=av_ojek, taxi=av_taxi, bus=av_bus, angkot=av_angkot), 
    choiceVar     = choice, 
    utilities     = V
  )
  
  ### Compute probabilities using MNL model
  P[["model"]] = apollo_mnl(mnl_settings, functionality)
  
  ### Take product across observation for same individual
  P = apollo_panelProd(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(model)

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

apollo_saveOutput(model)

Do you have any suggestions to solve this error? Thank you very much in advance for your help

Best regards,
Rahardianto
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: Error of Specification Issue - Parameter doesnt influence the log-likelihood of your model

Post by stephanehess »

Hi

only differences in utility matter.

So if you include

Code: Select all

b_drizzle * ( weather == 2 )
in every utility function, it will just drop out

What you probably want to do is to use separate coefficients for this for each alternative, fixing the coefficient to zero for one of them

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
rahardiantot
Posts: 2
Joined: 16 Jun 2023, 20:40

Re: Error of Specification Issue - Parameter doesnt influence the log-likelihood of your model

Post by rahardiantot »

Hi Prof. Hess,

Thank you for your recommendation, but i have question regarding to "fix the coefficient to zero for one utility". Which should I set to fix (zero)? Are there any considerations that I should pay attention to to determine this?

Best regards,
Rahardianto
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: Error of Specification Issue - Parameter doesnt influence the log-likelihood of your model

Post by stephanehess »

What you will need is separate coefficients by mode, say b_sunny_mc, b_sunny_car, etc. And include one of those in apollo_fixed. As you're using a model without random heterogeneity, it doesn't matter which one you fix
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Post Reply