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.

Mixed Logit in WTP Space - ***** False convergence *****

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
Post Reply
rafael_lionello
Posts: 10
Joined: 26 Apr 2020, 04:24

Mixed Logit in WTP Space - ***** False convergence *****

Post by rafael_lionello »

Dear Moderators,

I am working to estimate a mixed logit model in the willingness-to-pay (WTP) space using stated preference data. My objective is to estimate brand-specific WTP for consumer goods while evaluating the conditional parameters of the model.

My dataset covers two product categories: beer and chocolate. Each category has three attributes - brand, modifier (e.g., milk, semi-dark, and dark), and price. All parameters are random. And all parameters are alternative-specific, except for price.

The model for beer converged normally. However, in the chocolate model, I encountered a "False convergence" issue. I have attached the code and output for the chocolate model for reference.

Could anyone share insights or experiences on identifying and resolving issues that cause false convergence? Notably, when I set the GENERIC (an abstract, unbranded product) alternative as the reference instead of the OPTOUT, the model converged well with both the beer and chocolate data.

Thank you in advance for any guidance or experience you can share.

Code: Select all

####
## Script Apollo para 6795_2_MMNL_Dummy
#

# Carrega pacote Apollo
library(apollo)

# Set core controls
apollo_control <<- list(
  modelName       = modelName,
  modelDescr      = "Mixed MNL Dummy Coding - Mensuracao e Decomposicao de Brand Equity",
  indivID         = "Respondente",
  panelData       = TRUE,
  nCores          = 20L,
  mixing          = TRUE,
  outputDirectory = "Resultados"
)

#### Define os parametros do modelo ####
# Vetores de parametros, incluindo os que serao fixados em zero na estimacao

