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.

Error when generating intra-individual draws for mixed logit model

Ask questions about data format and processing of data, including the use of pre-estimation functions in Apollo. If your question relates to a specific error you are getting, please provide some of the output.
Post Reply
KaatVH
Posts: 2
Joined: 30 Apr 2021, 15:20

Error when generating intra-individual draws for mixed logit model

Post by KaatVH »

Dear all,

I would like to run a mixed logit model with both inter- and intra-individual Sobol draws with Faure-Tezuka scrambling.

However, I get an error message "Error in if (!any(scrambling == 0:3)) stop("invalid argument 'scrambling'") : missing value where TRUE/FALSE needed", after I implement the apollo_validateInputs command.

Code: Select all

apollo_inputs <- apollo_validateInputs()
The data has a panel structure, with 12 observations per individual (here per household).

The whole code from the start (everything runs smoothly until the apollo_validateInputs command):

Code: Select all

apollo_initialise()

apollo_control <- list(
  modelName = "Apollo_MMNL",
  modelDesc = "MMNL model on choice SP data",
  indivID = "hhid_uganda",
  mixing = TRUE,
  nCores = 3,
  seed = 123
  
)

apollo_draws <- list(
  interDrawsType = "sobolFaureTezuka", 
  interNDraws = 50,
  interNormDraws = c("inter_draws_child_m",
                     "inter_draws_child_w",
                     "inter_draws_child2_m",
                     "inter_draws_child2_w",
                     "inter_draws_educHalf_m",
                     "inter_draws_educHalf_w",
                     "inter_draws_educAll_m",
                     "inter_draws_educAll_w",
                     "inter_draws_healthMed_m",
                     "inter_draws_healthMed_w",
                     "inter_draws_healthHigh_m",
                     "inter_draws_healthHigh_w",
                     "inter_draws_nutrHalf_m",
                     "inter_draws_nutrHalf_w",
                     "inter_draws_nutrAll_m",
                     "inter_draws_nutrAll_w",
                     "inter_draws_delta_barg"),
  interUnifDraws=c(),
  intraDrawsType = "sobolFaureTezuka",
  intraNDraws = 50,
  intraNormDraws = c("intra_draws_child_m",
                     "intra_draws_child_w",
                     "intra_draws_child2_m",
                     "intra_draws_child2_w",
                     "intra_draws_educHalf_m",
                     "intra_draws_educHalf_w",
                     "intra_draws_educAll_m",
                     "intra_draws_educAll_w",
                     "intra_draws_healthMed_m",
                     "intra_draws_healthMed_w",
                     "intra_draws_healthHigh_m",
                     "intra_draws_healthHigh_w",
                     "intra_draws_nutrHalf_m",
                     "intra_draws_nutrHalf_w",
                     "intra_draws_nutrAll_m",
                     "intra_draws_nutrAll_w",
                     "intra_draws_delta_barg")
  #intraUnifDraws=c()
)
  

database <- DCE

apollo_beta<- c(
  mu_child_m = 0.17,
  mu_child_w = 0.11,
  mu_child2_m = -0.01,
  mu_child2_w = -0.005,
  mu_educHalf_m = 1.50,
  mu_educHalf_w = 1.98,
  mu_educAll_m = 2.76,
  mu_educAll_w = 3.25,
  mu_healthMed_m = 0.54,
  mu_healthMed_w = 0.8,
  mu_healthHigh_m = 1.15,
  mu_healthHigh_w = 1.32,
  mu_nutrHalf_m = 1.69,
  mu_nutrHalf_w = 1.63,
  mu_nutrAll_m = 1.99,
  mu_nutrAll_w = 1.99,
  mu_delta_barg = -0.69,
  inter_sigma_child_m = 1,
  inter_sigma_child_w = 1,
  inter_sigma_child2_m = 1,
  inter_sigma_child2_w = 1,
  inter_sigma_educHalf_m = 1,
  inter_sigma_educHalf_w = 1,
  inter_sigma_educAll_m = 1,
  inter_sigma_educAll_w = 1,
  inter_sigma_healthMed_m = 1,
  inter_sigma_healthMed_w = 1,
  inter_sigma_healthHigh_m = 1,
  inter_sigma_healthHigh_w = 1,
  inter_sigma_nutrHalf_m = 1,
  inter_sigma_nutrHalf_w = 1,
  inter_sigma_nutrAll_m = 1,
  inter_sigma_nutrAll_w = 1,
  inter_sigma_delta_barg = 0.2,
  intra_sigma_child_m = 1,
  intra_sigma_child_w = 1,
  intra_sigma_child2_m = 1,
  intra_sigma_child2_w = 1,
  intra_sigma_educHalf_m = 1,
  intra_sigma_educHalf_w = 1,
  intra_sigma_educAll_m = 1,
  intra_sigma_educAll_w = 1,
  intra_sigma_healthMed_m = 1,
  intra_sigma_healthMed_w = 1,
  intra_sigma_healthHigh_m = 1,
  intra_sigma_healthHigh_w = 1,
  intra_sigma_nutrHalf_m = 1,
  intra_sigma_nutrHalf_w = 1,
  intra_sigma_nutrAll_m = 1,
  intra_sigma_nutrAll_w = 1,
  intra_sigma_delta_barg = 0.2
)

apollo_fixed <- c()

apollo_inputs <- apollo_validateInputs()
In a previous specification, I implemented the apollo_validateInputs command, after the apollo_randCoeff <- function(apollo_beta, apollo_inputs) command. But this specification also led to the same error in the apollo_validateInputs command.

For completeness I also add the full apollo_randCoeff function:

Code: Select all

