Page 1 of 1

Errors when using sobol draws in RPL

Posted: 28 Jun 2020, 16:34
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

Re: Errors when using sobol draws in RPL

Posted: 28 Jun 2020, 16:36
by stephanehess
Hi Tim

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

Thanks

Stephane

Re: Errors when using sobol draws in RPL

Posted: 29 Jun 2020, 11:38
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'

Re: Errors when using sobol draws in RPL

Posted: 09 Jul 2020, 21:11
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