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.

Intra-individual heterogeneity with MMNL

Ask questions about model specifications. Ideally include a mathematical explanation of your proposed model.
Post Reply
rafael_lionello
Posts: 10
Joined: 26 Apr 2020, 04:24

Intra-individual heterogeneity with MMNL

Post by rafael_lionello »

Dear Professors,

I am trying to model a choice behavior in which buyers choose among alternatives "sequentially", i.e., there is a state dependence issue. It is a medicine choice context, where persons choose combos of three brands for a sequential application. For example, one person can choose brand 1 for the first application, brand 2 for the second one, and brand 5 for the third. Thus, the number of applications is fixed and equals three. Also, some brands are preferred as first application ones, while others are preferred as more last ones.

I will use stated preference data to estimate the parameters (although I will have revealed preference data either). My discrete choice experiment has ten alternatives/ brands (described by only one attribute, that is price) plus a opt-out alternative. It is a labelled experiment, thus I have a ASC per alternative. Each person will face 12 choice sets and, in each of them, have to choose one brand for the first application, one for the second, and one for the third. Thus, each person will generate 36 observations (3 choices per 12 choice sets).

The study intends to look at uptake of brands across applications and at different price leves. Thus, I should be able to simulate demand and market-shares of brands, per application.

To account for the heterogeneity in preference applications (first vs. second vs. third), I was considering the Mixed Logit Model and random components with intra-individual heterogeneity.

However, I am not sure how to specify this intra-heterogeneity component among the three apllications, but not among the 12 choice sets. Or even if it make sense at all. I have tried to follow the "MMNL_wtp_space_inter_intra" example in Apollo's Manual.


In sum,

1- Do you have any idea or reference of a model specification to deal with the current problem?
2- Does it make sense to model the heterogeneity in preference applications with the intra-component of the Mixed Logit Model? If yes, How should I specificy the application variables?


Thank you very much for your time!!!

Best Rafael.




(alternatives from 6 to 10 were omitted for sake of space)

Code: Select all

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

### Clear memory
rm(list = ls())

### Load Apollo library
library(apollo)

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
  modelName       = "MMNL_preference_space_inter_intra",
  modelDescr      = "Mixed logit model on Vaccine choice data, preference space, intra-individual heterogeneity",
  indivID         = "ID",
  mixing          = TRUE, 
  nCores          = 4,
  analyticGrad    = TRUE, # Needs to be set explicitly for models with inter-intra draws (requires extra RAM).
  outputDirectory = "output"
)

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

### Loading data from package
### if data is to be loaded from a file (e.g. called data.csv), 
### the code would be: database = read.csv("data.csv",header=TRUE)
database = myDataSet_vaccineChoiceData
### for data dictionary, use ?apollo_swissRouteChoiceData

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

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(asc_1                    =  0,
                asc_2                    =  0,
                asc_3                    =  0,
                asc_4                    =  0,
                asc_5                    =  0,
                asc_11                   =  0,
                b_price1                 =  0,
                b_price2                 =  0,
                b_price3                 =  0,
                b_price4                 =  0,
                b_price5                 =  0,
                mu_log_b_price1          = -3,
                sigma_log_b_price1_intra =  0,
                mu_log_b_price2          = -3,
                sigma_log_b_price2_intra =  0,
                mu_log_b_price3          = -3,
                sigma_log_b_price3_intra =  0,
                mu_log_b_price4          = -3,
                sigma_log_b_price4_intra =  0,
                mu_log_b_price5          = -3,
                sigma_log_b_price5_intra =  0,
                gamma_price_applicationB =  0,
                gamma_price_applicationC =  0) 


### Vector with names (in quotes) of parameters to be kept fixed at their starting value in apollo_beta, use apollo_beta_fixed = c() if none
apollo_fixed = c("asc_11")

# ################################################################# #
#### DEFINE RANDOM COMPONENTS                                    ####
# ################################################################# #

### Set parameters for generating draws
apollo_draws = list(
  #interDrawsType = "halton",
  #interNDraws    = 100,
  #interUnifDraws = c("draws_price_inter"),
  intraDrawsType = "mlhs",
  intraNDraws    = 100,
  intraUnifDraws = c(),
  intraNormDraws = c("draws_price_intra")
)

### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
  randcoeff = list()
  
  randcoeff[["b_price1"]] = (-exp(mu_log_b_price1 + sigma_log_b_price1_intra * draws_price_intra) * (gamma_price_applicationB*APPL_B + gamma_price_applicationC*APPL_C))
  randcoeff[["b_price2"]] = (-exp(mu_log_b_price2 + sigma_log_b_price2_intra * draws_price_intra) * (gamma_price_applicationB*APPL_B + gamma_price_applicationC*APPL_C))
  randcoeff[["b_price3"]] = (-exp(mu_log_b_price3 + sigma_log_b_price3_intra * draws_price_intra) * (gamma_price_applicationB*APPL_B + gamma_price_applicationC*APPL_C))
  randcoeff[["b_price4"]] = (-exp(mu_log_b_price4 + sigma_log_b_price4_intra * draws_price_intra) * (gamma_price_applicationB*APPL_B + gamma_price_applicationC*APPL_C))
  randcoeff[["b_price5"]] = (-exp(mu_log_b_price5 + sigma_log_b_price5_intra * draws_price_intra) * (gamma_price_applicationB*APPL_B + gamma_price_applicationC*APPL_C))
  
  return(randcoeff)
}

# ################################################################# #
#### 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 inputs and detach after function exit
  apollo_attach(apollo_beta, apollo_inputs)
  on.exit(apollo_detach(apollo_beta, apollo_inputs))
  
  ### Create list of probabilities P
  P = list()
  
  ### List of utilities: these must use the same names as in mnl_settings, order is irrelevant
  V = list()
  V[["alt1"]] = asc_1 + b_price1*price_ALT1
  V[["alt2"]] = asc_2 + b_price2*price_ALT2
  V[["alt3"]] = asc_3 + b_price3*price_ALT3
  V[["alt4"]] = asc_4 + b_price4*price_ALT4
  V[["alt5"]] = asc_5 + b_price5*price_ALT5
  V[["alt6"]] = asc_11
  
  ### Define settings for MNL model component
  mnl_settings = list(
    alternatives  = c(alt1=1, alt2=2, alt1=3, alt4=4, alt5=5, alt_11=11),
    avail         = list(alt1=1, alt2=1, alt3=1, alt4=1, alt5=1, alt_11=1),
    choiceVar     = choice,
    utilities     = V
  )
  
  ### Compute probabilities using MNL model
  P[["model"]] = apollo_mnl(mnl_settings, functionality)
  
  ### Average across intra-individual draws
  P = apollo_avgIntraDraws(P, apollo_inputs, functionality)
  
  ### Take product across observation for same individual
  P = apollo_panelProd(P, apollo_inputs, functionality)
  
  ### Average across inter-individual draws
  P = apollo_avgInterDraws(P, apollo_inputs, functionality)
  
  ### Prepare and return outputs of function
  P = apollo_prepareProb(P, apollo_inputs, functionality)
  return(P)
}

# ################################################################# #
#### MODEL ESTIMATION                                            ####
# ################################################################# #

model = apollo_estimate(apollo_beta, apollo_fixed,apollo_probabilities, apollo_inputs)
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Intra-individual heterogeneity with MMNL

Post by stephanehess »

Rafael

the easiest solution would be to estimate shift parameters for the coefficients in your utility function for application 2 and for application 3. This would capture the heterogeneity in preferences across applications.

You can start by making these shifts be deterministic, and you could then later make them random too.

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Post Reply