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.

need to define utilities for categorical variables in MNL model

Ask questions about model specifications. Ideally include a mathematical explanation of your proposed model.
Post Reply
akash212
Posts: 6
Joined: 17 May 2021, 22:23

need to define utilities for categorical variables in MNL model

Post by akash212 »

Hello,

I am very new to choice modeling and r coding. I am working on vehicle mode choice analysis.
I have 4 alternatives namely

1. Car
2. Walk
3. Bicycle
4. Public Transport

I have a variable called "motive" in my data set, which states the trip taken.

"motive" variable has 4 values (1=work purpose, 2=errands purpose, 3=social purpose, 4=leisure purpose). Now, I want to make use of this variable in my MNL choice model. But, I am not sure how we can define utilities for such variables.

Until now, I have used the below variables in my model. Where the "dist" variable gives the distance between 2 locations, and the "trip_duration" variables give the time taken to travel between 2 locations.

V[['walk']] = asc_walk + b_dist_w * log(dist + 1) + b_time_w * log(trip_duration+1)
V[['bicycle']] = asc_bicycle + b_dist_b * log(dist + 1) + b_time_b * log(trip_duration+1)
V[['pt']] = asc_pt + b_dist_p * log(dist + 1) + b_time_p * log(trip_duration+1)
V[['car']] = 0

Please let me know how can use the "motive" variable in the above equations.
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: need to define utilities for categorical variables in MNL model

Post by stephanehess »

Hi

you can just use:

V[['walk']] = asc_walk + b_dist_w * log(dist + 1) + b_time_w * log(trip_duration+1) + b_work_w * (motive==1) + b_errands_w * (motive==2) + b_social_w * (motive==3)

so that leisure is the base

and then do this for all alternatives except for car which is your base

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
akash212
Posts: 6
Joined: 17 May 2021, 22:23

Re: need to define utilities for categorical variables in MNL model

Post by akash212 »

Thank you for the reply, Stephane.

It is working as expected. :)
akash212
Posts: 6
Joined: 17 May 2021, 22:23

Re: need to define utilities for categorical variables in MNL model

Post by akash212 »

Hello Stephane,

I have a very general question to ask while implementing interaction of characteristics, how can we decide with the variables? Shall we check the correlation between variables and then create an interaction model with highly correlated features?

For example,
We took the interaction of characteristics between the "Business_trip" and "Income" variables in the mode choice behavior for the available choices of Car and Train.

What should be our approach while working with interaction variables?

Thanks in Advance,
Akash
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: need to define utilities for categorical variables in MNL model

Post by stephanehess »

Hi

correlation between the variables in the data does not imply anything behavioural in terms of possible interaction effects. So what you need to do instead is consider what kind of behavioural effects might make sense, and also look at tabulating your data before model specification to see whether specific combinations are more likely to be chosen than others.

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
akash212
Posts: 6
Joined: 17 May 2021, 22:23

Re: need to define utilities for categorical variables in MNL model

Post by akash212 »

OKay, understood. Thank you for the answer.
bokapatsila
Posts: 21
Joined: 28 Jul 2021, 02:41

Re: need to define utilities for categorical variables in MNL model

Post by bokapatsila »

akash212 wrote: 05 Jun 2021, 13:57 Hello,

I am very new to choice modeling and r coding. I am working on vehicle mode choice analysis.
I have 4 alternatives namely

1. Car
2. Walk
3. Bicycle
4. Public Transport

I have a variable called "motive" in my data set, which states the trip taken.

"motive" variable has 4 values (1=work purpose, 2=errands purpose, 3=social purpose, 4=leisure purpose). Now, I want to make use of this variable in my MNL choice model. But, I am not sure how we can define utilities for such variables.

Until now, I have used the below variables in my model. Where the "dist" variable gives the distance between 2 locations, and the "trip_duration" variables give the time taken to travel between 2 locations.

V[['walk']] = asc_walk + b_dist_w * log(dist + 1) + b_time_w * log(trip_duration+1)
V[['bicycle']] = asc_bicycle + b_dist_b * log(dist + 1) + b_time_b * log(trip_duration+1)
V[['pt']] = asc_pt + b_dist_p * log(dist + 1) + b_time_p * log(trip_duration+1)
V[['car']] = 0

Please let me know how can use the "motive" variable in the above equations.
Hi! I'm also new to choice modelling and trying to work my way through the examples. This topic seems to be relevant to my question:
What is the difference between the use of "V[['car']] = 0" as it is specified above, and "V[['car']] = asc_car + b_dist_car * log(dist + 1) + b_time_car * log(trip_duration+1) " together with setting "apollo_fixed = c("asc_car")" - something that is more common in the apollo examples? Thank you!
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: need to define utilities for categorical variables in MNL model

Post by stephanehess »

Hi

Code: Select all

V[['car']] = 0


is the same as

Code: Select all

V[['car']] = asc_car
together with setting

Code: Select all

apollo_fixed = c("asc_car")
But of course, this is different from

Code: Select all

V[['car']] = asc_car + b_dist_car * log(dist + 1) + b_time_car * log(trip_duration+1)
as you have other terms in the utility function.

But you can't have dist and trip_duration in all 4 utilities, as you need a normalisation.

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
bokapatsila
Posts: 21
Joined: 28 Jul 2021, 02:41

Re: need to define utilities for categorical variables in MNL model

Post by bokapatsila »

Thank you, Stephane!
Post Reply