Thanks a lot for having developed such as great package.
I'm trying to run a RPL in WTP space following the example_16.
My code :
# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS ####
# ################################################################# #
### Clear memory
rm(list = ls())
### Load Apollo library
library(apollo)
### Initialise code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName ="Apollo_choice_experiment ",
modelDescr ="Mixed logit model in WTP space",
indivID ="id1",
mixing = TRUE,
nCores = 1
)
# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #
database = read.csv("C:/Users/gt340/Documents/”Apollo_data.csv",header=TRUE)
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(
mu_log_b_price =-2,
sigma_log_b_price_inter =0,
mu_b_tenure =-1,
sigma_log_b_tenure_inter =0,
mu_b_savper =0.5,
sigma_log_b_savper_inter =0,
mu_b_time =1,
sigma_log_b_time_inter =0
)
apollo_fixed = c()
# ################################################################# #
#### DEFINE RANDOM COMPONENTS ####
# ################################################################# #
### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "halton",
interNDraws = 100,
interUnifDraws = c(),
interNormDraws = c("draws_price_inter" , "draws_tenure_inter" , "draws_savper_inter","draws_time_inter"),
intraDrawsType = "mlhs",
intraNDraws = 0,
intraUnifDraws = c(),
intraNormDraws = c()
)
### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()
randcoeff[["b_price"]] = -exp( mu_log_b_price
+ sigma_log_b_price_inter * draws_price_inter )
randcoeff[["b_tenure"]] = mu_b_tenure
+ sigma_log_b_tenure_inter* draws_tenure_inter
randcoeff[["b_savper"]] = mu_b_savper
+ sigma_log_b_savper_inter * draws_savper_inter
randcoeff[["b_time"]] = mu_b_time
+ sigma_log_b_time_inter* draws_time_inter
return(randcoeff)
}
# ################################################################# #
#### GROUP AND VALIDATE INPUTS ####
# ################################################################# #
apollo_inputs = apollo_validateInputs()
apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
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[['alt1']] = b_price*(b_tenure*tenure1 + price1 + b_savper*savper1 + b_time*time1)
V[['alt2']] = b_price*(b_tenure*tenure2 + price2 + b_savper*savper2 + b_time*time2)
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(alt1=1, alt2=2),
avail = list(alt1=1, alt2=1),
choiceVar = choice,
V = V
)
### Compute probabilities using MNL model
P[['model']] = apollo_mnl(mnl_settings, functionality)
### Average across intra-individual draws
### P = apollo_avgIntraDraws(P, apollo_inputs, functionality)
### Take product across observation for same individual
P = apollo_panelProd(P, apollo_inputs, functionality)
### Average across inter-individual draws
P = apollo_avgInterDraws(P, apollo_inputs, functionality)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
# ################################################################# #
#### MODEL ESTIMATION ####
# ################################################################# #
### Optional speedTest
#speedTest_settings=list(
# nDrawsTry = c(50, 75, 100),
# nCoresTry = 1:3,
# nRep = 10
#)
#apollo_speedTest(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs, speedTest_settings)
model = apollo_estimate(apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs,
estimate_settings=list(hessianRoutine="maxLik"))
It started the estimation:
Code: Select all
Starting main estimation
Initial function value: -Inf
Initial gradient value:
mu_log_b_price sigma_log_b_price_inter mu_b_tenure
NaN NaN NaN
sigma_log_b_tenure_inter mu_b_savper sigma_log_b_savper_inter
NaN NaN NaN
mu_b_time sigma_log_b_time_inter
NaN NaN
Error in maxOptim(fn = fn, grad = grad, hess = hess, start = start, method = "BFGS", :
NA in the initial gradient
Error in maxOptim(fn = fn, grad = grad, hess = hess, start = start, method = "BFGS", :
NA in the initial gradient
Thank you in advance for you reply!
BTW, I tried to attach my data in the post, but I have received a message when I try to do it:"Invalid file extension: Apollo_data.csv". If it's necessary, I will send you my data.