Page 1 of 1

Error when generating intra-individual draws for mixed logit model

Posted: 30 Apr 2021, 15:38
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

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

Posted: 10 May 2021, 16:22
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

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

Posted: 12 May 2021, 10:39
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

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

Posted: 12 May 2021, 17:12
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