apollo_beta <<- c(

  # ASC
  asc_OPTOUT = 0,

  mu_asc_Marca_ARCOR = 0,
  mu_asc_Marca_GAROTO = 0,
  mu_asc_Marca_HERSHEYS = 0,
  mu_asc_Marca_LACTA = 0,
  mu_asc_Marca_NESTLE = 0,
  mu_asc_Marca_NEUGEBAUER = 0,
  mu_asc_Marca_GENERICA = 0,

  sigma_asc_Marca_ARCOR = 0,
  sigma_asc_Marca_GAROTO = 0,
  sigma_asc_Marca_HERSHEYS = 0,
  sigma_asc_Marca_LACTA = 0,
  sigma_asc_Marca_NESTLE = 0,
  sigma_asc_Marca_NEUGEBAUER = 0,
  sigma_asc_Marca_GENERICA  = 0,

  # Modificador
  mu_b_Modificador_2_MEIO_AMARGO_ARCOR = 0,
  mu_b_Modificador_2_MEIO_AMARGO_GAROTO = 0,
  mu_b_Modificador_2_MEIO_AMARGO_HERSHEYS = 0,
  mu_b_Modificador_2_MEIO_AMARGO_LACTA = 0,
  mu_b_Modificador_2_MEIO_AMARGO_NESTLE = 0,
  mu_b_Modificador_2_MEIO_AMARGO_NEUGEBAUER = 0,
  mu_b_Modificador_2_MEIO_AMARGO_GENERICA = 0,
  mu_b_Modificador_3_AMARGO_ARCOR = 0,
  mu_b_Modificador_3_AMARGO_GAROTO = 0,
  mu_b_Modificador_3_AMARGO_HERSHEYS = 0,
  mu_b_Modificador_3_AMARGO_LACTA = 0,
  mu_b_Modificador_3_AMARGO_NESTLE = 0,
  mu_b_Modificador_3_AMARGO_NEUGEBAUER = 0,
  mu_b_Modificador_3_AMARGO_GENERICA = 0,

  sigma_b_Modificador_2_MEIO_AMARGO_ARCOR = 0,
  sigma_b_Modificador_2_MEIO_AMARGO_GAROTO = 0,
  sigma_b_Modificador_2_MEIO_AMARGO_HERSHEYS = 0,
  sigma_b_Modificador_2_MEIO_AMARGO_LACTA = 0,
  sigma_b_Modificador_2_MEIO_AMARGO_NESTLE = 0,
  sigma_b_Modificador_2_MEIO_AMARGO_NEUGEBAUER = 0,
  sigma_b_Modificador_2_MEIO_AMARGO_GENERICA = 0,
  sigma_b_Modificador_3_AMARGO_ARCOR = 0,
  sigma_b_Modificador_3_AMARGO_GAROTO = 0,
  sigma_b_Modificador_3_AMARGO_HERSHEYS = 0,
  sigma_b_Modificador_3_AMARGO_LACTA = 0,
  sigma_b_Modificador_3_AMARGO_NESTLE = 0,
  sigma_b_Modificador_3_AMARGO_NEUGEBAUER = 0,
  sigma_b_Modificador_3_AMARGO_GENERICA = 0,

  # Preco
  mu_log_b_preco = -3,
  sigma_log_b_preco = 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 <<- "asc_OPTOUT"

### DEFINE RANDOM COMPONENTS

### Set parameters for generating draws
apollo_draws = list(
  interDrawsType = "mlhs",
  interNDraws    = 2500L,
  interUnifDraws = c(),
  interNormDraws = c(
    "draws_preco",
    "draws_asc_ARCOR", "draws_asc_GAROTO", "draws_asc_HERSHEYS", "draws_asc_LACTA", "draws_asc_NESTLE", "draws_asc_NEUGEBAUER", "draws_asc_GENERICA",
    "draws_2_MEIO_AMARGO_ARCOR", "draws_2_MEIO_AMARGO_GAROTO", "draws_2_MEIO_AMARGO_HERSHEYS", "draws_2_MEIO_AMARGO_LACTA", "draws_2_MEIO_AMARGO_NESTLE", "draws_2_MEIO_AMARGO_NEUGEBAUER", "draws_2_MEIO_AMARGO_GENERICA", "draws_3_AMARGO_ARCOR", "draws_3_AMARGO_GAROTO", "draws_3_AMARGO_HERSHEYS", "draws_3_AMARGO_LACTA", "draws_3_AMARGO_NESTLE", "draws_3_AMARGO_NEUGEBAUER", "draws_3_AMARGO_GENERICA"
  ),
  intraDrawsType = "mlhs",
  intraNDraws    = 0,
  intraUnifDraws = c(),
  intraNormDraws = c()
)

#### Create random parameters ####
apollo_randCoeff <- function(apollo_beta, apollo_inputs){

  randcoeff <- list()

  randcoeff[["b_preco"]] <- -exp(mu_log_b_preco + sigma_log_b_preco * draws_preco)

  randcoeff[["asc_Marca_ARCOR"]] <- (mu_asc_Marca_ARCOR + sigma_asc_Marca_ARCOR * draws_asc_ARCOR)
  randcoeff[["asc_Marca_GAROTO"]] <- (mu_asc_Marca_GAROTO + sigma_asc_Marca_GAROTO * draws_asc_GAROTO)
  randcoeff[["asc_Marca_HERSHEYS"]] <- (mu_asc_Marca_HERSHEYS + sigma_asc_Marca_HERSHEYS * draws_asc_HERSHEYS)
  randcoeff[["asc_Marca_LACTA"]] <- (mu_asc_Marca_LACTA + sigma_asc_Marca_LACTA * draws_asc_LACTA)
  randcoeff[["asc_Marca_NESTLE"]] <- (mu_asc_Marca_NESTLE + sigma_asc_Marca_NESTLE * draws_asc_NESTLE)
  randcoeff[["asc_Marca_NEUGEBAUER"]] <- (mu_asc_Marca_NEUGEBAUER + sigma_asc_Marca_NEUGEBAUER * draws_asc_NEUGEBAUER)

  randcoeff[["asc_Marca_GENERICA"]] <- (mu_asc_Marca_GENERICA + sigma_asc_Marca_GENERICA * draws_asc_GENERICA)

  randcoeff[["b_Modificador_2_MEIO_AMARGO_ARCOR"]] <- (mu_b_Modificador_2_MEIO_AMARGO_ARCOR + sigma_b_Modificador_2_MEIO_AMARGO_ARCOR * draws_2_MEIO_AMARGO_ARCOR)
  randcoeff[["b_Modificador_2_MEIO_AMARGO_GAROTO"]] <- (mu_b_Modificador_2_MEIO_AMARGO_GAROTO + sigma_b_Modificador_2_MEIO_AMARGO_GAROTO * draws_2_MEIO_AMARGO_GAROTO)
  randcoeff[["b_Modificador_2_MEIO_AMARGO_HERSHEYS"]] <- (mu_b_Modificador_2_MEIO_AMARGO_HERSHEYS + sigma_b_Modificador_2_MEIO_AMARGO_HERSHEYS * draws_2_MEIO_AMARGO_HERSHEYS)
  randcoeff[["b_Modificador_2_MEIO_AMARGO_LACTA"]] <- (mu_b_Modificador_2_MEIO_AMARGO_LACTA + sigma_b_Modificador_2_MEIO_AMARGO_LACTA * draws_2_MEIO_AMARGO_LACTA)
  randcoeff[["b_Modificador_2_MEIO_AMARGO_NESTLE"]] <- (mu_b_Modificador_2_MEIO_AMARGO_NESTLE + sigma_b_Modificador_2_MEIO_AMARGO_NESTLE * draws_2_MEIO_AMARGO_NESTLE)
  randcoeff[["b_Modificador_2_MEIO_AMARGO_NEUGEBAUER"]] <- (mu_b_Modificador_2_MEIO_AMARGO_NEUGEBAUER + sigma_b_Modificador_2_MEIO_AMARGO_NEUGEBAUER * draws_2_MEIO_AMARGO_NEUGEBAUER)
  randcoeff[["b_Modificador_2_MEIO_AMARGO_GENERICA"]] <- (mu_b_Modificador_2_MEIO_AMARGO_GENERICA + sigma_b_Modificador_2_MEIO_AMARGO_GENERICA * draws_2_MEIO_AMARGO_GENERICA)
  randcoeff[["b_Modificador_3_AMARGO_ARCOR"]] <- (mu_b_Modificador_3_AMARGO_ARCOR + sigma_b_Modificador_3_AMARGO_ARCOR * draws_3_AMARGO_ARCOR)
  randcoeff[["b_Modificador_3_AMARGO_GAROTO"]] <- (mu_b_Modificador_3_AMARGO_GAROTO + sigma_b_Modificador_3_AMARGO_GAROTO * draws_3_AMARGO_GAROTO)
  randcoeff[["b_Modificador_3_AMARGO_HERSHEYS"]] <- (mu_b_Modificador_3_AMARGO_HERSHEYS + sigma_b_Modificador_3_AMARGO_HERSHEYS * draws_3_AMARGO_HERSHEYS)
  randcoeff[["b_Modificador_3_AMARGO_LACTA"]] <- (mu_b_Modificador_3_AMARGO_LACTA + sigma_b_Modificador_3_AMARGO_LACTA * draws_3_AMARGO_LACTA)
  randcoeff[["b_Modificador_3_AMARGO_NESTLE"]] <- (mu_b_Modificador_3_AMARGO_NESTLE + sigma_b_Modificador_3_AMARGO_NESTLE * draws_3_AMARGO_NESTLE)
  randcoeff[["b_Modificador_3_AMARGO_NEUGEBAUER"]] <- (mu_b_Modificador_3_AMARGO_NEUGEBAUER + sigma_b_Modificador_3_AMARGO_NEUGEBAUER * draws_3_AMARGO_NEUGEBAUER)
  randcoeff[["b_Modificador_3_AMARGO_GENERICA"]] <- (mu_b_Modificador_3_AMARGO_GENERICA + sigma_b_Modificador_3_AMARGO_GENERICA * draws_3_AMARGO_GENERICA)

  return(randcoeff)
}

#### Agrupa e valida entradas ####
apollo_inputs <<- apollo_validateInputs()

apollo_probabilities <<- function(apollo_beta, apollo_inputs, functionality = "estimate"){

  ### 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[["Marca_ARCOR"]] <- b_preco * (asc_Marca_ARCOR + Preco_ARCOR + b_Modificador_2_MEIO_AMARGO_ARCOR * (Modificador_ARCOR == 2) + b_Modificador_3_AMARGO_ARCOR * (Modificador_ARCOR == 3))
  V[["Marca_GAROTO"]] <- b_preco * (asc_Marca_GAROTO + Preco_GAROTO + b_Modificador_2_MEIO_AMARGO_GAROTO * (Modificador_GAROTO == 2) + b_Modificador_3_AMARGO_GAROTO * (Modificador_GAROTO == 3))
  V[["Marca_HERSHEYS"]] <- b_preco * (asc_Marca_HERSHEYS + Preco_HERSHEYS + b_Modificador_2_MEIO_AMARGO_HERSHEYS * (Modificador_HERSHEYS == 2) + b_Modificador_3_AMARGO_HERSHEYS * (Modificador_HERSHEYS == 3))
  V[["Marca_LACTA"]] <- b_preco * (asc_Marca_LACTA + Preco_LACTA + b_Modificador_2_MEIO_AMARGO_LACTA * (Modificador_LACTA == 2) + b_Modificador_3_AMARGO_LACTA * (Modificador_LACTA == 3))
  V[["Marca_NESTLE"]] <- b_preco * (asc_Marca_NESTLE + Preco_NESTLE + b_Modificador_2_MEIO_AMARGO_NESTLE * (Modificador_NESTLE == 2) + b_Modificador_3_AMARGO_NESTLE * (Modificador_NESTLE == 3))
  V[["Marca_NEUGEBAUER"]] <- b_preco * (asc_Marca_NEUGEBAUER + Preco_NEUGEBAUER + b_Modificador_2_MEIO_AMARGO_NEUGEBAUER * (Modificador_NEUGEBAUER == 2) + b_Modificador_3_AMARGO_NEUGEBAUER * (Modificador_NEUGEBAUER == 3))
  V[["Marca_GENERICA"]] <- b_preco * (asc_Marca_GENERICA + Preco_GENERICA + b_Modificador_2_MEIO_AMARGO_GENERICA * (Modificador_GENERICA == 2) + b_Modificador_3_AMARGO_GENERICA * (Modificador_GENERICA == 3))

  V[["OPTOUT"]] = asc_OPTOUT

  ### Define settings for MNL model component
  mnl_settings <- list(
    alternatives = c(
      Marca_ARCOR = 1,
      Marca_GAROTO = 2,
      Marca_HERSHEYS = 3,
      Marca_LACTA = 4,
      Marca_NESTLE = 5,
      Marca_NEUGEBAUER = 6,
      Marca_GENERICA = 7,
      OPTOUT = 9
    ),
    avail = list(
      Marca_ARCOR = Av_ARCOR,
      Marca_GAROTO = Av_GAROTO,
      Marca_HERSHEYS = Av_HERSHEYS,
      Marca_LACTA = Av_LACTA,
      Marca_NESTLE = Av_NESTLE,
      Marca_NEUGEBAUER = Av_NEUGEBAUER,
      Marca_GENERICA = Av_GENERICA,
      OPTOUT = 1
    ),
    choiceVar = ChoiceMarca,
    utilities = V
  )

  ### Compute probabilities using MNL model
  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_beta,
  apollo_fixed = apollo_fixed,
  apollo_probabilities = apollo_probabilities,
  apollo_inputs = apollo_inputs
)

###
## Fim
#

Code: Select all

apollo_draws and apollo_randCoeff were found, so apollo_control$mixing was set to TRUE
All checks on apollo_control completed.
WARNING: Your database contains some entries that are NA. This may well be intentional, but be advised that if these
  entries are used in your model, the behaviour may be unexpected. 
All checks on database completed.
Generating inter-individual draws ...................... Done
Preparing user-defined functions.

Testing likelihood function...

Overview of choices for MNL model component :
                                 Marca_ARCOR Marca_GAROTO Marca_HERSHEYS Marca_LACTA Marca_NESTLE
Times available                      3155.00      2499.00        3058.00     3056.00      3180.00
Times chosen                          587.00      1023.00        1072.00     1485.00      1499.00
Percentage chosen overall               7.65        13.33          13.97       19.36        19.54
Percentage chosen when available       18.61        40.94          35.06       48.59        47.14
                                 Marca_NEUGEBAUER Marca_GENERICA  OPTOUT
Times available                           3560.00        4508.00 7672.00
Times chosen                               712.00         329.00  965.00
Percentage chosen overall                    9.28           4.29   12.58
Percentage chosen when available            20.00           7.30   12.58


Pre-processing likelihood function...
Creating cluster...
Preparing workers for multithreading...

Testing influence of parameters
Starting main estimation

BGW using analytic model derivatives supplied by caller...


Iterates will be written to: 
 Resultados/6795_2_MMNL_Dummy_iterations.csv
    it    nf     F            RELDF    PRELDF    RELDX    MODEL stppar
     0     1 1.114441322e+04
     1     2 1.093522350e+04 1.877e-02 4.758e-03 1.76e-03   G   9.38e+00
     2     4 1.012623739e+04 7.398e-02 3.454e-02 9.87e-02   G   4.60e-02
     3     6 9.643006465e+03 4.772e-02 2.415e-02 8.47e-02   G   2.34e-01
     4     7 8.959969171e+03 7.083e-02 2.711e-02 3.41e-01   G   0.00e+00
     5     8 8.519732590e+03 4.913e-02 2.859e-02 6.32e-02   G   0.00e+00
     6     9 8.269984266e+03 2.931e-02 1.901e-02 5.06e-02   G   0.00e+00
     7    10 8.127414434e+03 1.724e-02 1.935e-02 7.81e-02   S   0.00e+00
     8    11 8.083487365e+03 5.405e-03 5.721e-03 5.08e-02   S   0.00e+00
     9    14 8.071990142e+03 1.422e-03 1.232e-03 1.04e-02   S   5.57e-01
    10    16 8.058838793e+03 1.629e-03 1.606e-03 3.21e-02   G   4.95e-02
    11    17 8.049888607e+03 1.111e-03 8.660e-04 2.28e-02   G   0.00e+00
    12    18 8.045340131e+03 5.650e-04 7.761e-04 2.19e-02   G   0.00e+00
    13    19 8.042026661e+03 4.118e-04 7.416e-04 1.65e-02   G   0.00e+00
    14    20 8.041799087e+03 2.830e-05 1.135e-03 3.67e-02   G   0.00e+00
    15    21 8.036765691e+03 6.259e-04 1.039e-03 1.94e-02   G   1.15e-01
    16    22 8.035010931e+03 2.183e-04 5.470e-04 1.84e-02   G   0.00e+00
    17    24 8.032612365e+03 2.985e-04 2.158e-04 6.47e-03  G-S  0.00e+00
    18    25 8.032119972e+03 6.130e-05 1.133e-04 8.38e-03   G   0.00e+00
    19    27 8.031384737e+03 9.154e-05 2.132e-04 4.55e-03   G   2.98e-01
    20    28 8.030370978e+03 1.262e-04 2.713e-04 7.47e-03   G   2.65e-01
    21    29 8.030147753e+03 2.780e-05 2.214e-04 4.83e-03   G   2.62e-01
    22    32 8.029527365e+03 7.726e-05 7.227e-05 1.51e-03   S   1.61e+00
    23    34 8.029316679e+03 2.624e-05 2.580e-05 7.03e-04   S   3.41e+00
    24    39 8.029292814e+03 2.972e-06 2.969e-06 1.04e-04   G   2.53e+01
    25    44 8.029290100e+03 3.381e-07 3.380e-07 1.24e-05   G   2.27e+02
    26    48 8.029289412e+03 8.561e-08 8.561e-08 2.80e-06   G   8.28e+02
    27    54 8.029289370e+03 5.295e-09 5.295e-09 1.67e-07   S   1.32e+04
    28    58 8.029289359e+03 1.324e-09 1.324e-09 4.17e-08   S   5.21e+04
    29    67 8.029289359e+03 1.034e-11 1.034e-11 3.26e-10   S   1.81e-01
    30    93 8.029289359e+03 3.225e-12 3.224e-12 1.01e-10   S   1.87e-01
    31   121 8.029289359e+03 7.951e-13 7.959e-13 2.50e-11   S   1.87e-01
    32   150 8.029289359e+03 3.962e-13 3.972e-13 1.25e-11   S   1.87e-01
    33   180 8.029289359e+03 1.997e-13 1.985e-13 6.23e-12   S   1.87e-01
    34   211 8.029289359e+03 9.979e-14 9.928e-14 3.12e-12   S   1.87e-01
    35   243 8.029289359e+03 4.871e-14 4.964e-14 1.56e-12   S   1.87e-01
    36   278 8.029289359e+03 7.703e-15 6.205e-15 1.95e-13   S   1.88e-01

***** False convergence *****

Estimated parameters:
                                                Estimate
asc_OPTOUT                                       0.00000
mu_asc_Marca_ARCOR                              -8.52009
mu_asc_Marca_GAROTO                            -14.46257
mu_asc_Marca_HERSHEYS                          -12.49213
mu_asc_Marca_LACTA                             -15.69918
mu_asc_Marca_NESTLE                            -15.64386
mu_asc_Marca_NEUGEBAUER                         -7.45868
mu_asc_Marca_GENERICA                           -1.23144
sigma_asc_Marca_ARCOR                            4.10243
sigma_asc_Marca_GAROTO                          -5.38929
sigma_asc_Marca_HERSHEYS                         5.16105
sigma_asc_Marca_LACTA                            4.41991
sigma_asc_Marca_NESTLE                           5.05973
sigma_asc_Marca_NEUGEBAUER                      -5.50294
sigma_asc_Marca_GENERICA                        -6.35113
mu_b_Modificador_2_MEIO_AMARGO_ARCOR            -0.12824
mu_b_Modificador_2_MEIO_AMARGO_GAROTO           -0.65644
mu_b_Modificador_2_MEIO_AMARGO_HERSHEYS          0.39638
mu_b_Modificador_2_MEIO_AMARGO_LACTA             0.42927
mu_b_Modificador_2_MEIO_AMARGO_NESTLE           -1.15468
mu_b_Modificador_2_MEIO_AMARGO_NEUGEBAUER        0.31668
mu_b_Modificador_2_MEIO_AMARGO_GENERICA          0.62361
mu_b_Modificador_3_AMARGO_ARCOR                  3.50512
mu_b_Modificador_3_AMARGO_GAROTO                13.84751
mu_b_Modificador_3_AMARGO_HERSHEYS              -0.68583
mu_b_Modificador_3_AMARGO_LACTA                  2.81006
mu_b_Modificador_3_AMARGO_NESTLE                 1.99952
mu_b_Modificador_3_AMARGO_NEUGEBAUER             2.80894
mu_b_Modificador_3_AMARGO_GENERICA               3.34061
sigma_b_Modificador_2_MEIO_AMARGO_ARCOR         -2.42529
sigma_b_Modificador_2_MEIO_AMARGO_GAROTO        -0.09322
sigma_b_Modificador_2_MEIO_AMARGO_HERSHEYS      -4.30614
sigma_b_Modificador_2_MEIO_AMARGO_LACTA         -2.22253
sigma_b_Modificador_2_MEIO_AMARGO_NESTLE         5.78344
sigma_b_Modificador_2_MEIO_AMARGO_NEUGEBAUER    -1.90182
sigma_b_Modificador_2_MEIO_AMARGO_GENERICA      -1.53862
sigma_b_Modificador_3_AMARGO_ARCOR              -6.73370
sigma_b_Modificador_3_AMARGO_GAROTO            -25.56256
sigma_b_Modificador_3_AMARGO_HERSHEYS            2.55299
sigma_b_Modificador_3_AMARGO_LACTA              -5.58133
sigma_b_Modificador_3_AMARGO_NESTLE             -6.26721
sigma_b_Modificador_3_AMARGO_NEUGEBAUER         -7.78105
sigma_b_Modificador_3_AMARGO_GENERICA           -5.05073
mu_log_b_preco                                  -1.04532
sigma_log_b_preco                               -0.88007

Final LL: -8029.2894

WARNING: Your model did not converge properly, and some of your parameter values are tending to +/-
  infinity. This could point to an identification issue. If you want to retain these
  parameters in the model, you may wish to set their value(s) in apollo_beta to the
  estimated value(s), include the parameter name(s) in apollo_fixed, and re-estimate the
  model. 
WARNING: Estimation failed. No covariance matrix to compute. 
Calculating log-likelihood at equal shares (LL(0)) for applicable models...
Calculating log-likelihood at observed shares from estimation data (LL(c)) for applicable
  models...
Calculating LL of each model component...
Calculating other model fit measures
INFORMATION: Your model took more than 10 minutes to estimate, so it was saved to file
  Resultados/6795_2_MMNL_Dummy_model.rds before calculating its covariance matrix. If
  calculation of the covariance matrix fails or is stopped before finishing, you can load
  the model up to this point using apollo_loadModel. 

Your model was estimated using the BGW algorithm. Please acknowledge this by citing Bunch
  et al. (1993) - DOI 10.1145/151271.151279
Unconditional distributions computed
Calculating conditionals...

Cache /Projetos/ConjointAPI/Cache/ModeloConjoint_6795_2_MMNL_Dummy.RDS salvo com sucesso!
Session restored from your saved work on 2024-Nov-13 13:15:09 UTC (1 hour ago)
stephanehess
Site Admin
Posts: 1351
Joined: 24 Apr 2020, 16:29

Re: Mixed Logit in WTP Space - ***** False convergence *****

Post by stephanehess »

Hi

it's difficult to diagnose exactly what is causing the issue here. However, your model is very complex in terms of the number of random components, and is thus likely quite unstable and dependent on the starting values. Did you build the model up gradually and compare it to simpler models?

In addition, it might help to work in preference space rather than WTP space

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
rafael_lionello
Posts: 10
Joined: 26 Apr 2020, 04:24

Re: Mixed Logit in WTP Space - ***** False convergence *****

Post by rafael_lionello »

Hi Stephane, and apologies for the delayed reply.

Following your advice, I simplified the model: now only the ASCs and the (generic) price coefficient are specified as random, while the coefficients for the modifiers (variants) are fixed. The model is still estimated in WTP space and now it is working fine.

Then, I introduced error components (ECs) with panel effects (ex., following the example "ECL_preference_space_panel_effect") to model correlation between alternatives.

However, after including the ECs, I noticed that the heterogeneity in the conditional distributions of the random ASCs essentially disappeared — they collapsed to their means.

I would like to ask two questions:

1) Is this expected behavior when combining error components (panel effects term or even heteroskedasticity) with random ASCs?

