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.

Nested Logit-location choice joint with mode utility

Ask questions about model specifications. Ideally include a mathematical explanation of your proposed model.
Post Reply
lucia
Posts: 3
Joined: 06 Apr 2022, 06:28

Nested Logit-location choice joint with mode utility

Post by lucia »

Dear Prof. Hess,

Thanks for your Apollo package!

I have encountered an issue with a nested logit mode framework using Apollo. For the nest logit mode structure, the upper level is the choice of the zones and zone alternatives, and the lower level is the utility of different travel modes. We have alternative-specific parameters (population & employment) and mode-specific parameters(beta for different travel modes).

I have two questions regarding the model. First, I estimated the mode without alternative specific variables (attached code file), and nesting parameters for two nests are always minus zero. I've tried searching for initial values for beta, but the nesting parameters become far from the range of (0-1). I've also tested increasing the maximum iterations; however, the nesting parameter results are still below zero.

The second question is, what would be the correct way to set alternative specific variables in the utility function? I've searched keywords in the forum but only found alternative specific constant examples. Please correct me if I missed the existing answers to this topic.

Thanks for your time!

The code I am testing is attached below:

library(apollo)

{
rm(list = ls())

apollo_initialise()

# #################################################################

#### LOAD DATA AND APPLY ANY TRANSFORMATIONS

# #################################################################

database = read.csv("E:\\...\\testmatrix.csv", header = TRUE)

apollo_control = list(
modelName ="Apollo_NL_Model",
modelDescr ="Two-level NL model ",
nCores = 1,
panelData=FALSE,
indivID = "ID"
)

apollo_beta=c(
asc_AutoPassen1 = 0,
asc_Rideshare1 = 0,
asc_PT1 = 0,
asc_AutoPassen2 = 0,
asc_Rideshare2 = 0,
asc_PT2 = 0,
asc_AutoPassen3 = 0,
asc_Rideshare3 = 0,
asc_PT3 = 0,
asc_AutoPassen4 = 0,
asc_Rideshare4 = 0,
asc_PT4 = 0,
#C_AutoPassUtil = 0,
#C_Rideshare = 0,
#C_PTUtil = 0,
#b_LogEmploy = -3,
#b_Logpop = -3,
lamda1 = 0.5,
lamda2 = 0.5,
lamda3 = 0.5,
lamda4 = 0.5
)


apollo_fixed =c()

apollo_inputs <- apollo_validateInputs()

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()

### List of utilities: these must use the same names as in nl_settings, order is irrelevant
V = list()

# Nest 1: alt1
V[['Auto1']] = 0


V[['Passenger1']] = asc_AutoPassen1
#b_LogEmploy*log(Employ1) + b_Logpop*log(Pop1)
#C_AutoPassUtil*Auto_util1

V[['Rideshare1']] = asc_Rideshare1
#b_LogEmploy*log(Employ1) + b_Logpop*log(Pop1)
# C_Rideshare*Auto_util1*0.8

V[['PT1']] = asc_PT1
#b_LogEmploy*log(Employ1) + b_Logpop*log(Pop1)
#C_PTUtil*PT_util1

#----------------------------------------------------------------------------------------------------
# Nest 2: alt2

V[['Auto2']] = 0


V[['Passenger2']] = asc_AutoPassen2
#b_LogEmploy*log(Employ2) + b_Logpop*log(Pop2)
#C_AutoPassUtil*Auto_util2

V[['Rideshare2']] = asc_Rideshare2
#b_LogEmploy*log(Employ2) + b_Logpop*log(Pop2)
# C_Rideshare*Auto_util2*0.8

V[['PT2']] = asc_PT2
#b_LogEmploy*log(Employ2) + b_Logpop*log(Pop2)
# C_PTUtil*PT_util2

#----------------------------------------------------------------------------------------------------
# Nest 3: alt3

V[['Auto3']] = 0

V[['Passenger3']] = asc_AutoPassen3
#b_LogEmploy*log(Employ3) + b_Logpop*log(Pop3) #+
#C_AutoPassUtil*Auto_util3

V[['Rideshare3']] = asc_Rideshare3
#b_LogEmploy*log(Employ3) + b_Logpop*log(Pop3) #+
#C_Rideshare*Auto_util3*0.8

V[['PT3']] = asc_PT3
#b_LogEmploy*log(Employ3) + b_Logpop*log(Pop3) #+
#C_PTUtil*PT_util3

### Specify nests for NL model

#----------------------------------------------------------------------------------------------------
# Nest 4: alt4

V[['Auto4']] = 0

V[['Passenger4']] = asc_AutoPassen4
#b_LogEmploy*log(Employ4) + b_Logpop*log(Pop4) #+
#C_AutoPassUtil*Auto_util4

V[['Rideshare4']] = asc_Rideshare4
#b_LogEmploy*log(Employ4) + b_Logpop*log(Pop4) #+
#C_Rideshare*Auto_util4*0.8

V[['PT4']] = asc_PT4
#b_LogEmploy*log(Employ4) + b_Logpop*log(Pop4) #+
#C_PTUtil*PT_util4

### Specify nests for NL model

nlNests = list(root = 1,
alt1 = lamda1,
alt2 = lamda2,
alt3 = lamda3,
alt4 = lamda4)

### Specify tree structure for NL model
nlStructure= list()
nlStructure[["root"]] = c("alt1","alt2","alt3","alt4")
nlStructure[["alt1"]] = c("Auto1","Passenger1","Rideshare1","PT1")
nlStructure[["alt2"]] = c("Auto2","Passenger2","Rideshare2","PT2")
nlStructure[["alt3"]] = c("Auto3","Passenger3","Rideshare3","PT3")
nlStructure[["alt4"]] = c("Auto4","Passenger4","Rideshare4","PT4")

# Define settings for NL model
nl_settings <- list(
alternatives = c(Auto1=1, Passenger1=2, Rideshare1=3, PT1=4,
Auto2=5, Passenger2=6, Rideshare2=7, PT2=8,
Auto3=9, Passenger3=10, Rideshare3=11, PT3=12,
Auto4=13, Passenger4=14, Rideshare4=15, PT4=16),

avail = 1, #always the first zone (alt1) being selected
choiceVar = modechoice,
V = V,
nlNests = nlNests,
nlStructure = nlStructure
)

### Compute probabilities using NL model

P[["model"]] = apollo_nl(nl_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)
}

