Mixture of logit model: unbalanced panel data

94 views
Skip to first unread message

Yuanjie Tu

unread,
May 20, 2021, 2:38:35 AM5/20/21
to Biogeme
Hi Professor Bierlaire,

I encountered an error when applying a mixed logit referring to the Panel.py example. I sorted the data using "ID", so observations of the same individual have the same ID and are consecutive. The format of the data is the same as Swissmetro data on the Biogeme website, but for each individual, the number of observations can be different (individual 1 can have 3 observations and individual 5 can have 2). Thus there is an error popping out saying "The data must be sorted so that the data for the same individual are consecutive." I also pasted the error message below.

Could you help me with this?
WechatIMG7730.png

Thanks much!

Yuanjie Tu

Bierlaire Michel

unread,
May 20, 2021, 2:55:12 AM5/20/21
to yua...@uw.edu, Bierlaire Michel, Biogeme
You need to investigate with pandas. 
The numbers in the error message are calculated using this function: http://biogeme.epfl.ch/sphinx/biogeme.html#biogeme.tools.countNumberOfGroups
    df['_biogroups'] = (df[column] != df[column].shift(1)).cumsum()
    return len(df['_biogroups'].unique())

The number of groups is the value before sorting, and the number of individuals is the value after sorting. If the two values differ, the error message is triggered.



<WechatIMG7730.png>

Thanks much!

Yuanjie Tu


--
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/54cade91-f5df-4bf7-a029-68f7e3a35a1fn%40googlegroups.com.
<WechatIMG7730.png>

Reply all
Reply to author
Forward
0 new messages