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. We check the forum at least twice a week. It may thus take a couple of days for your post to appear and before we reply. There is no need to submit the post multiple times.

Mixed Logit - elasticities

Ask questions about post-estimation functions (e.g. prediction, conditionals, etc) or other processing of results.
Post Reply
katya2727
Posts: 4
Joined: 17 Jul 2024, 19:49

Mixed Logit - elasticities

Post by katya2727 »

Hello Prof. Hess and Prof. Palma,

I have a question regarding elasticities for the mixed logit model. Is it possible to use the part of the code below from MNL_SP_covariates.r to find elasticities for the mixed logit model? The formulas of relative probabilities are quite different in MNL and mixed logit as mixed logit does not follow the IIA assumption, so I was wondering we need to somehow account for that when calculating elasticities.

Thank you for all your work!

Best,
Katya

# ----------------------------------------------------------------- #
#---- MODEL PREDICTIONS AND ELASTICITY CALCULATIONS ----
# ----------------------------------------------------------------- #

### Use the estimated model to make predictions
predictions_base = apollo_prediction(model, apollo_probabilities, apollo_inputs, prediction_settings=list(runs=30))

### Now imagine the cost for rail increases by 1%
database$cost_rail = 1.01*database$cost_rail

### Rerun predictions with the new data
apollo_inputs = apollo_validateInputs()
predictions_new = apollo_prediction(model, apollo_probabilities, apollo_inputs)

### Return to original data
database$cost_rail = 1/1.01*database$cost_rail
apollo_inputs = apollo_validateInputs()

### work with predictions at estimates
predictions_base=predictions_base[["at_estimates"]]

### Compute change in probabilities
change=(predictions_new-predictions_base)/predictions_base

### Not interested in chosen alternative now, so drop last column
change=change[,-ncol(change)]

### First two columns (change in ID and task) also not needed
change=change[,-c(1,2)]

### Look at first individual
change[database$ID==1,]

### And person 9, who has all 4 modes available
change[database$ID==9,]

### Summary of changes (possible presence of NAs for unavailable alternatives)
summary(change)

### Look at mean changes for subsets of the data, ignoring NAs
colMeans(change,na.rm=TRUE)
colMeans(subset(change,database$business==1),na.rm=TRUE)
colMeans(subset(change,database$business==0),na.rm=TRUE)
colMeans(subset(change,(database$income<quantile(database$income,0.25))),na.rm=TRUE)
colMeans(subset(change,(database$income>=quantile(database$income,0.25))|(database$income<=quantile(database$income,0.75))),na.rm=TRUE)
colMeans(subset(change,(database$income>quantile(database$income,0.75))),na.rm=TRUE)

### Compute own elasticity for rail:
log(sum(predictions_new[,6])/sum(predictions_base[,6]))/log(1.01)

### Compute cross-elasticities for other modes
log(sum(predictions_new[,3])/sum(predictions_base[,3]))/log(1.01)
log(sum(predictions_new[,4])/sum(predictions_base[,4]))/log(1.01)
log(sum(predictions_new[,5])/sum(predictions_base[,5]))/log(1.01)
stephanehess
Site Admin
Posts: 1351
Joined: 24 Apr 2020, 16:29

Re: Mixed Logit - elasticities

Post by stephanehess »

Hi

yes, they can be used. Note that they are likely not that different from MNL given that in prediction, you average across draws too to get demand forecasts

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
katya2727
Posts: 4
Joined: 17 Jul 2024, 19:49

Re: Mixed Logit - elasticities

Post by katya2727 »

Hello Prof. Hess,

Thank you for the reply! Is there any better way to find those elasticities for mixed logit?

Thanks again,
Katya
stephanehess
Site Admin
Posts: 1351
Joined: 24 Apr 2020, 16:29

Re: Mixed Logit - elasticities

Post by stephanehess »

Hi

those are the correct sample distribution elasticities, so there is no "better" way. You could investigate the use of posterior distributions, see the discussions in Train's hanbook for example

Best wishes

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
katya2727
Posts: 4
Joined: 17 Jul 2024, 19:49

Re: Mixed Logit - elasticities

Post by katya2727 »

Hello Prof. Hess,

Got it! Thank you so much for the response.

Best,
Katya
Post Reply