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.

Error in HB estimation with random parameters

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

Error in HB estimation with random parameters

Post by rafael_lionello »

Dear Professor,

I am getting the following error when I add one or more random parameters to a HB model. It happens with different number of random parameters (ex., "asc_tresc" only, "b_cost" only, all parameters except "asc_outro" etc.) or type of distributions (ex., N, CN+, LN-, etc.).
Error in asc_tresc * apollo_inputs$apollo_scaling["asc_tresc"] :
non-numeric argument to binary operator
Ps.: It does not happen when I use non-random parameters only.

I appreciate any directions. Thank you for your time.

Best, Rafael.

Code: Select all

### Set core controls
apollo_control = list(
  modelName       = "HB_MMNL",
  modelDescr      = "HB model on brand choice SP data, mix of random and non-random parameters",
  indivID         = "ResponseId",
  HB              = TRUE, 
  outputDirectory = "output",
  nCores = 24
)


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

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(asc_tresc   = 0,
                asc_pilao   = 0,
                asc_melitta = 0,
                asc_brasil  = 0,
                asc_caboclo = 0,
                asc_pele    = 0,
                asc_fort    = 0,
                asc_outro   = 0,
                b_cost      = -3
                )

### 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_outro")


# ################################################################# #
#### HB settings                                                 ####
# ################################################################# #

apollo_HB = list(
  hbDist = c(asc_tresc = "N",
                     asc_pilao   = "NR",
                     asc_melitta = "NR",
                     asc_brasil  = "NR",
                     asc_caboclo = "NR",
                     asc_pele    = "NR",
                     asc_fort    = "NR",
                     asc_outro   = "NR",
                     b_cost      = "LN-"),
  gNCREP = 50000, # burn-in iterations
  gNEREP = 20000, # post burn-in iterations
  gINFOSKIP = 500)

# ################################################################# #
#### GROUP AND VALIDATE INPUTS                                   ####
# ################################################################# #

apollo_inputs = apollo_validateInputs()



# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION                        ####
# ################################################################# #

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=list()
  V[["tresc"]]   = asc_tresc   + b_cost * Preco_TRES_CORACOES
  V[["pilao"]]   = asc_pilao   + b_cost * Preco_PILAO
  V[["melitta"]] = asc_melitta + b_cost * Preco_MELITTA
  V[["brasil"]]  = asc_brasil  + b_cost * Preco_BRASILEIRO
  V[["caboclo"]] = asc_caboclo + b_cost * Preco_CABOCLO
  V[["pele"]]    = asc_pele    + b_cost * Preco_PELE
  V[["fort"]]    = asc_fort    + b_cost * Preco_FORT
  V[["outro"]]   = 0
    
    
    
  ### Define settings for MNL model component
  mnl_settings = list(
    alternatives  = c(tresc=1, pilao=2, melitta=3, brasil=4, caboclo=5, pele=6, fort=7, outro=99), 
    avail         = list(tresc=1, pilao=1, melitta=1, brasil=1, caboclo=1, pele=1, fort=1, outro=1), 
    choiceVar    = Choice, 
    utilities    = V
  )
  
  ### Compute probabilities using MNL model
  P[["model"]] = apollo_mnl(mnl_settings, functionality)
  
  ### Prepare and return outputs of function
  P = apollo_prepareProb(P, apollo_inputs, functionality)
  return(P)
}
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: Error in HB estimation with random parameters

Post by stephanehess »

Rafael

what version of Apollo are you using?

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

Re: Error in HB estimation with random parameters

Post by rafael_lionello »

Hello, Stephane.

Thank you for your reply.

It should be the last version (v0.2.9). Strangely, however, even after updating (or removing apollo and installing again), I am receiving a message that my version is more than six months old.

Rafael.

library(apollo)

Apollo 0.2.9
http://www.ApolloChoiceModelling.com
See url for a detailed manual, examples and a user forum.
Sign up to the user forum to receive updates on new releases.

WARNING: Your version of Apollo is more than six months old. Using the latest version will
ensure you have all current functionality and bug fixes. You can update to the
latest version by typing: install.packages("apollo")

Current process will resume in 5 seconds unless interrupted by the user.....
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: Error in HB estimation with random parameters

Post by stephanehess »

Rafael

this is a bug (the date warning) that will be resolved in v0.3.0 that is coming out in a couple of weeks

Do you still get the other issue still too?

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

Re: Error in HB estimation with random parameters

Post by rafael_lionello »

Hello, Stephane.

1- Yes, the bug (the date warning) was resolved and it is not showing up anymore.

2- Yes, I am still with the other issue. Would you have any directions on that?


Thank you very much.

Rafael
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: Error in HB estimation with random parameters

Post by stephanehess »

Rafael

apologies for the slow reply, I was on leave

Would you be able to share the code and data with me outside the forum and I'll look into it for you

Thanks

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