Important: Read this before posting to this forum

  1. This forum is for questions related to the use of Apollo. We will answer some general choice modelling questions too, where appropriate, and time permitting. We cannot answer questions about how to estimate choice models with other software packages.
  2. There is a very detailed manual for Apollo available at http://www.ApolloChoiceModelling.com/manual.html. This contains detailed descriptions of the various Apollo functions, and numerous examples are available at http://www.ApolloChoiceModelling.com/examples.html. In addition, help files are available for all functions, using e.g. ?apollo_mnl
  3. Before asking a question on the forum, users are kindly requested to follow these steps:
    1. Check that the same issue has not already been addressed in the forum - there is a search tool.
    2. Ensure that the correct syntax has been used. For any function, detailed instructions are available directly in Apollo, e.g. by using ?apollo_mnl for apollo_mnl
    3. Check the frequently asked questions section on the Apollo website, which discusses some common issues/failures. Please see http://www.apollochoicemodelling.com/faq.html
    4. Make sure that R is using the latest official release of Apollo.
  4. If the above steps do not resolve the issue, then users should follow these steps when posting a question:
    1. provide full details on the issue, including the entire code and output, including any error messages
    2. posts will not immediately appear on the forum, but will be checked by a moderator first. This may take a day or two at busy times. There is no need to submit the post multiple times.

Effects coding in MMNL model

Ask questions about data format and processing of data, including the use of pre-estimation functions in Apollo. If your question relates to a specific error you are getting, please provide some of the output.
Post Reply
nlsr
Posts: 2
Joined: 19 Sep 2024, 15:53

Effects coding in MMNL model

Post 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
stephanehess
Site Admin
Posts: 1210
Joined: 24 Apr 2020, 16:29

Re: Effects coding in MMNL model

Post 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
--------------------------------
Stephane Hess
www.stephanehess.me.uk
nlsr
Posts: 2
Joined: 19 Sep 2024, 15:53

Re: Effects coding in MMNL model

Post 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
stephanehess
Site Admin
Posts: 1210
Joined: 24 Apr 2020, 16:29

Re: Effects coding in MMNL model

Post 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
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Post Reply