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)
}
John.