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. We check the forum at least twice a week. It may thus take a couple of days for your post to appear and before we reply. There is no need to submit the post multiple times.

Problem with Estimating Scale Parameter

Ask questions about how to estimate models and how to change your settings for estimation.
Post Reply
ayjossy
Posts: 6
Joined: 01 Jun 2023, 19:37

Problem with Estimating Scale Parameter

Post by ayjossy »

Dear Prof. Hess and Dr. Palma,
Once again, thank you for your efforts in building and supporting the Apollo Software.
I observed an issue while trying to accounting for scale difference in my estimation. My dataset consists of three experimental groups in food choice experiment. Two of the groups were treated in information and the control group received no information. My aim is to estimate scale parameters for the treated groups relative to the control for which I fixed the scale to 1. I observe that when I fix the scale control group to 1 and estimated for others, I get the following values :
Estimate Rob.std.err.
price -4.669 0.221
sigma_price_inter -4.146 1.203
afla -5.449 0.994
sigma_afla_inter 5.742 1.218
nafdac 1.657 0.527
sigma_nafdac_inter -5.900 0.978
untested 2.471 0.542
sigma_untested_inter 1.573 0.322
mu_control 1.000 NA
mu_FT -0.445 0.103
mu_ST -0.466 0.100

sigma_afla_nafdac -0.632 0.341
sigma_afla_untested -0.103 0.546
sigma_nafdac_untested 1.299 0.399
sigma_afla_price 6.931 1.065
sigma_nafdac_price -1.340 0.265
sigma_untested_price -2.970 0.604

However, when I normalize one of the treated groups and estimate the scale parameters for the control and the other treated group, I get the following values:

Estimate Std.err.
price -4.536 0.119
sigma_price_inter -3.304 0.378
afla 8.997 0.849
sigma_afla_inter -2.034 0.343
nafdac 6.887 0.684
sigma_nafdac_inter -0.958 0.268
untested 4.549 0.514
sigma_untested_inter -0.322 0.422
mu_control 1.223 0.157
mu_FT 1.363 0.196
mu_ST 1.000 NA

sigma_afla_nafdac 0.535 0.259
sigma_afla_untested 2.244 0.363
sigma_nafdac_untested 0.609 0.279
sigma_afla_price 4.755 0.557
sigma_nafdac_price 1.451 0.276
sigma_untested_price -1.018 0.368

My concern is:
In the first output, the estimated scale parameters were negative and apparently below 0.5 but in the second output, the values seem to align with the normal pattern of positive scale parameters I am used to

My experience with values of scale parameters of this nature is that the are usually a positive value either above 1 or below 1. Please, I need your advise on what may be responsible for such noticeable difference in the values of scale parameters depending on which group I normalize. Out of curiosity, I will like to ask if it has anything to do with whether I specified the distribution of price parameter as negative log-uniform?

Please, find below my full code. Thank you

Code: Select all

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

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

### Load Apollo library
library(apollo)
library(lmtest)
library(dplyr)

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
  modelName       = "MMNL_Pref_Pooled_SBA_LU_Scaled_TE_September_2024_04_B",
  modelDescr      = "Mixed logit model, Pooled Log Uniform Price, Scaled ",
  indivID         = "id",  
  mixing          = TRUE, 
  nCores          = 7,
  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)
