Nested logit model and WTP

65 views
Skip to first unread message

Mariana Sousa

unread,
Dec 12, 2022, 7:36:15 AM12/12/22
to Biogeme
Dear professor Bierlaire,

I am trying to develop a nested logit model with 15 nests, each with 2 alternatives (labeled and unlabeled SKU). My data is structured in an aggregate form, so I use the quantities that were sold to calculate the log likelihood.
I am having problems with the estimation of this model. The Hessian norm always converges to infinitive, even when I try to estimate a simple MNL. I have tried different optimizers and different scales for my variables and the problem remains the same. Is there something wrong with the modeling?

Also, I need to calculate the average WTP for the labeled and unlabeled alternatives. Is it sufficient to do the division of the derivative of the remaining shelf life by the price of each of the alternatives and then average all the simulated labeled and unlabeled WTP's? Should the MU parameters not be considered for the calculation?


data_agg = db.Database("df_", df_)

n_alt = 30
globals().update(data_agg.variables)

ASC_unlabeled = {}
ASC_labeled = {}
B_rsl_unlabeled = {}
B_rsl_labeled = {}
B_Price_unlabeled = {}
B_Price_labeled = {}
Mu = {}
nest = {}

for i in range(15):
    
    ASC_unlabeled[i] = Beta('ASC_unlabeled' + str(array_skus[i]), 0, None, None, 0)
    ASC_labeled[i] = Beta('ASC_labeled' + str(array_skus[i]), -0.184, None, None, 0)
    B_rsl_unlabeled[i] = Beta('B_rsl_unlabeled'  + str(array_skus[i]),2,None, None,0)
    B_rsl_labeled[i] = Beta('B_rsl_etiqueta'  + str(array_skus[i]),1,None, None,0)
    B_Price_unlabeled[i] = Beta('B_Price_unlabeled'  + str(array_skus[i]),-0.323,None, None,0) 
    B_Price_labeled[i] = Beta('B_Price_labeled'  + str(array_skus[i]),-0.734,None, None,0) 
    
    Mu[i] = Beta('MU'+ str(array_skus[i]), 1, 1, 10, 0)
    
    nest[i] = Mu[i], [2*i, 2*i+1]
    

ASC_unlabeled[0] = Beta('ASC_unlabeled6119649' , 0, None, None, 1)

nests = nest[0], nest[1], nest[2], nest[3], nest[4], nest[5], nest[6], nest[7], nest[8], nest[9], nest[10], nest[11], nest[12], nest[13], nest[14]


# Utilities
V = {}
av = {}
n = 0
for i in range(15):
    V[i+n] = (ASC_unlabeled[i] + B_Price_unlabeled[i] * Variable(str(array_skus[i])+'_price_unlabeled')  + B_rsl_unlabeled[i] * log((Variable(str(array_skus[i])+'_remaining_shelf_life_unlabeled'))+1))
    av[i+n] = Variable(str(array_skus[i])+'_av')
    n +=1
    V[i+n] = (ASC_labeled[i] + B_Price_labeled[i] * Variable(str(array_skus[i])+'_price_labeled') + B_rsl_labeled[i] * Variable(str(array_skus[i])+'_remaining_shelf_life_labeled'))
    av[i+n] = Variable(str(array_skus[i])+'_av_et')

logprob = (Variable(str(array_skus[0])+'_sold_unlabeled')) * (models.lognested(V, av, nests,  0)) + (Variable(str(array_skus[0])+'_sold_labeled')) * (models.lognested(V, av, nests,  1))

for i in range(1,15):
    logprob += (Variable(str(array_skus[i])+'_sold_unlabeled') )* (models.lognested(V, av, nests, i*2))
    logprob += (Variable(str(array_skus[i])+'_sold_labeled')) *( models.lognested(V, av, nests,  (i*2+1)) )
    
biogeme = bio.BIOGEME(data_agg, logprob)
biogeme.modelName = "nested"
results = biogeme.estimate(algorithm=opt.bioNewton, algoParameters={'maxiter':100})

Thank you in advance.

Kindest regards.

Bierlaire Michel

unread,
Dec 12, 2022, 7:41:25 AM12/12/22
to mariana.so...@gmail.com, Bierlaire Michel, Biogeme
You probably have an identification issue. 
In general, if an alternative has no label, it is not associated with an ASC. 
Also, I am not sure that the numbering of alternatives is consistent. The loop on i with n increase at each iteration looks suspicious. 


--
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/9b9fadca-758f-45eb-8efe-2066409a5e03n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages