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)
Best regards,
Rahardianto