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.

Cross-nested specification

Ask questions about model specifications. Ideally include a mathematical explanation of your proposed model.
Post Reply
jbas
Posts: 6
Joined: 18 Feb 2021, 10:57

Cross-nested specification

Post by jbas »

Hi,

I'm finding trouble in estimating a CNL specification that is slighlty different than that shown in the examples.
In Apollo_example_6.r, as the manual explains, there are three nests; One for air and rail, One of Bus and Rail, and one in which Car is all alone. Since car is on its own, the nesting parameter for the car nest is set to 1.

Well, my nesting structure is different, I have four alternatives: Car, Bike, Walk, Other; and I'd like to put in nest1 Car and Other, while in nest2 Bike, Walk, and Other. For that, I wrote:

Code: Select all

 ### Specify nests for CNL model
  cnlNests = list(motor=lambda_motor, nomotor=lambda_nomotor) 

  ### Specify nest allocation parameters for alternatives included in multiple nests
  alpha_other_motor   = exp(alpha0_other_motor)/(exp(alpha0_other_motor) + exp(alpha0_other_nomotor))
  alpha_other_nomotor = 1 - alpha_other_motor
  
  
  ### Specify tree structure, showing membership in nests (one row per nest, one column per alternative)
  cnlStructure      = matrix(0, nrow=length(cnlNests), ncol=length(V))
  cnlStructure[1,] = c( 0,  0, 1, alpha_other_motor  ) 
  cnlStructure[2,] = c( 1,  0, 0, alpha_other_nomotor) 
  
  
  ### Define settings for NL model
  cnl_settings <- list(
    alternatives = c(car=1, bike=2, walk=3, other=4),
    avail        = list(car=av_car, bike=av_bike, walk=av_walk, other=av_other),
    choiceVar    = CHOICE,
    V            = V,
    cnlNests      = cnlNests,
    cnlStructure  = cnlStructure
  )
  
Note that I have changed three things with respect to the example:
- I removed 'car=1' in cnlNests, and not replaced with any other alternative since there is no nest with one only alternative
- Removed cnlStructure[2] since there is no third nest
- Switch the '1' in cnlStructure[2,] from the second to the first position.

Is this structure correct? When I code it like this, apollo_estimates throws the error:
Error in apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, : Log-likelihood calculation fails at values close to the starting values!.
However, no matter the starting values, it always gives that error. That's why I thought the problem is in the nesting structure.

Thanks for your help.

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

Re: Cross-nested specification

Post by stephanehess »

Hi

in your model, you are not including bike in any nest as the second column in cnlStructure is just 0.

Apollo should give a different error message here, and we will fix that

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