Page 1 of 1

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

Posted: 28 Sep 2022, 00:28
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.

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

Posted: 28 Sep 2022, 18:11
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

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

Posted: 28 Sep 2022, 21:57
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.

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

Posted: 25 Nov 2022, 16:28
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