Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Latent class membership model

87 views
Skip to first unread message

Mike Sri

unread,
Sep 3, 2024, 1:44:16 AM9/3/24
to Biogeme
Dear Prof. Bierlaire, 

I am looking to construct the latent class model that we can select the number of classes but not with panel data. I only saw the example with panel data so just wondering if it possible to work with cross-sectional data instead. 

Best,
Mike

Michel Bierlaire

unread,
Sep 3, 2024, 2:06:57 AM9/3/24
to tats...@gmail.com, Michel Bierlaire, Biogeme
Of course.
This example does not exploit the panel structure of the data.
https://biogeme.epfl.ch/sphinx/auto_examples/swissmetro/plot_b07discrete_mixture.html#sphx-glr-auto-examples-swissmetro-plot-b07discrete-mixture-py
> --
> 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/89b40538-6977-44bf-bb7f-a0d64f9d8dban%40googlegroups.com.

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

Mike Sri

unread,
Sep 5, 2024, 3:50:27 AM9/5/24
to Biogeme
Thank you for the prompt response, Prof. Bierlaire.  I followed the ex7 and wanted to extend it to three classes which I ran to the error as I specified model as follow. 

ASC_CAR_C1 = Beta('ASC_CAR_C1', 0, None, None, 0)
ASC_TRAIN_C1 = Beta('ASC_TRAIN_C1', 0, None, None, 0)
ASC_SM_C1 = Beta('ASC_SM_C1', 0, None, None, 1)
B_TIME_C1 = Beta('B_TIME_C1', 0, None, None, 0)
B_COST_C1 = Beta('B_COST_C1', 0, None, None, 0)

ASC_CAR_C2 = Beta('ASC_CAR_C2', 0, None, None, 0)
ASC_TRAIN_C2 = Beta('ASC_TRAIN_C2', 0, None, None, 0)
ASC_SM_C2 = Beta('ASC_SM_C2', 0, None, None, 1)
B_TIME_C2 = Beta('B_TIME_C2', 0, None, None, 0)
B_COST_C2 = Beta('B_COST_C2', 0, None, None, 0)

ASC_CAR_C3 = Beta('ASC_CAR_C3', 0, None, None, 0)
ASC_TRAIN_C3 = Beta('ASC_TRAIN_C3', 0, None, None, 0)
ASC_SM_C3 = Beta('ASC_SM_C3', 0, None, None, 1)
B_TIME_C3 = Beta('B_TIME_C3', 0, None, None, 0)
B_COST_C3 = Beta('B_COST_C3', 0, None, None, 0)

Class membership probability.

PROB_CLASS1 = Beta('PROB_CLASS1', 0.5, 0, 1, 0)
PROB_CLASS2 = Beta('PROB_CLASS2', 0.5, 0, 1, 0)
PROB_CLASS3 = 1 - PROB_CLASS1-PROB_CLASS2

Definition of the utility functions for latent class 1, where the
time coefficient is zero.



V11 = ASC_TRAIN_C1 + B_COST_C1 * TRAIN_COST_SCALED
V12 = ASC_SM_C1 + B_COST_C1 * SM_COST_SCALED
V13 = ASC_CAR_C1 + B_COST_C1 * CAR_CO_SCALED

V21 = ASC_TRAIN_C2 + B_TIME_C2 * TRAIN_TT_SCALED + B_COST_C2 * TRAIN_COST_SCALED
V22 = ASC_SM_C2 + B_TIME_C2 * SM_TT_SCALED + B_COST_C2 * SM_COST_SCALED
V23 = ASC_CAR_C2 + B_TIME_C2 * CAR_TT_SCALED + B_COST_C2 * CAR_CO_SCALED

V31 = ASC_TRAIN_C3 + B_TIME_C3 * TRAIN_TT_SCALED + B_COST_C3 * TRAIN_COST_SCALED
V32 = ASC_SM_C3 + B_TIME_C3 * SM_TT_SCALED + B_COST_C3 * SM_COST_SCALED
V33 = ASC_CAR_C3 + B_TIME_C3 * CAR_TT_SCALED + B_COST_C3 * CAR_CO_SCALED

Associate utility functions with the numbering of alternatives.
V1 = {1: V11, 2: V12, 3: V13}
V2 = {1: V21, 2: V22, 3: V23}
V3 = {1: V31, 2: V32, 3: V33}

Associate the availability conditions with the alternatives.

av = {1: TRAIN_AV_SP, 2: SM_AV, 3: CAR_AV_SP}

The choice model is a discrete mixture of logit, with availability conditions

prob1 = models.logit(V1, av, CHOICE)
prob2 = models.logit(V2, av, CHOICE)
prob3 = models.logit(V3, av, CHOICE)
prob = PROB_CLASS1 * prob1 + PROB_CLASS2 * prob2 + PROB_CLASS3*prob3
logprob = log(prob)



Michel Bierlaire

unread,
Sep 9, 2024, 9:43:49 AM9/9/24
to tats...@gmail.com, Michel Bierlaire, Biogeme


> On 3 Sep 2024, at 09:00, Mike Sri <tats...@gmail.com> wrote:
>
> PROB_CLASS1 = Beta('PROB_CLASS1', 0.5, 0, 1, 0)
> PROB_CLASS2 = Beta('PROB_CLASS2', 0.5, 0, 1, 0)
> PROB_CLASS3 = 1 - PROB_CLASS1-PROB_CLASS2
>
>

This is not valid, as it does not prevent prob_class3 to be negative.

Instead, you need something like

X_CLASS1 = Beta('X_CLASS1', 0, None, None, 0)
X_CLASS2 = Beta('X_CLASS2', 0, None, None, 0)
X = {1: X_CLASS1, 2: X_CLASS2, 3: 0}


PROB_CLASS1 = model.logit(X, None, 1)
PROB_CLASS2 = model.logit(X, None, 2)
PROB_CLASS3 = model.logit(X, None, 3)
Reply all
Reply to author
Forward
0 new messages