2) And more broadly, is it appropriate to include both error components and random ASCs in the same utility function — or is there a more suitable way to capture correlation between alternatives while retaining individual brand-specific effects (e.g., through ASCs)?


Thank you very much again for your guidance,

Rafael

Code: Select all

]####
## Script Apollo para 6795_CHOC_MMNL_Dummy
#

# # Carrega pacote Apollo
# library(apollo)

# Set core controls
apollo_control <<- list(
  modelName       = "ascs_aleatoria_ec_panel",
  modelDescr      = "ascs sao aleatorias, com ec panel effect",
  indivID         = "Respondente",
  panelData       = TRUE,
  nCores          = 20L
)

database <- model$Database

#### Define os parametros do modelo ####
# Vetores de parametros, incluindo os que serao fixados em zero na estimacao

apollo_beta <<- c(
  
  # ASC
  asc_OPTOUT = 0,
  asc_Marca_GENERICA = 0,
  
  mu_asc_Marca_ARCOR = 0,
  mu_asc_Marca_GAROTO = 0,
  mu_asc_Marca_HERSHEYS = 0,
  mu_asc_Marca_LACTA = 0,
  mu_asc_Marca_NESTLE = 0,
  mu_asc_Marca_NEUGEBAUER = 0,
  
  sigma_asc_Marca_ARCOR = 0,
  sigma_asc_Marca_GAROTO = 0,
  sigma_asc_Marca_HERSHEYS = 0,
  sigma_asc_Marca_LACTA = 0,
  sigma_asc_Marca_NESTLE = 0,
  sigma_asc_Marca_NEUGEBAUER = 0,
  
  sigma_panel    = 0.01,
  
  # Modificador
  b_Modificador_2_MEIO_AMARGO_ARCOR = 0,
  b_Modificador_2_MEIO_AMARGO_GAROTO = 0,
  b_Modificador_2_MEIO_AMARGO_HERSHEYS = 0,
  b_Modificador_2_MEIO_AMARGO_LACTA = 0,
  b_Modificador_2_MEIO_AMARGO_NESTLE = 0,
  b_Modificador_2_MEIO_AMARGO_NEUGEBAUER = 0,
  b_Modificador_2_MEIO_AMARGO_GENERICA = 0,
  
  b_Modificador_3_AMARGO_ARCOR = 0,
  b_Modificador_3_AMARGO_GAROTO = 0,
  b_Modificador_3_AMARGO_HERSHEYS = 0,
  b_Modificador_3_AMARGO_LACTA = 0,
  b_Modificador_3_AMARGO_NESTLE = 0,
  b_Modificador_3_AMARGO_NEUGEBAUER = 0,
  b_Modificador_3_AMARGO_GENERICA = 0,
  
  # Preco
  mu_log_b_preco = -5,
  sigma_log_b_preco = -0.01
)

