Dear Profesors,
Thanks for developing such a powerful tool.
I am trying to estimate a MDCEV model. However, I got the following error message:
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
Preparing user-defined functions.
Error en if (!test) {: valor ausente donde TRUE/FALSE es necesario
I don't know what's happening. I have used this code before and It has worked perfectly well.
Any help would be very appreciated!
Thanks in advance!
I share the code:
# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS: SL PORT CHOICE PAPER ####
# ################################################################# #
### Clear memory
rm(list = ls())
### Load Apollo library
library(apollo)
### Initialise code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName = "MDCEV_SL",
modelDescr = "MDCEV model, alpha-gamma profile, no outside good and constants only in utilities",
indivID = "ID",
outputDirectory = "output"
)
# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #
### Loading data from package
### if data is to be loaded from a file (e.g. called data.csv),
### the code would be: database = read.csv("data.csv",header=TRUE)
database = read.csv("vb.csv",header=TRUE, sep=";")
### Use only SP data
###database = subset(database,database$SP==1)
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(alpha_base = 0,
gamma_barcelona = 1,
gamma_valencia = 1,
delta_valencia = 0,
b_cost = 0,
b_productivity = 0,
b_hinterland = 0,
b_infras = 0,
sig = 1)
### 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("sig", "alpha_base")
# ################################################################# #
#### 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()
### Define individual alternatives
alternatives = c("barcelona",
"valencia")
### Define availabilities
avail = list(barcelona = 1,
valencia = 1)
### Define continuous consumption for individual alternatives
continuousChoice = list(barcelona = barcelona,
valencia = valencia)
### Define utilities for individual alternatives
V = list()
V[["barcelona" ]] = b_cost * costbcn + b_infras * blbcn + b_productivity * prodbcn + b_hinterland * hintbcn
V[["valencia" ]] = delta_valencia + b_cost * costvlc + b_infras * blvlc + b_productivity * prodvlc + b_hinterland * hintvlc
### Define alpha parameters
alpha = list(barcelona = 1 /(1 + exp(-alpha_base)),
valencia = 1 /(1 + exp(-alpha_base)))
### Define gamma parameters
gamma = list(barcelona = gamma_barcelona,
valencia = gamma_valencia)
### Define costs for individual alternatives
cost = list(barcelona = 1,
valencia = 1)
### Define settings for MDCEV model
mdcev_settings <- list(alternatives = alternatives,
avail = avail,
continuousChoice = continuousChoice,
utilities = V,
alpha = alpha,
gamma = gamma,
sigma = sig,
cost = cost,
budget = 1)
### Compute probabilities using MDCEV model
P[["model"]] = apollo_mdcev(mdcev_settings, functionality)
### Take product across observation for same individual
P = apollo_panelProd(P, apollo_inputs, 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)
# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #
apollo_modelOutput(model)
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO FILE, using model name) ----
# ----------------------------------------------------------------- #
apollo_saveOutput(model)
Important: Read this before posting to this forum
- 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.
- 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
- Before asking a question on the forum, users are kindly requested to follow these steps:
- Check that the same issue has not already been addressed in the forum - there is a search tool.
- 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
- Check the frequently asked questions section on the Apollo website, which discusses some common issues/failures. Please see http://www.apollochoicemodelling.com/faq.html
- Make sure that R is using the latest official release of Apollo.
- Users can check which version they are running by entering packageVersion("apollo").
- Then check what is the latest full release (not development version) at http://www.ApolloChoiceModelling.com/code.html.
- To update to the latest official version, just enter install.packages("apollo"). To update to a development version, download the appropriate binary file from http://www.ApolloChoiceModelling.com/code.html, and install the package from file
- If the above steps do not resolve the issue, then users should follow these steps when posting a question:
- provide full details on the issue, including the entire code and output, including any error messages
- posts will not immediately appear on the forum, but will be checked by a moderator first. We check the forum at least twice a week. It may thus take a couple of days for your post to appear and before we reply. There is no need to submit the post multiple times.
Error in estimates in MDCEV
-
stephanehess
- Site Admin
- Posts: 1355
- Joined: 24 Apr 2020, 16:29
Re: Error in estimates in MDCEV
Hi
apologies for the slow reply. Can you confirm you are using the latest version of Apollo? If the error persists, please send me the code and data and I'll have a look for you
Best wishes
Stephane
apologies for the slow reply. Can you confirm you are using the latest version of Apollo? If the error persists, please send me the code and data and I'll have a look for you
Best wishes
Stephane