estimate_settings <- list(maxIterations = 5000)

# #################################################################

#### MODEL ESTIMATION

# #################################################################

NLmodel = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
}

apollo_modelOutput(NLmodel)


The estimation results are as follows:
***** Singular convergence *****

Estimated parameters:
Estimate
asc_AutoPassen1 11.09500
asc_Rideshare1 7.07276
asc_PT1 -12.79277
asc_AutoPassen2 -10.56887
asc_Rideshare2 -0.74122
asc_PT2 -0.74122
asc_AutoPassen3 -0.75133
asc_Rideshare3 -0.75133
asc_PT3 -0.75133
asc_AutoPassen4 -0.75136
asc_Rideshare4 -0.75136
asc_PT4 -0.75136
lamda1 15.18385
lamda2 -0.15593
lamda3 0.06352
lamda4 0.06906

Final LL: -1340.4552

WARNING: Estimation failed. No covariance matrix to compute.

Current process will resume in 3 seconds unless interrupted by the user...

Nesting structure for model component :
Nest: root (1)
|-Nest: alt1 (15.1839)
| |-Alternative: Auto1
| |-Alternative: Passenger1
| |-Alternative: Rideshare1
| '-Alternative: PT1
|-Nest: alt2 (-0.1559)
| |-Alternative: Auto2
| |-Alternative: Passenger2
| |-Alternative: Rideshare2
| '-Alternative: PT2
|-Nest: alt3 (0.0635)
| |-Alternative: Auto3
| |-Alternative: Passenger3
| |-Alternative: Rideshare3
| '-Alternative: PT3
'-Nest: alt4 (0.0691)
|-Alternative: Auto4
|-Alternative: Passenger4
|-Alternative: Rideshare4
'-Alternative: PT4

WARNING: The nesting parameter for nest "alt1" should be between 0 and 1 (the nesting parameter for nest "root"), yet its value is 15.1839.
WARNING: The nesting parameter for nest "alt2" should be between 0 and 1 (the nesting parameter for nest "root"), yet its value is -0.1559.

Calculating log-likelihood at equal shares (LL(0)) for applicable models...
Calculating log-likelihood at observed shares from estimation data (LL(c)) for applicable models...
Calculating LL of each model component...
Calculating other model fit measures
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: Nested Logit-location choice joint with mode utility

Post by stephanehess »

Hi

I think the reason your model is not working at the moment is that you only have constants in the utilities, which makes it impossible to estimate a nesting structure

Regarding your second question, can you explain a bit more what you mean, please?

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