### 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 <<- "asc_OPTOUT"

### DEFINE RANDOM COMPONENTS

### Set parameters for generating draws
apollo_draws = list(
  interDrawsType = "mlhs",
  interNDraws    = 1000L,
  interUnifDraws = c(),
  interNormDraws = c(
    "draws_preco",
    "draws_asc_ARCOR", "draws_asc_GAROTO", "draws_asc_HERSHEYS", "draws_asc_LACTA", "draws_asc_NESTLE", "draws_asc_NEUGEBAUER",
    "draws_ARCOR", "draws_GAROTO", "draws_HERSHEYS", "draws_LACTA", "draws_NESTLE", "draws_NEUGEBAUER", "draws_GENERICA", "draws_OPTOUT"
  ),
  intraDrawsType = "mlhs",
  intraNDraws    = 0,
  intraUnifDraws = c(),
  intraNormDraws = c()
)

#### Create random parameters ####
apollo_randCoeff <- function(apollo_beta, apollo_inputs){
  
  randcoeff <- list()
  
  randcoeff[["b_preco"]] <- -exp(mu_log_b_preco + sigma_log_b_preco * draws_preco)
  
  randcoeff[["asc_Marca_ARCOR"]] <- (mu_asc_Marca_ARCOR + sigma_asc_Marca_ARCOR * draws_asc_ARCOR)
  randcoeff[["asc_Marca_GAROTO"]] <- (mu_asc_Marca_GAROTO + sigma_asc_Marca_GAROTO * draws_asc_GAROTO)
  randcoeff[["asc_Marca_HERSHEYS"]] <- (mu_asc_Marca_HERSHEYS + sigma_asc_Marca_HERSHEYS * draws_asc_HERSHEYS)
  randcoeff[["asc_Marca_LACTA"]] <- (mu_asc_Marca_LACTA + sigma_asc_Marca_LACTA * draws_asc_LACTA)
  randcoeff[["asc_Marca_NESTLE"]] <- (mu_asc_Marca_NESTLE + sigma_asc_Marca_NESTLE * draws_asc_NESTLE)
  randcoeff[["asc_Marca_NEUGEBAUER"]] <- (mu_asc_Marca_NEUGEBAUER + sigma_asc_Marca_NEUGEBAUER * draws_asc_NEUGEBAUER)
  
  randcoeff[["ec_ARCOR"]] <- (sigma_panel * draws_ARCOR)
  randcoeff[["ec_GAROTO"]] <- (sigma_panel * draws_GAROTO)
  randcoeff[["ec_HERSHEYS"]] <- (sigma_panel * draws_HERSHEYS)
  randcoeff[["ec_LACTA"]] <- (sigma_panel * draws_LACTA)
  randcoeff[["ec_NESTLE"]] <- (sigma_panel * draws_NESTLE)
  randcoeff[["ec_NEUGEBAUER"]] <- (sigma_panel * draws_NEUGEBAUER)
  randcoeff[["ec_GENERICA"]] <- (sigma_panel * draws_GENERICA)
  randcoeff[["ec_OPTOUT"]] <- (sigma_panel * draws_OPTOUT)
  
  return(randcoeff)
}