apollo_database = read.csv(file = file.choose())
# ################################################################# #
#### DEFINE MODEL PARAMETERS                                     ####
# ################################################################# #

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(
  price             = -5,            sigma_price_inter      = 0,
  
  
  afla              = 0,            sigma_afla_inter          = 0,    
  nafdac          = 0,            sigma_nafdac_inter     = 0,  
  untested       = 0,            sigma_untested_inter  = 0, 
  
  fafla             = 0,            fnafdac    = 0,  funtested           = 0,                
  safla             = 0,            snafdac    = 0,  suntested           = 0,                 
  
 #For Scale
  mu_control    = 1,
  mu_FT         = 1,
  mu_ST         = 1,
  
  #Correlations in parameters
  sigma_afla_nafdac = 0,    sigma_afla_untested = 0,  sigma_nafdac_untested = 0,
  sigma_afla_price  = 0,     sigma_nafdac_price = 0,  sigma_untested_price = 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("mu_control")

### Overwrite beta starting values
#apollo_readBeta(apollo_beta, apollo_fixed, "MMNL_Pref_Pooled_LU_Scaled_TE_September_2024_04_A", overwriteFixed = FALSE)
# ################################################################# #
#### DEFINE RANDOM COMPONENTS                                    ####
# ################################################################# #

### Set parameters for generating draws
apollo_draws = list(
  interDrawsType = "sobol",
  interNDraws    = 500,
  interUnifDraws = c("unif_draws_price_inter"),
  interNormDraws = c(
                     
                     ##Draws for alternative-specific parameters for the three groups
                     "draws_afla_inter","draws_nafdac_inter", "draws_untested_inter",
                     
                     #Draw for correlation among price parameters
                     "draws_afla_price", "draws_nafdac_price",
                     "draws_afla_nprice", "draws_nafdac_nprice", "draws_untested_price",
                     
                     #Draws for correlation among alternative-specific parameters
                     "draws_afla_nafdac", "draws_afla_untested", "draws_nafdac_untested"
  )

)

### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
  randcoeff = list()
  
  # Log-Uniform distribution
  randcoeff[["b_price"]] = -exp(price + sigma_price_inter * unif_draws_price_inter)
  
  # Normal distribution
  #randcoeff[["b_price"]] = (price + sigma_price_inter * unif_draws_price_inter)
  
  randcoeff[["b_afla"]] =  (afla + sigma_afla_inter*draws_afla_inter + sigma_afla_price*draws_afla_price)
  
  randcoeff[["b_nafdac"]] = (nafdac + sigma_nafdac_inter*draws_nafdac_inter +
                               sigma_afla_nafdac*draws_afla_nafdac +
                               sigma_nafdac_price*draws_nafdac_price)
  
  randcoeff[["b_untested"]] = (untested + sigma_untested_inter*draws_untested_inter +
                                 sigma_afla_untested*draws_afla_untested + sigma_nafdac_untested*draws_nafdac_untested +
                                 sigma_untested_price*draws_untested_price)
  
  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"]] = (b_price*Price1 + b_afla*afla1 + fafla*first_treated_afla1 + safla*second_treated_afla1) 
  
  V[["alt2"]] = (b_price*Price2  + b_nafdac*nafdac2 + fnafdac*first_treated_nafdac2  + snafdac*second_treated_nafdac2)  
  
  V[["alt3"]] = (b_price*Price3 + b_untested*untested3 + funtested*first_treated_untested3 + suntested*second_treated_untested3)
  
  V[["alt4"]] = 0
  
  ### Define settings for MNL model component
  # mnl_settings = list(
  #   alternatives  = c(alt1=1, alt2=2, alt3=3, alt4=4),
  #   avail         = list(alt1=1, alt2=1, alt3=1, alt4=1),
  #   choiceVar     = Choice,
  #   utilities     = V
  # )
  # 
  ### Compute probabilities using MNL model
  ### Compute probabilities for the ST using MNL model
  mnl_settings_ST = list(
    alternatives  = c(alt1=1, alt2=2, alt3=3, alt4=4),
    avail         = list(alt1=1, alt2=1, alt3=1, alt4=1),
    choiceVar     = Choice,
    utilities     = list(alt1 = mu_ST*V[["alt1"]],
                         alt2     = mu_ST*V[["alt2"]],
                         alt3     = mu_ST*V[["alt3"]],
                         alt4     = mu_ST*V[["alt4"]]),
    rows          = (group==3)
  )
  
  P[["ST"]] = apollo_mnl(mnl_settings_ST, functionality)
  
  ### Compute probabilities for the FT using MNL model
  mnl_settings_FT = list(
    alternatives  = c(alt1=1, alt2=2, alt3=3, alt4=4),
    avail         = list(alt1=1, alt2=1, alt3=1, alt4=1),
    choiceVar     = Choice,
    utilities     = list(alt1  = mu_FT*V[["alt1"]],
                         alt2  = mu_FT*V[["alt2"]],
                         alt3  = mu_FT*V[["alt3"]],
                         alt4  = mu_FT*V[["alt4"]]),
    rows          = (group==2)
  )
  
  P[["FT"]] = apollo_mnl(mnl_settings_FT, functionality)
  
  ### Compute probabilities for the control using MNL model
  mnl_settings_control = list(
    alternatives  = c(alt1=1, alt2=2, alt3=3, alt4=4),
    avail         = list(alt1=1, alt2=1, alt3=1, alt4=1),
    choiceVar     = Choice,
    utilities     = list(alt1  = mu_control*V[["alt1"]],
                         alt2  = mu_control*V[["alt2"]],
                         alt3  = mu_control*V[["alt3"]],
                         alt4  = mu_control*V[["alt4"]]),
    rows          = (group==1)
  )
  
  P[["Control"]] = apollo_mnl(mnl_settings_control, functionality)
  
  
  
  
  # 
  #   ### Combined model
  P = apollo_combineModels(P, apollo_inputs, functionality)
  
  #P[["model"]] = apollo_mnl(mnl_settings, 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, estimate_settings=list(maxIterations=400))

# ################################################################# #
#### MODEL OUTPUTS                                               ####
# ################################################################# #

# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN)                               ----
# ----------------------------------------------------------------- #
modelOutput_settings = list(
  printPVal =2,
  printClassical = FALSE
)
apollo_modelOutput(model, modelOutput_settings)

# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO FILE, using model name)               ----
# ----------------------------------------------------------------- #

apollo_saveOutput(model, modelOutput_settings)
stephanehess
Site Admin
Posts: 1339
Joined: 24 Apr 2020, 16:29

Re: Problem with Estimating Scale Parameter

Post by stephanehess »

Hi

did you first try this with MNL rather than Mixed Logit?

And did you also ensure that you get consistent signs across segment-specific models (as opposed to just a single joint model)?

Thanks

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
ayjossy
Posts: 6
Joined: 01 Jun 2023, 19:37

Re: Problem with Estimating Scale Parameter

Post by ayjossy »

Prof., thanks for the prompt response.

1. Yes, I did estimate with MNL and here are the results:
First scenario
Estimate Std.err.
price -0.001 0.000
afla 2.499 0.236
nafdac 1.990 0.217
untested 1.700 0.202
mu_control 1.000 NA
mu_FT 3.354 0.536
mu_ST 2.612 0.383


Second scenario:
Estimate Std.err.
price -0.001 0.000
afla 6.528 0.771
nafdac 5.196 0.667
untested 4.439 0.645
mu_control 0.383 0.056
mu_FT 1.284 0.224
mu_ST 1.000 NA


2. Yes, the signs are consistent across segment-specific models both in MNL and Mixed logit specifications.

Thank you for your anticipated response.
Last edited by ayjossy on 10 Sep 2024, 19:27, edited 1 time in total.
stephanehess
Site Admin
Posts: 1339
Joined: 24 Apr 2020, 16:29

Re: Problem with Estimating Scale Parameter

Post by stephanehess »

sorry, I meant group specific models. so not just scale differences but separate models. and the same for MMNL. That could tell us what is happening here
--------------------------------
Stephane Hess
www.stephanehess.me.uk
ayjossy
Posts: 6
Joined: 01 Jun 2023, 19:37

Re: Problem with Estimating Scale Parameter

Post by ayjossy »

Prof., thank you. Exactly what I meant too. Please, I attached the results of the group-specific models estimated both in MNL and MMNL.
Thank you for your anticipated response.
Attachments
Group_Specific_Model_Results.jpg
Group_Specific_Model_Results.jpg (95.33 KiB) Viewed 111895 times
stephanehess
Site Admin
Posts: 1339
Joined: 24 Apr 2020, 16:29

Re: Problem with Estimating Scale Parameter

Post by stephanehess »

what happens in a joint MNL model. Do the scale differences work there?
--------------------------------
Stephane Hess
www.stephanehess.me.uk
ayjossy
Posts: 6
Joined: 01 Jun 2023, 19:37

Re: Problem with Estimating Scale Parameter

Post by ayjossy »

Dear Prof.,
Thank you. In the joint MNL model, scale parameters depend on which scale I fixed to 1.

Here are the results:

First scenario (When Scale for the control group is fixed to 1)
Estimate Std.err.
price -0.001 0.000
afla 2.499 0.236
nafdac 1.990 0.217
untested 1.700 0.202
mu_control 1.000 NA
mu_FT 3.354 0.536
mu_ST 2.612 0.383

Second scenario (When Scale for one of the treated groups is fixed to 1):
Estimate Std.err.
price -0.001 0.000
afla 6.528 0.771
nafdac 5.196 0.667
untested 4.439 0.645
mu_control 0.383 0.056
mu_FT 1.284 0.224
mu_ST 1.000 NA

Thank you for your anticipated response.
stephanehess
Site Admin
Posts: 1339
Joined: 24 Apr 2020, 16:29

Re: Problem with Estimating Scale Parameter

Post by stephanehess »

Hi

okay, these are of course the same (relative values are identical).

Can you use these as starting values in the MMNL?

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
ayjossy
Posts: 6
Joined: 01 Jun 2023, 19:37

Re: Problem with Estimating Scale Parameter

Post by ayjossy »

Dear Prof.,
Thank you. I think I forgot to mention from the beginning that I did not experience the issue of unexpected (negative) scale values if I specify the price parameter in MMNL to follow normal distribution. I only have the issue when I specify the price parameter to follow log-uniform. And price is the only attribute in my design. Other parameters are estimated as ASCs since I have labelled design. Just to clarify, do you want me to use log of the price coefficient from the MNL as the starting value for price in the log-uniform specification? Thank you for clarifying.

Gbenga
stephanehess
Site Admin
Posts: 1339
Joined: 24 Apr 2020, 16:29

Re: Problem with Estimating Scale Parameter

Post by stephanehess »

Hi

sorry, a bit confused when you say price is the only attribute. Can you give me a bit more detail about the choice setting?

Thanks

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