Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

3-class discrete mixture model

15 views
Skip to first unread message

Rachel Murray-Watson

unread,
Jan 25, 2025, 4:46:34 AMJan 25
to Biogeme
In the following, I am struggling to extend it to three classes. Particularly at this step: 

PROB_class0 = logit({0: W, 1: 0}, None, 0)
PROB_class1 = logit({0: W, 1: 0}, None, 1)

I have tried: 

PROB_class0
= logit({0: W, 1: 0}, None, 0)
PROB_class1 = logit({0: W, 1: 0}, None, 1)
PROB_class2 = logit({0: W, 1: 0, 2:0}, None, 1)
But it fails. 


In addition, what would be the best way to estimate the AIC or similar for each model, to evaluate whether 2 or 3 (or more?) classes is a better fit? 

# Utilities
Alt1 = [[
     a_2[i] * Variable(f'{t}_a_1_2')
    + a_3[i] * Variable(f'{t}_a_1_3')
    + a_4[i] * Variable(f'{t}_a_1_4')

   
    + b_2[i] * Variable(f'{t}_b_1_2')
    + b_3[i] * Variable(f'{t}_b_1_3')
    + b_4[i] * Variable(f'{t}_b_1_4')
    + b_5[i] * Variable(f'{t}_b_1_5')


    + c[i] * Variable(f'{t}_c_1')
     for t in range(1, 10)
]
    for i in range(NUMBER_OF_CLASSES)
]

Alt2 = [[ACS2_param[i] +  
     a_2[i] * Variable(f'{t}_a_2_2')
    + a_3[i] * Variable(f'{t}_a_2_3')
    + a_4[i] * Variable(f'{t}_a_2_4')

    + b_2[i] * Variable(f'{t}_b_2_2')
    + b_3[i] * Variable(f'{t}_b_2_3')
    + b_4[i] * Variable(f'{t}_b_2_4')
    + b_5[i] * Variable(f'{t}_b_2_5')

    + c[i] * Variable(f'{t}_c_2')

    for t in range(1, 10)
]
  for i in range(NUMBER_OF_CLASSES)
]
# Associate utility functions with the numbering of alternatives
V = [
[{1: Alt1[i][t], 2: Alt2[i][t]} for t in range(9)]
for i in range(NUMBER_OF_CLASSES)
]
# Associate the availability conditions with the alternatives

av = {1: 1, 2: 1}

#obsprob = [loglogit(V[t], av, Variable(f'{t+1}_Chosen_Alternative')) for t in range(9)]
#condprobIndiv = exp(bioMultSum(obsprob))
prob = [
exp(
bioMultSum(
[loglogit(V[i][t], av, Variable(f'{t+1}_Chosen_Alternative')) for t in range(9)]
)
)
for i in range(NUMBER_OF_CLASSES)
]

W = CLASS_1 + Class_Gender*Gender + Class_Race*Race + Class_Hispanic*Hispanic + Class_Age*Age + Class_Income*Income + Class_Residence*Residence + Class_Child*Child + Class_Assisted_Living*Assisted_Living + Class_State*State + Class_Vaccine*Vaccine + Class_Chronic*Chronic + Class_Vulnerable_contact*Vulnerable_contact + Class_Health_Insurance*Health_Insurance + Class_News*News + Class_Political*Political + Class_Self_employed*Self_employed + Class_Remote*Remote + Class_Education*Education + Class_Pregnant*Pregnant + Class_Vehicle*Vehicle

PROB_class0 = logit({0: W, 1: 0}, None, 0)
PROB_class1 = logit({0: W, 1: 0}, None, 1)
probIndiv = PROB_class0 * prob[0] + PROB_class1 * prob[1]


logprob = log(MonteCarlo(probIndiv))
the_biogeme = bio.BIOGEME(flat_database, logprob, parameter_file='few_draws.toml', numberOfDraws=10)
the_biogeme.modelName = 'panel_flat_latent_class'
Reply all
Reply to author
Forward
0 new messages