Page 1 of 1

Bayesian estimation of a 2 level nested logit estimated using bayesian estimation

Posted: 03 Sep 2024, 18:17
by TCEagle
Dear team,

I am confused a bit on how to set up the apollo_probabilities function to fit a 2 level nested logit model using Bayesian estimation (through Apollo's call to RSGHB routines). In RSGHB we have to write out the logsum formulas and the nest probabilities and the within nest probabilities expressions. In Apollo do I simply use the same expressions used in the NL_two_levels.r code? Using a highly simplified version of the utility functions...

V=list()
V[["car"]] = asc_car + b_tt_car * time_car + b_cost * cost_car
V[["bus"]] = asc_bus + b_tt_bus * time_bus + b_access * access_bus + b_cost * cost_bus
V[["air"]] = asc_air + b_tt_air * time_air + b_access * access_air + b_cost * cost_air
V[["rail"]] = asc_rail + b_tt_rail * time_rail + b_access * access_rail + b_cost * cost_rail

### Specify nests for NL model
nlNests = list(root=1,
PT=lambda_PT)

### Specify tree structure for NL model
nlStructure= list()
nlStructure[["root"]] = c("car","PT")
nlStructure[["PT"]] = c("bus","air","rail")

### Define settings for NL model
nl_settings <- list(
alternatives = c(car=1, bus=2, air=3, rail=4),
avail = list(car=av_car, bus=av_bus, air=av_air, rail=av_rail),
choiceVar = choice,
utilities = V,
nlNests = nlNests,
nlStructure = nlStructure
)

### Compute probabilities using MNL 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)

This seems to run, but I am not sure it is right. Is this correct, or do I need to write out my own logum expressions, etc. as I would if using RSGHB? If I have to write out all the losum etc., expression as I do in RSGHB, do I still have to call a P[["model"]] ? if so should that be P[["model"]] = apollo_mnl(mnl_settings, functionality) or something else..

Thank you in advance for your help!

Tom Eagle

Re: Bayesian estimation of a 2 level nested logit estimated using bayesian estimation

Posted: 04 Sep 2024, 00:47
by stephanehess
Hi Tom

what you do is correct. Apollo uses exactly the same code for classical and Bayesian estimation (except dropping the panel prod for the latter, as you have already done). It then prepares everything internally for using RSGHB

Best wishes

Stephane

Re: Bayesian estimation of a 2 level nested logit estimated using bayesian estimation

Posted: 04 Sep 2024, 00:57
by TCEagle
Thank you Stephane. I really appreciate your help.

Tom