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.).
Ps.: It does not happen when I use non-random parameters only.Error in asc_tresc * apollo_inputs$apollo_scaling["asc_tresc"] :
non-numeric argument to binary operator
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)
}