Page 1 of 1

Intra-individual heterogeneity with MMNL

Posted: 29 Aug 2022, 19:09
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)

Re: Intra-individual heterogeneity with MMNL

Posted: 30 Aug 2022, 12:10
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