#### Agrupa e valida entradas ####
apollo_inputs <<- apollo_validateInputs()

apollo_probabilities <<- function(apollo_beta, apollo_inputs, functionality = "estimate"){
  
  ### 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[["Marca_ARCOR"]] <- b_preco * (asc_Marca_ARCOR + Preco_ARCOR + b_Modificador_2_MEIO_AMARGO_ARCOR * (Modificador_ARCOR == 2) + b_Modificador_3_AMARGO_ARCOR * (Modificador_ARCOR == 3)) + ec_ARCOR
  V[["Marca_GAROTO"]] <- b_preco * (asc_Marca_GAROTO + Preco_GAROTO + b_Modificador_2_MEIO_AMARGO_GAROTO * (Modificador_GAROTO == 2) + b_Modificador_3_AMARGO_GAROTO * (Modificador_GAROTO == 3)) + ec_GAROTO
  V[["Marca_HERSHEYS"]] <- b_preco * (asc_Marca_HERSHEYS + Preco_HERSHEYS + b_Modificador_2_MEIO_AMARGO_HERSHEYS * (Modificador_HERSHEYS == 2) + b_Modificador_3_AMARGO_HERSHEYS * (Modificador_HERSHEYS == 3)) + ec_HERSHEYS
  V[["Marca_LACTA"]] <- b_preco * (asc_Marca_LACTA + Preco_LACTA + b_Modificador_2_MEIO_AMARGO_LACTA * (Modificador_LACTA == 2) + b_Modificador_3_AMARGO_LACTA * (Modificador_LACTA == 3)) + ec_LACTA
  V[["Marca_NESTLE"]] <- b_preco * (asc_Marca_NESTLE + Preco_NESTLE + b_Modificador_2_MEIO_AMARGO_NESTLE * (Modificador_NESTLE == 2) + b_Modificador_3_AMARGO_NESTLE * (Modificador_NESTLE == 3)) + ec_NESTLE
  V[["Marca_NEUGEBAUER"]] <- b_preco * (asc_Marca_NEUGEBAUER + Preco_NEUGEBAUER + b_Modificador_2_MEIO_AMARGO_NEUGEBAUER * (Modificador_NEUGEBAUER == 2) + b_Modificador_3_AMARGO_NEUGEBAUER * (Modificador_NEUGEBAUER == 3)) + ec_NEUGEBAUER
  V[["Marca_GENERICA"]] <- b_preco * (asc_Marca_GENERICA + Preco_GENERICA + b_Modificador_2_MEIO_AMARGO_GENERICA * (Modificador_GENERICA == 2) + b_Modificador_3_AMARGO_GENERICA * (Modificador_GENERICA == 3)) + ec_GENERICA
  V[["OPTOUT"]] = asc_OPTOUT + ec_OPTOUT
  
  ### Define settings for MNL model component
  mnl_settings <- list(
    alternatives = c(
      Marca_ARCOR = 1,
      Marca_GAROTO = 2,
      Marca_HERSHEYS = 3,
      Marca_LACTA = 4,
      Marca_NESTLE = 5,
      Marca_NEUGEBAUER = 6,
      Marca_GENERICA = 7,
      OPTOUT = 9
    ),
    avail = list(
      Marca_ARCOR = Av_ARCOR,
      Marca_GAROTO = Av_GAROTO,
      Marca_HERSHEYS = Av_HERSHEYS,
      Marca_LACTA = Av_LACTA,
      Marca_NESTLE = Av_NESTLE,
      Marca_NEUGEBAUER = Av_NEUGEBAUER,
      Marca_GENERICA = Av_GENERICA,
      OPTOUT = 1
    ),
    choiceVar = ChoiceMarca,
    utilities = V
  )
  
  ### Compute probabilities using MNL model
  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_beta,
  apollo_fixed = apollo_fixed,
  apollo_probabilities = apollo_probabilities,
  apollo_inputs = apollo_inputs
)

apollo_modelOutput(model)
 
c <- apollo_conditionals(model, apollo_probabilities, apollo_inputs)

saveRDS(model, file = "SandBox/model_chocolate_ascRandom_ecPanel.rds")
saveRDS(c, file = "SandBox/conditionals_chocolate_ascRandom_ecPanel.rds")
# base <- readRDS("conditionals_chocolate.rds")


###
## Fim
# [/code
Last edited by rafael_lionello on 04 Jun 2025, 13:01, edited 8 times in total.
stephanehess
Site Admin
Posts: 1351
Joined: 24 Apr 2020, 16:29

Re: Mixed Logit in WTP Space - ***** False convergence *****

Post by stephanehess »

Rafael

if you have random ASCs, then you essentially already capture the same effect, but you allow for heteroskedasticity. So I'm not sure you add much value with the separate panel term. Were the estimates for the sigmas different across alternatives?

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