Page 1 of 1

Error in Bayesian estimation between Apollo versions

Posted: 20 May 2021, 15:00
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.

Re: Error in Bayesian estimation between Apollo versions

Posted: 20 May 2021, 15:39
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

Re: Error in Bayesian estimation between Apollo versions

Posted: 06 Dec 2022, 17:40
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

Re: Error in Bayesian estimation between Apollo versions

Posted: 02 Feb 2023, 15:33
by stephanehess
could you share the data with my via e-mail?

Re: Error in Bayesian estimation between Apollo versions

Posted: 02 Feb 2023, 15:39
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

Re: Error in Bayesian estimation between Apollo versions

Posted: 08 Mar 2023, 10:27
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