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.

Errors when using sobol draws in RPL

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
Post Reply
arohamirai
Posts: 18
Joined: 28 Jun 2020, 16:26

Errors when using sobol draws in RPL

Post by arohamirai »

Hi,

Thank you for inventing the Apollo package. I have a question: when I want to use alternative draws, e.g., sobol draws in random parameter model specification, it returns an error:

Error in .Fortran(CF_sobol_f, as.double(qn), as.integer(nb), as.integer(dim), :
Incorrect number of arguments (11), expecting 4 for 'type'

The model can be successfully run with MLHS draws, however, when I changed the interDrawsType from MLHS to sobol, I got the error stated above. I can't find relevant statement about the use of sobol draws in the Mannual; Could you kindly tell me where is the problem?? thank you very much.


Tim
stephanehess
Site Admin
Posts: 1049
Joined: 24 Apr 2020, 16:29

Re: Errors when using sobol draws in RPL

Post by stephanehess »

Hi Tim

Could you please share your code and the full output you see so we can investigate?

Thanks

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
arohamirai
Posts: 18
Joined: 28 Jun 2020, 16:26

Re: Errors when using sobol draws in RPL

Post by arohamirai »

Dear Stephane,

Thank you. Please find the codes and the errors (underlined) below:



CODES
# ################################################################# #
#### 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 ="MMNL",
modelDescr ="MMNL",
indivID ="ID",
nCores = 3,
mixing = TRUE,
noDiagnostics = TRUE
)

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

database = read.csv("R_T1_withSC.csv",header=TRUE)


##renames##
names(database)[names(database)=="id"] <- "ID"

database= subset(database, database$same_answersG==0&same_answersQ==0)


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

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(asc_1 = 0,



asc_3 = 0,



hinc_mu = 0,
hinc_sig = 0,


hdec_mu = 0,
hdec_sig = 0,


vinc = 0,


vdec = 0,


cinc = 0,

cdec = 0


)

### 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_1")

# ################################################################# #
#### DEFINE RANDOM COMPONENTS ####
# ################################################################# #

### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "sobol",
interNDraws = 500,
interUnifDraws = c(),
interNormDraws = c("draws_hinc","draws_hdec"),

intraDrawsType = "halton",
intraNDraws = 0,
intraUnifDraws = c(),
intraNormDraws = c()
)

### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()

randcoeff[["hinc"]] = hinc_mu + hinc_sig*draws_hinc
randcoeff[["hdec"]] = hdec_mu + hdec_sig*draws_hdec


return(randcoeff)
}

# ################################################################# #
#### 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()

### Compute utilities
V=list()
V[['alt1']] = asc_1 + hinc*h_1_inc + hdec*h_1_dec + vinc*v_1_inc + vdec*v_1_dec + cinc*c_1_inc + cdec*c_1_dec

V[['alt2']] = asc_1 + hinc*h_2_inc + hdec*h_2_dec + vinc*v_2_inc + vdec*v_2_dec + cinc*c_2_inc + cdec*c_2_dec

V[['alt3']] = asc_3


### Define settings for MNL model component that are generic across classes
mnl_settings = list(
alternatives = c(alt1=1, alt2=2,alt3=3),
avail = list(alt1=1, alt2=1,alt3=1),
choiceVar = choice,
V = V

)





### Compute probabilities using MNL model
P[['model']] = apollo_mnl(mnl_settings, 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 starting values search
# apollo_beta=apollo_searchStart(apollo_beta, apollo_fixed,apollo_probabilities, apollo_inputs)

model = apollo_estimate(apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs, estimate_settings=list(hessianRoutine="maxLik"))

# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #

# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #

apollo_modelOutput(model)




ERRORS

> # ################################################################# #
> #### GROUP AND VALIDATE INPUTS ####
> # ################################################################# #
>
> apollo_inputs = apollo_validateInputs()
Missing setting for workInLogs, set to default of FALSE
Missing setting for seed, set to default of 13
Missing setting for HB, set to default of FALSE
Several observations per individual detected based on the value of ID.
Setting panelData set to TRUE.
All checks on apollo_control completed.
All checks on data completed.
Generating inter-individual draws Error in .Fortran(CF_sobol_f, as.double(qn), as.integer(nb), as.integer(dim), :
Incorrect number of arguments (11), expecting 2 for 'index'
stephanehess
Site Admin
Posts: 1049
Joined: 24 Apr 2020, 16:29

Re: Errors when using sobol draws in RPL

Post by stephanehess »

Hi Tim

thanks for sharing the code and data with me which allowed me to investigate this. On my machine, the code runs fine with Sobol and with other draws. The error you are getting is actually not by Apollo but by randtoolbox which is called by Apollo for Sobol draws. Can I suggest that in the first place, you try to update randtoolbox to the latest version in case it's not up to date

Best wishes

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Post Reply