Re: Dummy modeling with Biogeme - How to set up utility function

224 views
Skip to first unread message

Bierlaire Michel

unread,
Jul 6, 2023, 2:30:52 AM7/6/23
to Laura Marie Arena, Bierlaire Michel, Biogeme
Dear Laura,

Please post your questions to the biogeme users group, so that everyone can benefit from the discussion.

> On 5 Jul 2023, at 19:23, Laura Marie Arena <laura...@tum.de> wrote:
>
> Dear Prof. Bierlaire,
>
>
> I am currently writing my master's thesis as part of which I am conducting a choice experiment.
>
> Before I can start with the data collection, I would like to finalize my Python code (using BIOGEME) to analyze the choice data, however there is one question that I cannot solve myself and I was wondering if you could help me with this issue:
>
> I have a dummy variables with 3 levels (red, yellow & green).
> Therefore, I included 2 betas (performance_yellow & performance_green) for the variable (with red being the baseline level) in my utility function. However, I cannot find out how to index the specific levels within my utility function.

There is no automatic treatment of discrete variables, as they can be modeled in many ways.
You need to define two dummy variables, one called yellow, and one called red. They take the value one or zero.

Michel


>
> I tried the following:
> performance_yellow * a1_x6['1'] + performance_green * a1_x6['2']
> (the yellow level is represented by the number 1 in my choice set design and the green level is represented by the number 2 in my choice set design).
>
> However, the following error message appears: "TypeError: 'Variable' object is not subscriptable"
>
> Could you please tell me how to include my dummy variable with the 3 levels into my utility function, so that I get a beta for my yellow and a beta for my green level in my output and hence can interpret my results?
>
>
> Thank you for your time and help.
> Your input is highly appreciated!
>
> Kind regards
> Laura Arena


Michel Bierlaire
Transport and Mobility Laboratory
School of Architecture, Civil and Environmental Engineering
EPFL - Ecole Polytechnique Fédérale de Lausanne
http://transp-or.epfl.ch
http://people.epfl.ch/michel.bierlaire

Laura Arena

unread,
Jul 7, 2023, 3:52:53 AM7/7/23
to Biogeme
Hi,

thank you for posting my question and your response.

I came up with the following solution, however I am not sure if it leads to meaningful results:

1. Definition of dummy variables
a1_x5_green = (a1_x5 == 1 )
a1_x5_yellow = (a1_x5 == 2 )
a2_x5_green = (a2_x5 == 1 )
a2_x5_yellow = (a2_x5 == 2 )

2. Utility function for alternative 1
performance_yellow * a1_x5_yellow + performance_green * a1_x5_green

(in my choice experiment data, green is represented by the number 1, yellow by the number 2, and red, i.e. the baseline, by the number 3)

Could you please confirm this approach or - if it is not correct - suggest an alternative?

Thank you very much!
Laura

Bierlaire Michel

unread,
Jul 7, 2023, 9:00:43 AM7/7/23
to laura.mar...@gmail.com, Bierlaire Michel, Biogeme


> On 7 Jul 2023, at 09:47, Laura Arena <laura.mar...@gmail.com> wrote:
>
> Hi,
>
> thank you for posting my question and your response.
>
> I came up with the following solution, however I am not sure if it leads to meaningful results:
>
> 1. Definition of dummy variables
> a1_x5_green = (a1_x5 == 1 )
> a1_x5_yellow = (a1_x5 == 2 )
> a2_x5_green = (a2_x5 == 1 )
> a2_x5_yellow = (a2_x5 == 2 )
>

Yes, that’s correct. How the sake of efficiency, I would create these variables in the original database, so that they are not recalculated each time they are needed.
You can use the DefineVariable function of the Database object to do that.
http://biogeme.epfl.ch/sphinx/database.html#biogeme.database.Database.DefineVariable
See examples here: https://github.com/michelbierlaire/biogeme/blob/master/examples/latent/optima.py

> 2. Utility function for alternative 1
> performance_yellow * a1_x5_yellow + performance_green * a1_x5_green
>
> (in my choice experiment data, green is represented by the number 1, yellow by the number 2, and red, i.e. the baseline, by the number 3)
>
> Could you please confirm this approach or - if it is not correct - suggest an alternative?

Yes, it looks correct.
> --
> You received this message because you are subscribed to the Google Groups "Biogeme" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to biogeme+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/biogeme/b6fb2082-1633-4c6a-be58-37670b3af039n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages