Page 1 of 1

Estimation of Generic attribute design (SP survey)

Posted: 15 Mar 2022, 02:53
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.

Re: Estimation of Generic attribute design (SP survey)

Posted: 18 Mar 2022, 15:55
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)

Re: Estimation of Generic attribute design (SP survey)

Posted: 28 Apr 2022, 23:01
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?

Re: Estimation of Generic attribute design (SP survey)

Posted: 29 Apr 2022, 00:31
by stephanehess
Yes, but you need to think whether such a linear interaction makes sense

Re: Estimation of Generic attribute design (SP survey)

Posted: 29 Apr 2022, 01:14
by Yashin
Thank you so much SIr.