Page 1 of 1

Effects coding in MMNL model

Posted: 19 Sep 2024, 20:02
by nlsr
Dear Apollo Choice Modelling forum,

I'm coding my choice experiment results, and as I have several categorical attributes where none of my levels are included in my opt-out and there is no baseline, I decided to use effects coding.

I first coded an MNL model, where I specified them like this: (as shown in your example online)
level_c = -level_a - level_b

But I am now moving to an MMNL model, and I'm not sure how to correctly code this using sigmas and mus, I currently coded it by calculating mus and sigmas separately: i.e. mu_level_c = -mu_level_a - mu_level_b and sigma_level_c= - sigma_level_a - sigma_level_b

Would this be correct?

Many thanks in advance for your help,

Best regards,

Noelle

Re: Effects coding in MMNL model

Posted: 20 Sep 2024, 08:02
by stephanehess
Hi

personally, I would recommend that you stick to dummy coding, it's much easier and completely consistent, see https://doi.org/10.1016/j.jocm.2016.09.005

if you want to use efefcts coding, then your differences would need to be in the random parameters themselves that you define in apollo_randCoeff, not in the means and sd

Stephane

Re: Effects coding in MMNL model

Posted: 20 Sep 2024, 15:55
by nlsr
Hi Stephane,

Many thanks for your fast reply. I used the differences in the random parameters as you suggested, but I can't seem to obtain a value at the end when I use the apollo_deltaMethod function, I get error messages,

Please find my code below:

My coeffcicients:

apollo_beta = c(mu_asc_alt3 = -3,
sigma_asc_alt3 = 0.01,
mu_size = 0,
sigma_size = 0,
mu_reuse_agri = 0,
sigma_reuse_agri = 0,
mu_reuse_industry = 0,
sigma_reuse_industry = 0,
mu_walk_yes = 0,
sigma_walk_yes = 0,
mu_walk_no = 0,
mu_distance_200 = 0,
sigma_distance_200 = 0,
mu_distance_500 = 0,
sigma_distance_500 = 0,
mu_distance_1000 = 0,
sigma_distance_1000 = 0,
mu_price = -3,
sigma_price = 0.01)

After fixing mu_walk_no to 0, here are my random coeff:

apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()

randcoeff[["b_asc"]] = mu_asc_alt3 + sigma_asc_alt3 * draws_acs
randcoeff[["b_size"]] = mu_size + sigma_size * draws_size
randcoeff[["b_reuse_agri"]] = mu_reuse_agri + sigma_reuse_agri * draws_reuse_agri
randcoeff[["b_reuse_industry"]] = mu_reuse_industry + sigma_reuse_industry * draws_reuse_industry
randcoeff[["b_reuse_parc"]] = - randcoeff[["b_reuse_industry"]] - randcoeff[["b_reuse_agri"]]
randcoeff[["b_distance_1000"]] = mu_distance_1000 + sigma_distance_1000 * draws_distance_1000
randcoeff[["b_distance_500"]] = mu_distance_500 + sigma_distance_500 * draws_distance_500
randcoeff[["b_distance_200"]] = mu_distance_200 + sigma_distance_200 * draws_distance_200
randcoeff[["b_distance_100"]] = - randcoeff[["b_distance_1000"]] - randcoeff[["b_distance_500"]] - randcoeff[["b_distance_200"]]
randcoeff[["b_walk_yes"]] = mu_walk_yes + sigma_walk_yes * draws_walk_yes
randcoeff[["b_price"]] = -exp( mu_price + sigma_price * draws_price )

return(randcoeff)
}

As you can see, I have 2 levels that I code using effects coding: 100m and reusing the water in parcs.

These are my utility functions:

V = list()
V[["alt1"]] = b_size * size1 + b_reuse_agri * (reuse1==2) + b_reuse_industry * (reuse1==3) + b_reuse_parc * (reuse1==1) + b_distance_100 * (distance1==100) + b_distance_200 * (distance1==200) + b_distance_500 * (distance1==500) + b_distance_1000 * (distance1==1000) + mu_walk_no * (walk1==2)+ b_walk_yes * (walk1==1) + b_price*price1
V[["alt2"]] = b_size * size2 + b_reuse_agri * (reuse2==2) + b_reuse_industry * (reuse2==3) + b_reuse_parc * (reuse2==1) + b_distance_100 * (distance2==100) + b_distance_200 * (distance2==200) + b_distance_500 * (distance2==500) + b_distance_1000 * (distance2==1000) + mu_walk_no * (walk2==2)+ b_walk_yes * (walk2==1) + b_price*price2
V[["alt3"]] = b_asc

And after estimating my model, I want to get the value for distance_100 and for reuse_parc, so I implemented the apollo_deltaMethod functions:

I tried these 2 ways of coding, but none seem to work as I always get these error messages "Error: object 'randcoeff' not found" or "Error: object 'b_reuse_parc' not found" :

apollo_deltaMethod(model,deltaMethod_settings = list(expression=c(randcoeff[["b_reuse_parc"]] = - randcoeff[["b_reuse_industry"]] - randcoeff[["b_reuse_agri"]])))

apollo_deltaMethod(model,deltaMethod_settings = list(expression=c(b_reuse_parc = - b_reuse_industry - b_reuse_agri)))

How do you suggest I code the last functions to be able to have a value for my 2 levels?

Many thanks in advance for your help,

Best regards,

Noelle

Re: Effects coding in MMNL model

Posted: 27 Sep 2024, 18:54
by stephanehess
Hi

the delta method operates on estimated parameters, but you are trying to use it on a random coefficient, which is a function of multiple distributed parameters. That will not work.

Stephane