I wanted to do a multinomial logit model for travel mode choice on my dataset.
1- When I want to estimate alternate specific constants, the results are strange and the errors are too big.
2-Also, the sign of the beta parameter for the "bus_cost" variable is positive. But a positive sign does not make sense, since as the price of the bus increases, the utility of it should decrease. The standard error of this variable is also too big.
I would be so thankful if you could help me with these issues.
Code: Select all
library(tidyverse)
library(apollo)
library(haven)
apollo_initialise()
apollo_control = list(
modelName ="Model_MNL",
modelDescr ="Mode",
indivID ="id",
)
tbl <- read_csv("Travel_Mode.csv")
database <- as.data.frame(tbl)
apollo_beta = c(asc_DR = 0, asc_RI = 0, asc_WA= 0, asc_BUS = 0,A_drive_time=0, B_ride_time=0,A_Car=0, A_driving_Freq=0, C_walk_time=0, C_disability=0, C_accessibility=0, D_bus_cost=0 ,D_bus_time=0)
apollo_fixed = c()
apollo_inputs = apollo_validateInputs()
apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))
V = list()
V[["DR"]] = asc_DR+A_drive_time * drive_time + A_driving_Freq * driving_Freq+A_Car*Car
V[["RI"]] = asc_RI+B_ride_time * ride_time
V[["WA"]] = asc_WA+ C_walk_time*walk_time+ C_disability*disability+ C_accessibility*accessibility
V[["BUS"]] =asc_BUS+D_bus_cost* bus_cost+ C_disability*disability+ D_bus_time*bus_time
mnl_settings = list(
alternatives = c(DR = 1, RI = 2, WA = 3, BUS=4),
avail = list(DR=av_drive, RI=av_ride, WA=av_walk, BUS=av_bus),
choiceVar = CHOICE,
V = V)
P = list()
P[['model']] = apollo_mnl(mnl_settings, functionality)
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
model = apollo_estimate(apollo_beta,
apollo_fixed,
apollo_probabilities,
apollo_inputs)
apollo_modelOutput(model)
Code: Select all
Code: Select all
Overview of choices for MNL model component :
DR RI WA BUS
Times available 112.00 153.00 153.0 132.00
Times chosen 81.00 39.00 13.0 20.00
Percentage chosen overall 52.94 25.49 8.5 13.07
Percentage chosen when available 72.32 25.49 8.5 15.15
Pre-processing likelihood function...
Testing influence of parameters.............
Starting main estimation
Initial function value: -193.9134
Initial gradient value:
asc_DR asc_RI asc_WA asc_BUS A_drive_time B_ride_time A_Car A_driving_Freq C_walk_time C_disability
51.500000 -4.666667 -30.666667 -16.166667 492.833333 8.166667 54.500000 106.500000 -2953.583333 -20.166667
C_accessibility D_bus_cost D_bus_time
-10.916667 -19.362500 -985.250000
initial value 193.913400
iter 2 value 160.614390
iter 3 value 155.379730
iter 4 value 152.266863
iter 5 value 135.999335
iter 6 value 130.210627
iter 7 value 99.115257
iter 8 value 97.028935
iter 9 value 89.862081
iter 10 value 88.633905
iter 11 value 85.650116
iter 12 value 83.836349
iter 13 value 79.105769
iter 14 value 78.484469
iter 15 value 77.885079
iter 16 value 77.594341
iter 17 value 77.393871
iter 18 value 77.375799
iter 19 value 77.372847
iter 20 value 77.372618
iter 21 value 77.371617
iter 22 value 77.370698
iter 23 value 77.370255
iter 24 value 77.370152
iter 25 value 77.370134
iter 26 value 77.370130
iter 26 value 77.370130
iter 26 value 77.370130
final value 77.370130
converged
Additional convergence test using scaled estimation. Parameters will be scaled by their current estimates and additional iterations will be
performed.
initial value 77.370130
iter 1 value 77.370130
final value 77.370130
converged
Estimated parameters:
Estimate
asc_DR -2.24667
asc_RI 1.27761
asc_WA 2.58634
asc_BUS -1.61726
A_drive_time -0.08235
B_ride_time -0.14189
A_Car 1.31058
A_driving_Freq 2.90470
C_walk_time -0.09854
C_disability -0.45844
C_accessibility 0.29397
D_bus_cost 3.43610
D_bus_time -0.08302
Computing covariance matrix using analytical gradient.
0%....25%....50%....75%..100%
WARNING: Some eigenvalues of the Hessian are positive, indicating convergence to a saddle point!
Computing score matrix...
Calculating LL(0) for applicable models...
Calculating LL(c) for applicable models...
Calculating LL of each model component...
Warning messages:
1: In sqrt(diag(varcov)) : NaNs produced
2: In sqrt(diag(robvarcov)) : NaNs produced
> apollo_modelOutput(model)
Model run using Apollo for R, version 0.2.6 on Windows by Aria
www.ApolloChoiceModelling.com
Model name : Model_MNL
Model description: mode
Model run at : 2021-11-27 20:16:00
Estimation method: bfgs
Model diagnosis : successful convergence
Number of individuals : 153
Number of rows in database: 153
Number of modelled outcomes: 153
Number of cores used: 1
Model without mixing
LL(start) : -193.9134
LL(0): -193.9134
LL(C) : -135.2653
LL(final) : -77.37013
Rho-square (0): 0.601
Adj.Rho-square (0) : 0.534
Rho-square (C) : 0.428
Adj.Rho-square (C) : 0.3319
AIC: 180.74
BIC : 220.14
Estimated parameters : 13
Time taken (hh:mm:ss): 00:00:0.63
pre-estimation: 00:00:0.32
estimation : 00:00:0.13
post-estimation : 00:00:0.18
Iterations: 29
Min abs eigenvalue of Hessian: 0
Unconstrained optimisation.
Estimates:
Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0)
asc_DR -2.24667 NaN NaN 1514.64745 -0.001483
asc_RI 1.27761 NaN NaN 857.82632 0.001489
asc_WA 2.58634 NaN NaN NaN NaN
asc_BUS -1.61726 NaN NaN 882.69570 -0.001832
A_drive_time -0.08235 0.13677 -0.6021 0.11548 -0.713120
B_ride_time -0.14189 0.11921 -1.1902 0.11128 -1.275021
A_Car 1.31058 1.01159 1.2956 0.99761 1.313721
A_driving_Freq 2.90470 0.64540 4.5006 0.57781 5.027062
C_walk_time -0.09854 0.02911 -3.3848 0.03414 -2.886562
C_disability -0.45844 0.54796 -0.8366 0.54898 -0.835077
C_accessibility 0.29397 0.75147 0.3912 0.75926 0.387174
D_bus_cost 3.43610 3.66049 0.9387 1.71946 1.998361
D_bus_time -0.08302 0.03483 -2.3839 0.03557 -2.333819
Code: Select all