Page 2 of 2

Re: Error when estimating a ICLV model with two sources of information

Posted: 03 Apr 2024, 13:36
by cbobcat
Hi, I am getting the same error when running models with multiple data sources. I'm using Apollo version 0.3.1. Running on one core works, but increasing the number of cores to 2 (or more) results in this:

Testing influence of parameters
Error in checkForRemoteErrors(lapply(cl, recvResult)) :
one node produced an error: (subscript) logical subscript too long

Has there been any progress on this issue since the last posts?


Posting the code below:

library(apollo)
apollo_initialise()

apollo_control = list(
modelName ="MMNL alt-specific combined indic",
modelDescr ="Mixed logit with combined indicators, scale normalization",
indivID ="RespID",
mixing = TRUE,
nCores = 1,
outputDirectory = "output",
panelData = TRUE
)

database = read.csv("Data_clean.csv", header=TRUE, sep=";")

database = subset(database,database$avail == 1)

apollo_beta = c( asc_m = -0.893299,
asc_r = -1.249897,
asc_opt = 0,
b_comp_mu = 0.156941,
b_comp_sig = 0,
b_m_single_thresh_mu = -0.295765,
b_m_single_thresh_sig = 0,
b_m_stepped_thresh_mu = -0.121848,
b_m_stepped_thresh_sig = 0,
b_m_no_thresh = 0,
b_r_single_thresh_mu = -0.441755,
b_r_single_thresh_sig = 0,
b_r_stepped_thresh_mu = -0.01,
b_r_stepped_thresh_sig = 0,
b_r_no_thresh = 0,
b_sched_start = 0,
b_sched_end_mu = -0.243476,
b_sched_end_sig = 0,
b_sched_install_mu = 0.206316,
b_sched_install_sig = 0,
b_m_mr_owner_mu = 0.051143,
b_m_mr_owner_sig = 0,
b_m_mr_exam = 0,
b_m_mr_consult_mu = 0.056611,
b_m_mr_consult_sig = 0,
b_r_mr_owner_mu = 0,
b_r_mr_owner_sig = 0,
b_r_mr_exam = 0,
b_r_mr_consult_mu = 0.116185,
b_r_mr_consult_sig = 0,
mu_beetlesDK = 1,
mu_birdsDK = 1,
mu_plantsDK = 1,
mu_beetlesFI = 1,
mu_birdsFI = 1,
mu_plantsFI = 1)

apollo_fixed = c("asc_opt", "b_m_no_thresh", "b_r_no_thresh", "b_sched_start", "b_m_mr_exam", "b_r_mr_exam", "mu_beetlesDK")

apollo_draws = list(
interDrawsType = "mlhs",
interNDraws = 500,
interNormDraws = c("draws_comp","draws_m_single_thresh","draws_r_single_thresh","draws_m_stepped_thresh","draws_r_stepped_thresh","draws_sched_end","draws_sched_install","draws_m_mr_owner","draws_r_mr_owner","draws_m_mr_consult","draws_r_mr_consult")
)

apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()

randcoeff[["b_comp"]] = exp(b_comp_mu + b_comp_sig * draws_comp) # lognormal distr
randcoeff[["b_m_single_thresh"]] = b_m_single_thresh_mu + b_m_single_thresh_sig * draws_m_single_thresh
randcoeff[["b_m_stepped_thresh"]] = b_m_stepped_thresh_mu + b_m_stepped_thresh_sig * draws_m_stepped_thresh
randcoeff[["b_r_single_thresh"]] = b_r_single_thresh_mu + b_r_single_thresh_sig * draws_r_single_thresh
randcoeff[["b_r_stepped_thresh"]] = b_r_stepped_thresh_mu + b_r_stepped_thresh_sig * draws_r_stepped_thresh
randcoeff[["b_sched_end"]] = b_sched_end_mu + b_sched_end_sig * draws_sched_end
randcoeff[["b_sched_install"]] = b_sched_install_mu + b_sched_install_sig * draws_sched_install
randcoeff[["b_m_mr_owner"]] = b_m_mr_owner_mu + b_m_mr_owner_sig * draws_m_mr_owner
randcoeff[["b_r_mr_owner"]] = b_r_mr_owner_mu + b_r_mr_owner_sig * draws_r_mr_owner
randcoeff[["b_m_mr_consult"]] = b_m_mr_consult_mu + b_m_mr_consult_sig * draws_m_mr_consult
randcoeff[["b_r_mr_consult"]] = b_r_mr_consult_mu + b_r_mr_consult_sig * draws_r_mr_consult

return(randcoeff)
}

apollo_inputs = apollo_validateInputs()

apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){

apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))

# Create list of probabilities P
P = list()