apollo_randCoeff <- function(apollo_beta, apollo_inputs){
 
  randcoeff=list()
  
  randcoeff[["beta_child_m"]] <- mu_child_m + inter_sigma_child_m * inter_draws_child_m + intra_sigma_child_m * intra_draws_child_m
  randcoeff[["beta_child_w"]] <- mu_child_w + inter_sigma_child_w * inter_draws_child_w + intra_sigma_child_w * intra_draws_child_w
  randcoeff[["beta_child2_m"]] <- mu_child2_m + inter_sigma_child2_m * inter_draws_child2_m + intra_sigma_child2_m * intra_draws_child2_m
  randcoeff[["beta_child2_w"]] <- mu_child2_w + inter_sigma_child2_w * inter_draws_child2_w + intra_sigma_child2_w * intra_draws_child2_w
  randcoeff[["beta_educHalf_m"]] <- mu_educHalf_m + inter_sigma_educHalf_m * inter_draws_educHalf_m + intra_sigma_educHalf_m * intra_draws_educHalf_m
  randcoeff[["beta_educHalf_w"]] <- mu_educHalf_w + inter_sigma_educHalf_w * inter_draws_educHalf_w + intra_sigma_educHalf_w * intra_draws_educHalf_w
  randcoeff[["beta_educAll_m"]] <- mu_educAll_m + inter_sigma_educAll_m * inter_draws_educAll_m + intra_sigma_educAll_m * intra_draws_educAll_m
  randcoeff[["beta_educAll_w"]] <- mu_educAll_w + inter_sigma_educAll_w * inter_draws_educAll_w + intra_sigma_educAll_w * intra_draws_educAll_w
  randcoeff[["beta_healthMed_m"]] <- mu_healthMed_m + inter_sigma_healthMed_m * inter_draws_healthMed_m + intra_sigma_healthMed_m * intra_draws_healthMed_m
  randcoeff[["beta_healthMed_w"]] <- mu_healthMed_w + inter_sigma_healthMed_w * inter_draws_healthMed_w + intra_sigma_healthMed_w * intra_draws_healthMed_w
  randcoeff[["beta_healthHigh_m"]] <- mu_healthHigh_m + inter_sigma_healthHigh_m * inter_draws_healthHigh_m + intra_sigma_healthHigh_m * intra_draws_healthHigh_m
  randcoeff[["beta_healthHigh_w"]] <- mu_healthHigh_w + inter_sigma_healthHigh_w * inter_draws_healthHigh_w + intra_sigma_healthHigh_w * intra_draws_healthHigh_w
  randcoeff[["beta_nutrHalf_m"]] <- mu_nutrHalf_m + inter_sigma_nutrHalf_m * inter_draws_nutrHalf_m + intra_sigma_nutrHalf_m * intra_draws_nutrHalf_m
  randcoeff[["beta_nutrHalf_w"]] <- mu_nutrHalf_w + inter_sigma_nutrHalf_w * inter_draws_nutrHalf_w + intra_sigma_nutrHalf_w * intra_draws_nutrHalf_w
  randcoeff[["beta_nutrAll_m"]] <- mu_nutrAll_m + inter_sigma_nutrAll_m * inter_draws_nutrAll_m + intra_sigma_nutrAll_m * intra_draws_nutrAll_m
  randcoeff[["beta_nutrAll_w"]] <- mu_nutrAll_w + inter_sigma_nutrAll_w * inter_draws_nutrAll_w + intra_sigma_nutrAll_w * intra_draws_nutrAll_w
  randcoeff[["delta_barg"]] <- exp(mu_delta_barg + inter_sigma_delta_barg * inter_draws_delta_barg + intra_sigma_delta_barg * intra_draws_delta_barg)
  
  return(randcoeff)
}
Thank you very much for any clarification on how to solve this error.
Best regards,
Kaat Van Hoyweghen
dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: Error when generating intra-individual draws for mixed logit model

Post by dpalma »

Hi Kaat,

Sorry for the delayed response.

You found a bug in Apollo. The fix is implemented in v0.2.5, which you will be able to download in a couple of hours from the webpage: http://www.apollochoicemodelling.com/code.html (you need to choose the appropriate file for your operating system)

If you are using RStudio, you install this file simply by selecting Tool > Install Packages... in the menu bar, and then selecting Install from: Package Archive File, and select the file you downloaded.

If you are not using RStudio, then you can run the following code:

Code: Select all

install.packages("C:/path/to/file/apollo_0.2.5.zip", repos=NULL)
Where you need to change "C:/path/to/file/apollo_0.2.5.zip" to the appropriate path to the downloaded file.

Cheers
David
KaatVH
Posts: 2
Joined: 30 Apr 2021, 15:20

Re: Error when generating intra-individual draws for mixed logit model

Post by KaatVH »

Dear David,

Thank you for your reply.

I installed the v0.2.5 version from the link you provided. Unfortunately it still reports the same error when I use Sobol draws with Faure-Tezuka scrambling for the intra-individual draws.

To be able to continue my analyses, I use plain Sobol draws for the intra-individual draws, but I would prefer to add the scrambling for the most optimal analysis.

Cheers,
Kaat
dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: Error when generating intra-individual draws for mixed logit model

Post by dpalma »

Hi Kaat,

Sorry, we got delayed uploading the new version. If you are using windows or linux, please try downloading the files from one of the following links:

Windows: https://www.dropbox.com/s/p54vae5c8iyw1 ... 5.zip?dl=1
Linux (source): https://www.dropbox.com/s/ykcntau9iwpoh ... ar.gz?dl=1

We don't yet have a macOS version, but we should upload it soon to the webpage.
Please let us know if it works out with these files.

Cheers
David
Post Reply