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.

Estimation of Generic attribute design (SP survey)

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
Post Reply
Yashin
Posts: 21
Joined: 23 Sep 2021, 01:43

Estimation of Generic attribute design (SP survey)

Post by Yashin »

Dear Sir,

I was looking for an example of the code for the estimation of the Generic attribute design for the MNL model in the Apollo website. However, I did not find any suitable leads.

My question is :

Is there any dataset where the MNL model is established with a Generic dataset instead of (Alternate specific design) in Apollo? a case example?

If so, In this case, should estimate 'ASC' in order to understand the users' preferences since my dataset is an unlabelled and forced Discrete choice experiment.

Any leads are highly appreciated.
dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: Estimation of Generic attribute design (SP survey)

Post by dpalma »

Hi,

In the examples section of the Apollo's webpage, you can download example MMNL_preference_space, which is an unlabelled experiment without any alternative specific constant. However, this examples uses a mix-logit, not an MNL.

Below is an example script for an unlabelled MNL model using the same data.

Best wishes
David

Code: Select all

# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS                       ####
# ################################################################# #

### Initialise
rm(list = ls())
library(apollo)
apollo_initialise()

### Set core controls
apollo_control = list(
  modelName       = "mnl_unlabelled",
  modelDescr      = "MNL on Swiss route choice data",
  indivID         = "ID"
)

# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS                     ####
# ################################################################# #

database = apollo_swissRouteChoiceData

# ################################################################# #
#### DEFINE MODEL PARAMETERS                                     ####
# ################################################################# #

### Vector of parameters, including any kept fixed during estimation
apollo_beta = c(bTT = 0,
                bTC = 0, 
                bHW = 0,
                bCH = 0)

### Vector with parameter names (in quotes) to be kept fixed at 
# their starting values during estimation.
# Use apollo_beta_fixed = c() if none
apollo_fixed = c()


# ################################################################# #
#### GROUP AND VALIDATE INPUTS                                   ####
# ################################################################# #

apollo_inputs = apollo_validateInputs()

# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION                        ####
# ################################################################# #

apollo_probabilities=function(apollo_beta, apollo_inputs, 
                              functionality="estimate"){
  
  ### Function initialisation: do not change the following three commands
  ### Attach and detach inputs, and create empty list of probabilities
  apollo_attach(apollo_beta, apollo_inputs)
  on.exit(apollo_detach(apollo_beta, apollo_inputs))
  P = list()
  
  ### List of MNL utilities: must use the same names as in mnl_settings
  V = list()
  V[["alt1"]] = bTT*tt1 + bTC*tc1 + bHW*hw1 + bCH*ch1
  V[["alt2"]] = bTT*tt2 + bTC*tc2 + bHW*hw2 + bCH*ch2
  
  ### Define settings for MNL model component
  mnl_settings = list(
    alternatives = c(alt1=1, alt2=2),
    choiceVar    = choice,
    utilities    = V
  )
  
  ### Compute probabilities using MNL model
  P[["model"]] = apollo_mnl(mnl_settings, functionality)
  
  ### Comment out as necessary
  P = apollo_panelProd(P, apollo_inputs, functionality)
  P = apollo_prepareProb(P, apollo_inputs, functionality)
  return(P)
}


# ################################################################# #
#### MODEL ESTIMATION AND OUTPUT                                 ####
# ################################################################# #

model = apollo_estimate(apollo_beta, apollo_fixed,
                        apollo_probabilities, apollo_inputs)

apollo_modelOutput(model)

apollo_saveOutput(model)
Yashin
Posts: 21
Joined: 23 Sep 2021, 01:43

Re: Estimation of Generic attribute design (SP survey)

Post by Yashin »

Thank you for the reply and help.

I would like to know an additional thing.

is it also possible to include the explanatory variables with the unlabelled MNL model? Such as the socio-demographics effect in an interaction term. If so, I tried using the following script to run the MNL model (unlabelled alternatives).

1.

V[['Option_1']] = b_dist * Distance_1 +b_resv * Reservation_1 + b_cost * Price_1 +
b_cpeed * Charging_Speed_1 +b_edu_rev*(Reservation_1*(Age))+b_edu_p*(Price_1*(Age))


V[['Option_2']] = b_dist * Distance_2 +b_resv * Reservation_2 + b_cost * Price_2 +
b_cpeed * Charging_Speed_2 +b_edu_rev*(Reservation_2*(Age))+b_edu_p*(Price_2*(Age))


V[['Option_3']] = b_dist * Distance_3 +b_resv * Reservation_3 + b_cost * Price_3 +
b_cpeed * Charging_Speed_3 + b_edu_rev*(Reservation_3*(Age))+b_edu_p*(Price_3*(Age))

2. In addition to this, If I would like to estimate a certain age group from my dataset where Age is the categorical variable coded from 1 to 6 with different categories of Age, I have used the following script:

V[['Option_1']] = b_dist * Distance_1 +b_resv * Reservation_1 + b_cost * Price_1 +
b_cpeed * Charging_Speed_1 +
b_edu_rev*(Reservation_1*(Age))+b_edu_p*(Price_1*(Age==2))

V[['Option_2']] = b_dist * Distance_2 +b_resv * Reservation_2 + b_cost * Price_2 +
b_cpeed * Charging_Speed_2 +
b_edu_rev*(Reservation_2*(Age))+b_edu_p*(Price_2*(Age==2))

V[['Option_3']] = b_dist * Distance_3 +b_resv * Reservation_3 + b_cost * Price_3 +
b_cpeed * Charging_Speed_3 +
b_edu_rev*(Reservation_3*(Age))+b_edu_p*(Price_3*(Age==2))


I would like to know if these approaches are the correct way to represent the utility functions?
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Estimation of Generic attribute design (SP survey)

Post by stephanehess »

Yes, but you need to think whether such a linear interaction makes sense
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Yashin
Posts: 21
Joined: 23 Sep 2021, 01:43

Re: Estimation of Generic attribute design (SP survey)

Post by Yashin »

Thank you so much SIr.
Post Reply