V = list()
V[['alt_m']] = asc_m + b_comp * (m_comp/10000) + b_m_single_thresh * (m_thresh == 2) + b_m_stepped_thresh * (m_thresh == 1) + b_m_no_thresh * (m_thresh == 0) + b_sched_start * (m_sched == 0) + b_sched_end * (m_sched == 2) + b_sched_install * (m_sched == 1) + b_m_mr_owner * (m_mr == 1) + b_m_mr_exam * (m_mr == 0) + b_m_mr_consult * (m_mr == 2)
V[['alt_r']] = asc_r + b_comp * (r_comp/10000) + b_r_single_thresh * (r_thresh == 2) + b_r_stepped_thresh * (r_thresh == 1) + b_r_no_thresh * (r_thresh == 0) + b_sched_start * (r_sched == 0) + b_sched_end * (r_sched == 2) + b_sched_install * (r_sched == 1) + b_r_mr_owner * (r_mr == 1) + b_r_mr_exam * (r_mr == 0) + b_r_mr_consult * (r_mr == 2)
V[['optout']] = asc_opt


mnl_settings_beetlesDK = list(
alternatives = c(alt_m = 1, alt_r = 2, optout = 0),
choiceVar = choice,
utilities = list(alt_m = mu_beetlesDK*V[["alt_m"]],
alt_r = mu_beetlesDK*V[["alt_r"]],
optout = mu_beetlesDK*V[["optout"]]),
rows = (beetlesDK==1)
)
P[["beetlesDK"]] = apollo_mnl(mnl_settings_beetlesDK, functionality)


mnl_settings_plantsDK = list(
alternatives = c(alt_m = 1, alt_r = 2, optout = 0),
choiceVar = choice,
utilities = list(alt_m = mu_plantsDK*V[["alt_m"]],
alt_r = mu_plantsDK*V[["alt_r"]],
optout = mu_plantsDK*V[["optout"]]),
rows = (plantsDK==1)
)
P[["plantsDK"]] = apollo_mnl(mnl_settings_plantsDK, functionality)


mnl_settings_birdsDK = list(
alternatives = c(alt_m = 1, alt_r = 2, optout = 0),
choiceVar = choice,
utilities = list(alt_m = mu_birdsDK*V[["alt_m"]],
alt_r = mu_birdsDK*V[["alt_r"]],
optout = mu_birdsDK*V[["optout"]]),
rows = (birdsDK==1)
)
P[["birdsDK"]] = apollo_mnl(mnl_settings_birdsDK, functionality)


mnl_settings_beetlesFI = list(
alternatives = c(alt_m = 1, alt_r = 2, optout = 0),
choiceVar = choice,
utilities = list(alt_m = mu_beetlesFI*V[["alt_m"]],
alt_r = mu_beetlesFI*V[["alt_r"]],
optout = mu_beetlesFI*V[["optout"]]),
rows = (beetlesFI==1)
)
P[["beetlesFI"]] = apollo_mnl(mnl_settings_beetlesFI, functionality)


mnl_settings_birdsFI = list(
alternatives = c(alt_m = 1, alt_r = 2, optout = 0),
choiceVar = choice,
utilities = list(alt_m = mu_birdsFI*V[["alt_m"]],
alt_r = mu_birdsFI*V[["alt_r"]],
optout = mu_birdsFI*V[["optout"]]),
rows = (birdsFI==1)
)
P[["birdsFI"]] = apollo_mnl(mnl_settings_birdsFI, functionality)


mnl_settings_plantsFI = list(
alternatives = c(alt_m = 1, alt_r = 2, optout = 0),
choiceVar = choice,
utilities = list(alt_m = mu_plantsFI*V[["alt_m"]],
alt_r = mu_plantsFI*V[["alt_r"]],
optout = mu_plantsFI*V[["optout"]]),
rows = (plantsFI==1)
)
P[["plantsFI"]] = apollo_mnl(mnl_settings_plantsFI, functionality)


P = apollo_combineModels(P, apollo_inputs, functionality)

P = apollo_panelProd(P, apollo_inputs, functionality)

P = apollo_avgInterDraws(P, apollo_inputs, functionality)

# Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}

model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)

apollo_modelOutput(model, modelOutput_settings=list(printPVal = TRUE))

Re: Error when estimating a ICLV model with two sources of information

Posted: 22 Apr 2024, 13:38
by stephanehess
Hi

can you share your code and data with me outside the forum and I'll look into it

Stephane

Re: Error when estimating a ICLV model with two sources of information

Posted: 20 May 2024, 14:57
by stephanehess
Hi

so the issue in your code is due to the fact that when splitting across cores, only one of the model components applies in each core (as your data is sorted by source). We will develop a more elegant solution for this in future, but for now, if you add the following line after reading the data, it should work

database = database[order(database$start),]

Stephane