Error in apollo_modifyUserDefFunc(apollo_beta, apollo_fixed, apollo_probabilities)
Posted: 03 Nov 2022, 15:54
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
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