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 apollo_modifyUserDefFunc(apollo_beta, apollo_fixed, apollo_probabilities)

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
Post Reply
Shan
Posts: 12
Joined: 14 May 2020, 17:38

Error in apollo_modifyUserDefFunc(apollo_beta, apollo_fixed, apollo_probabilities)

Post by Shan »

Dear Sir,

I hope you are doing well. I would like to estimate income effects in my simple MNL model. However, when running the codes, R reported an error indicating that a parameter (b_fare_bus) from apollo_beta was re-defined inside apollo_probabilities, which is not allowed. I have checked my codes with the example ones, but I could not find out where my problem is. Could you please help me find out? Part of my codes is as follows.

### Vector of parameters:
apollo_beta = c(asc_car = 0,
asc_bus = 0,
asc_metro = 0,
b_fuel_CNG = 0,
b_fuel_electricity = 0,
b_access_bus = 0,
b_access_metro = 0,
b_freq_bus = 0,
b_freq_metro = 0,
b_egress_bus = 0,
b_egress_metro = 0,
b_seat_all_bus = 0,
b_seat_all_metro = 0,
b_seat_half_bus = 0,
b_seat_half_metro = 0,
b_seat_half = 0,
b_seat_no = 0,
b_tt_car = 0,
b_tt_bus = 0,
b_tt_metro = 0,
b_fare_bus = 0,
b_fare_bus_shift_female = 0,
fare_bus_income_elast = 0,
b_fare_metro = 0,
b_fare_metro_shift_female = 0,
fare_metro_income_elast = 0,
b_fuelcost = 0,
b_fuelcost_shift_female = 0,
fuelcost_income_elast = 0,
b_parking = 0)

### Parameters to be kept fixed at their starting value in apollo_beta:
apollo_fixed = c("asc_car", "b_fuel_CNG", "b_seat_no")

# ################################################################# #
#### 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 a list of probabilities P
P = list()

### Create coefficients with interactions with socio-demographics
b_fare_bus= (b_fare_bus + b_fare_bus_shift_female * female) * (income/mean_income) ^ fare_bus_income_elast
b_fare_metro= (b_fare_metro + b_fare_metro_shift_female * female) * (income/mean_income) ^ fare_metro_income_elast
b_fuelcost= (b_fuelcost + b_fuelcost_shift_female * female) * (income/mean_income) ^ fuelcost_income_elast
stephanehess
Site Admin
Posts: 1042
Joined: 24 Apr 2020, 16:29

Re: Error in apollo_modifyUserDefFunc(apollo_beta, apollo_fixed, apollo_probabilities)

Post by stephanehess »

Hi

you have e.g.

Code: Select all

b_fare_bus= (b_fare_bus + b_fare_bus_shift_female * female) * (income/mean_income) ^ fare_bus_income_elast
so you are redefining b_fare_bus, as it appears on the left and right hand side. The easy solution is to instead use something like:

Code: Select all

b_fare_bus= (b_fare_bus_base + b_fare_bus_shift_female * female) * (income/mean_income) ^ fare_bus_income_elast
so b_fare_bus_base is the estimated parameter, and b_fare_bus is used inside the utilities, and is given by the combination across parameters

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