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.

Three-levels NL model, utility equation

Ask questions about existing examples and put in requests to software developers and users for other example implementations of models.
Post Reply
kkkkk
Posts: 1
Joined: 09 Dec 2023, 07:03

Three-levels NL model, utility equation

Post by kkkkk »

Dear authors,

I am applying nested-logit model recently and have read the examples on your website. http://www.apollochoicemodelling.com/fi ... e_levels.r

The example is quite clear. But I don't know how to write the code if I want to add utilities specific to nests, which is named Wnk in the chapter of DISCRETE CHOICE METHODS WITH SIMULATION:
4.2.3. Decomposition into Two
Logits Expression (4.2) is not very illuminating as a formula. However, the choice probabilities can be expressed in an alternative fashion that is quite simple and readily interpretable. Without loss of generality, the observed component of utility can be decomposed into two parts: (1) a part labeled W that is constant for all alternatives within a nest, and (2) a part labeled Y that varies over alternatives within a nest. Utility is written as
(4.3) Unj = Wnk + Ynj + εnj
for j ∈ Bk, where:
Wnk depends only on variables that describe nest k. These variables differ over nests but not over alternatives within each nest.
Ynj depends on variables that describe alternative j. These variables vary over alternatives within nest k.
To speak specifically, suppose a variable pa, referring to "the Parking accessibility in the neighborhood" . pa influences choice between nest "car"(a degenerate nest) and "PT". Then how to write the utility equation with the nest specific utility( 𝛽 * pa ) ?

Here is the code in your example, with no nest specific utility.

Code: Select all

### List of utilities: these must use the same names as in nl_settings, order is irrelevant
  V = list()
  V[["car"]]  = asc_car        + b_tt_car_value  * time_car                           + b_cost_value * cost_car
  V[["bus"]]  = asc_bus_value  + b_tt_bus_value  * time_bus  + b_access * access_bus  + b_cost_value * cost_bus 
  V[["air"]]  = asc_air_value  + b_tt_air_value  * time_air  + b_access * access_air  + b_cost_value * cost_air   + b_no_frills * ( service_air == 1 )  + b_wifi * ( service_air == 2 )  + b_food * ( service_air == 3 )
  V[["rail"]] = asc_rail_value + b_tt_rail_value * time_rail + b_access * access_rail + b_cost_value * cost_rail  + b_no_frills * ( service_rail == 1 ) + b_wifi * ( service_rail == 2 ) + b_food * ( service_rail == 3 )
  
  ### Specify nests for NL model
  nlNests      = list(root=1, PT=lambda_PT, fastPT=lambda_fastPT)
  
  ### Specify tree structure for NL model
  nlStructure= list()
  nlStructure[["root"]]   = c("car","PT")
  nlStructure[["PT"]]     = c("bus","fastPT")
  nlStructure[["fastPT"]] = c("air","rail")
I will be very grateful if you can help with this question.

Best regards,

Kathy
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: Three-levels NL model, utility equation

Post by stephanehess »

Kathy

apologies for the slow reply, David and I have been away.

There is no specific provision in Apollo for nest-specific utilities, but you can add those parts into the utilities for each of the alternatives in the nest

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