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 Bayesian estimation between Apollo versions

Report bugs or highlight issues with Apollo functions. At a minimum, please include the part of the output where you believe the bug is manifested. Ideally, please share your model file.
Post Reply
dasham
Posts: 3
Joined: 20 May 2021, 14:38

Error in Bayesian estimation between Apollo versions

Post by dasham »

Hi,

My colleagues and I are running a Bayesian estimation of a mixed logit model. I have apollo version 0.1.0 which I downloaded last year and they have the most updated one. We are running the exact same code and using the same files - however, they receive a warning at the end of the estimation that reads (b_locationL1 is one of the parameters we are estimating):

Error in b_locationL1 * apollo_inputs$apollo_scaling["b_locationL1"] :
non-numeric argument to binary operator

They do not get a summary output after this message. However, I do not receive this error and I am able to get an output and save it. I am wondering if there have been some changes to the code in between the versions that is causing this discrepancy? Further, we have checked to see if there are any non-numeric variables that we are using for the estimate and this is not the case.

Thank you for your help.
dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: Error in Bayesian estimation between Apollo versions

Post by dpalma »

Hi,

There have been many changes in Apollo since v0.1.0. Among them, we changed the way scaling is implemented. However, it is hard to diagnose without looking at the actual code. Could you share the model script and, if possible, a sample of the data?

Cheers
David
Jenni.Fu
Posts: 2
Joined: 06 Dec 2022, 17:05

Re: Error in Bayesian estimation between Apollo versions

Post by Jenni.Fu »

Hi,

I think I have the same issues with the latest version 0.2.8.
Error in b_c * apollo_inputs$apollo_scaling["b_c"] :
non-numeric argument to binary operator

I attached the code below. If needed, is there a way to share the csv data?

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

### Load Apollo library
library(apollo)

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
modelName = "HB_MMNL",
modelDescr = "HB model on choice data",
indivID = "ID.x",
HB = TRUE,
outputDirectory = "output"
)

# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #

### Loading data from package
#testdata <- read.csv("testdata.csv")

database = testdata

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

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(
asc_car = 0,
asc_bus = 0,
asc_air = 0,
asc_rail = 0,
asc_hea = 0,
asc_none = 0,
b_tt = -3,
b_c = -3,
b_te = -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_car")

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

apollo_HB = list(
hbDist = c(
asc_car = "NR",
asc_bus = "N",
asc_air = "N",
asc_rail = "N",
asc_hea = "N",
asc_none = "N",
b_tt = "LN-",
b_c = "LN-",
b_te = "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[['car']] = asc_car + b_c * tc.car + b_tt * tt_min.car + b_te * te.car
V[['rail']] = asc_rail + b_c * tc.rail + b_tt * tt_min.rail + b_te * te.rail
V[['bus']] = asc_bus + b_c * tc.bus + b_tt * tt_min.bus + b_te * te.bus
V[['air']]= asc_air + b_c * tc.air + b_tt * tt_min.air + b_te * te.air
V[['hea']]= asc_hea + b_c * tc.commute_air + b_tt * tt_min.commute_air + b_te * te.commute_air
V[['none']]= asc_none


### Define settings for MNL model component
mnl_settings = list(
alternatives = c(car=1, rail=2, bus=3, air=4, hea=5, none=6),
avail = list(car=1, rail=1, bus=1, air=1, hea=1, none=1),
choiceVar = choice,
V = 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)
}

# ################################################################# #
#### MODEL ESTIMATION ####
# ################################################################# #

model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)

Thank you very much in advance!

Cheers,
Mengying
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Error in Bayesian estimation between Apollo versions

Post by stephanehess »

could you share the data with my via e-mail?
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Jenni.Fu
Posts: 2
Joined: 06 Dec 2022, 17:05

Re: Error in Bayesian estimation between Apollo versions

Post by Jenni.Fu »

Dear Professor,

I just forwarded the data and the script via email. Thank you very much for your help!

Best regards,
Mengying Fu
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Error in Bayesian estimation between Apollo versions

Post by stephanehess »

Thanks for sending this to us. This was a bug that happens when exactly one parameter in a HB model is not random. This has been fixed now in version 0.2.9 which will be released in a couple of weeks
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Post Reply