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: Error in paste0 ... result would exceed 2^31-1 bytes

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
Post Reply
jjanmaat
Posts: 11
Joined: 01 Dec 2020, 20:01

Error: Error in paste0 ... result would exceed 2^31-1 bytes

Post by jjanmaat »

Hello,

I am estimating a number of mixed multinomial logit models on choice experiment data. Most of my models solve fine. However, one model run on a subset of the data fails.

apollo_estimate iterates fine. It converges, and then proceeds through the parameter scaling and additional iterations. At the end of this, it states that the estimation has converged, and displays 'Estimated parameters:'. It then pauses for some time, after which it produces the error message:

Error in paste0(rep(" ", max(nchar(m)) - nchar(m)), m, collapse = "") : result would exceed 2^31-1 bytes

The values for apollo_beta are drawn from a previous run of the model. The error is occurring when a subset of the data.

Code: Select all

#
# Set up the random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs) {
  randcoef = list()
  randcoef[["b_Su"]] = m_b_Su + s_b_Su * draws_Su
  randcoef[["b_Ha"]] = m_b_Ha + s_b_Ha * draws_Ha
  randcoef[["b_Sh_50"]] = m_b_Sh_50 + s_b_Sh_50 * draws_Sh_50
  randcoef[["b_Sh_100"]] = m_b_Sh_100 + s_b_Sh_100 * draws_Sh_100
  randcoef[["b_Gv_App"]] = m_b_Gv_App + s_b_Gv_App * draws_Gv_App
  randcoef[["b_Gv_Mul"]] = m_b_Gv_Mul + s_b_Gv_Mul * draws_Gv_Mul
  randcoef[["asc"]] = m_asc + s_asc * draws_asc +
    g_IncMid * (IncChar3Q == "Middle") +
    g_IncUpp * (IncChar3Q == "Upper") +
    g_IncRef * (IncChar3Q == "Refuse") +
    # g_EduHS * (EducChar == "High") +
    g_EduCU * (EducChar == "Coll/Uni") + 
    g_Gen * (GenChar == "Male") + 
    g_Urban * Urban +
    g_AgeMid * (AgeCat3 == "Middle") +
    g_AgeOld * (AgeCat3 == "Old") +
    g_WhyFam * (HuntReason == "Family") +
    g_WhyNat * (HuntReason == "Nature") +
    g_WhyTro * (HuntReason == "Trophy") +
    g_WhereNear * (ToFavCat3 == "Near") +
    g_WhereFar * (ToFavCat3 == "Far") +
    g_PolRight * (PolLean3 == "Right")
  return(randcoef)
}
#
#
# Set up the probabilities for the choices.
apollo_probabilities_mml_pooled <- 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 for probabilities
  P <- list()
  ### Create alternative specific constants
  asc_SQ_value = 0
  asc_Alt_value <- asc 
  ### List of utilities
  V <- list()
  V[['SQ']] <- asc_SQ_value + 
    b_Su * SuS + 
    b_Ha * HaS +
    b_Gv_App * (GvS == "App") +
    b_Gv_Mul * (GvS == "Mul") +
    b_Sh_50 * (ShS == 0.5) + 
    b_Sh_100 * (ShS == 1.0) + 
    b_Li * LiS
  V[['Alt']] <- asc_Alt_value + 
    b_Su * SuA + 
    b_Ha * HaA +
    b_Gv_App * (GvA == "App") +
    b_Gv_Mul * (GvA == "Mul") +
    b_Sh_50 * (ShA == 0.5) + 
    b_Sh_100 * (ShA == 1.0) + 
    b_Li * LiA
  ### MNL settings. Define choices, choice variable, utilities, availability of cases
  mnl_settings <- list(
    alternatives = c(SQ = "S", Alt = "A"),
    avail = 1,
    choiceVar = Ch,
    V = V
  )
  ### Compute probabilities
  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)
}
Suggestions appreciated!

John.
dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: Error: Error in paste0 ... result would exceed 2^31-1 bytes

Post by dpalma »

Hi John,

Could you share your database and the whole script? Without that it's difficult to diagnose the problem. You can email them to D.Palma [at] leeds.ac.uk , they will be treated in a confidential way.

Cheers
David
jjanmaat
Posts: 11
Joined: 01 Dec 2020, 20:01

Re: Error: Error in paste0 ... result would exceed 2^31-1 bytes

Post by jjanmaat »

Hello David,

I did a starting value search, and started with estimates from a previous model run with a larger data set. Those didn't give the error. The resulting estimates where nonsense, very large in absolute value. I updated apollo, and now it reports that the Hessian has some complex eigenvalues, and as such it is not symmetrical.

John.
dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: Error: Error in paste0 ... result would exceed 2^31-1 bytes

Post by dpalma »

Hi John,

Sorry for the belated response.

It does seem like the maximisation of the log-likelihood is running into issues, and it gets trapped in either a local optima, a saddle point, or it has problems converging. You may want to try using a different optimisation algorithm. I would give BHHH a try. You can change the algorithm in the call to apollo_estimate, for example:

Code: Select all

model <- apollo_estimate(apollo_beta,apollo_fixed,apollo_probabilities, apollo_inputs,
                         estimate_settings=list(estimationRoutine="bhhh"))
There is no guarantee that BHHH will work better, but it might be worth the try. You can always try to simplify your model as well. You have multiple random parameters, including the ASC, which can easily cause identification issues. "Walker (2002) Mixed Logit model: dispelling misconceptions of identification" discusses potential issues.

Cheers
David
Post Reply