Page 1 of 1

Error in HB estimation with random parameters

Posted: 24 Jul 2023, 14:41
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)
}

Re: Error in HB estimation with random parameters

Posted: 24 Jul 2023, 17:08
by stephanehess
Rafael

what version of Apollo are you using?

Stephane

Re: Error in HB estimation with random parameters

Posted: 24 Jul 2023, 17:52
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.....

Re: Error in HB estimation with random parameters

Posted: 10 Aug 2023, 10:10
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

Re: Error in HB estimation with random parameters

Posted: 02 Sep 2023, 14:27
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

Re: Error in HB estimation with random parameters

Posted: 18 Sep 2023, 09:34
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