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.

Integrate draws provided by the user into Apollo

Put in requests for new capabilities such as functions for new models.
Post Reply
alvarogutyerrez
Posts: 12
Joined: 19 Jan 2021, 07:53
Contact:

Integrate draws provided by the user into Apollo

Post by alvarogutyerrez »

Dear Stephane and David,

I wondered if it is possible to provide Apollo with draws that the user created. I need a fully-antithetic draws (Andersen, 2014) for a project, and I have written an R function (see below) for that, but I am not sure if it is possible to provide Apollo with it. At the moment, I am using the R package mixl (Molloy, Becker, Schmid & Axhausen, 2021) which allows the user to provide a matrix with draws, but I would like to port my code into Apollo.

Additionally, I am aware of the "antithetic" option available in Apollo. However, as far as I understood the source code of the apollo_makeDraws function it is only one-dimensional antithetic, and not fully antithetic (meaning using all the possible 2^{n-1} combinations, where n is the number of dimensions of the integration.)

Here is the R function I mentioned earlier:

Code: Select all

create_antithetic_sobol_draws <- function(Nindividuals, nDraws, draw_dimensions,scrambling=3){

  ## Uniform scramble Sobol draws
  uniform_sobol_draws <- as.matrix(randtoolbox::sobol(
    n          = Nindividuals * nDraws,
    scrambling = scrambling, #3 = sobolowenfauretezuka scrambling
    dim        = draw_dimensions,
    normal     = FALSE))


  ## Antithetic expansion
  anthi_draw <- do.call(
    rbind,
    apply(X = uniform_sobol_draws,
          MARGIN = 1,
          FUN = function(x) {
            expand.grid(
              data.frame(rbind(x, 1 - x)))})
  )

  ## as matrix
  anthi_draw_matrix <- as.matrix(anthi_draw)

  ## transform into standard normal distribution draws
  normal_anthitetic_scramble_sobol_draws <- stats::qnorm(anthi_draw_matrix)
  ## drop useless colnames
  colnames(normal_anthitetic_scramble_sobol_draws) <- NULL

  # count the total number of draws
  N_final_draws<- nrow(normal_anthitetic_scramble_sobol_draws)/Nindividuals

  cat(N_final_draws, "antithetic draws generated from the original", "\n",
      nDraws, "draws for",
      Nindividuals," individuals expanded using",
      draw_dimensions,"dimensions","\n"  )

  return(normal_anthitetic_scramble_sobol_draws)
}
Thank you for your time!


References
  • Andersen, L. M. (2014). Obtaining reliable likelihood ratio tests from simulated likelihood functions. PloS one, 9(10), e106136.
  • Molloy, J., Becker, F., Schmid, B., & Axhausen, K. W. (2021). mixl: An open-source R package for estimating complex choice models on large datasets. Journal of choice modelling, 39, 100284.
Álvaro A. Gutiérrez-Vargas
https://alvarogutyerrez.github.io/
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Integrate draws provided by the user into Apollo

Post by stephanehess »

Yes, it is possible. See Section 6.1.3 in the manual (towards the end of that section)
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Post Reply