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.
  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 when estimating a ICLV model with two sources of information

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
Post Reply
samesag
Posts: 4
Joined: 28 Jan 2021, 15:56

Error when estimating a ICLV model with two sources of information

Post by samesag » 28 Jan 2021, 16:26

Dear Stephane and David,

Thank you for developing the Apollo package, and thank you in advance for taking the time to read this issue.

I'm trying to run a model with one (for the moment) LV. In this model, I have two sources of information where one is much bigger than the other (eodh = 21481 obs, and enc = 231 obs), and the LV is only applicable to the enc observations. At first, I tried running the code without estimating a factor scale, ignoring the fact that I have two different sources, and my model was successful. However, I want to have a scale factor for this two sources, so I review the Apollo_example_22.r file to create my code, and the Apollo_example_24.r to include the LV, but I get the following error when using apollo_estimate, which I haven't been able to debug or understand:

Testing likelihood functionError in checkForRemoteErrors(lapply(cl, recvResult)) :
5 nodes produced errors; first error: (subscript) logical subscript too long


My code is this:

# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS ####
# ################################################################# #

### Clear memory
rm(list = ls())

### Load Apollo library
library(apollo)

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
modelName = "BE_LV_V1",
modelDescr = "Modelo estratégico con variables latentes",
indivID = "id_persona",
mixing = TRUE,
nCores = 6
)

# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #

setwd("~/Desktop/estrategico_LV")
database = read.csv("bd_conjunta_V1.csv", header = TRUE, dec = ".")

# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(asc_cero = 0,

asc_moto = 0,
b_inc2_1 = 0,
b_inc3_1 = 0,
b_inc4_1 = 0,
b_inc5_1 = 0,
b_inc6_1 = 0,
b_inc7_1 = 0,
b_inc8_1 = 0,
b_inc9_1 = 0,
b_estr2_1 = 0,
b_estr3_1 = 0,
b_estr4_1 = 0,
b_acthom1_1 = 0,
b_acthom2_1 = 0,
b_acthom3m_1 = 0,
b_com500_1 = 0,
b_Dens_500_1 = 0,
b_Est_TM_1 = 0,
b_Est_SITP_1 = 0,
b_periferia_1 = 0,

asc_carro = 0,
b_inc2_2 = 0,
b_inc3_2 = 0,
b_inc4_2 = 0,
b_inc5_2 = 0,
b_inc6_2 = 0,
b_inc7_2 = 0,
b_inc8_2 = 0,
b_inc9_2 = 0,
b_estr2_2 = 0,
b_estr3_2 = 0,
b_estr4_2 = 0,
b_acthom1_2 = 0,
b_acthom2_2 = 0,
b_acthom3m_2 = 0,
b_com500_2 = 0,
b_Dens_500_2 = 0,
b_Est_TM_2 = 0,
b_Est_SITP_2 = 0,
b_periferia_2 = 0,

asc_ambos = 0,
b_inc2_3 = 0,
b_inc3_3 = 0,
b_inc4_3 = 0,
b_inc5_3 = 0,
b_inc6_3 = 0,
b_inc7_3 = 0,
b_inc8_3 = 0,
b_inc9_3 = 0,
b_estr2_3 = 0,
b_estr3_3 = 0,
b_estr4_3 = 0,
b_acthom1_3 = 0,
b_acthom2_3 = 0,
b_acthom3m_3 = 0,
b_com500_3 = 0,
b_Dens_500_3 = 0,
b_Est_TM_3 = 0,
b_Est_SITP_3 = 0,
b_periferia_3 = 0,

#Funcionalidad auto
lambda_FuncionalidadAuto = 1,

gamma_edad_FuncionalidadAuto = 0,
#gamma_hombre_FuncionalidadAuto = 0,
#gamma_claseBaja_FuncionalidadAuto = 0,
#gamma_claseMedia_FuncionalidadAuto = 0,
#gamma_numPersonas_FuncionalidadAuto = 0,
gamma_numAuto_FuncionalidadAuto = 0,
#gamma_numMoto_FuncionalidadAuto = 0,
gamma_IngDef_FuncionalidadAuto = 0,
#gamma_numVeh_FuncionalidadAuto = 0,

zeta_disp = 1, #p1
zeta_comodo = 1, #p5
zeta_rapido = 1, #p9
zeta_libertad = 1, #p13

tau_disp_1 = -2,
tau_disp_2 = -1,
tau_disp_3 = 1,
tau_disp_4 = 2,
tau_comodo_1 = -2,
tau_comodo_2 = -1,
tau_comodo_3 = 1,
tau_comodo_4 = 2,
tau_rapido_1 = -2,
tau_rapido_2 = -1,
tau_rapido_3 = 1,
tau_rapido_4 = 2,
tau_libertad_1 = -2,
tau_libertad_2 = -1,
tau_libertad_3 = 1,
tau_libertad_4 = 2,

mu_eodh = 1,
mu_enc = 1)

### Vector with names (in quotes) of parameters to be kept fixed at their starting value in apollo_beta, use apollo_beta_fixed = c() if none
apollo_fixed = c("asc_cero", "mu_eodh")

# ################################################################# #
#### DEFINE RANDOM COMPONENTS ####
# ################################################################# #

### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "halton",
interNDraws = 100,
interUnifDraws = c(),
interNormDraws = c("eta_FuncionalidadAuto"),

intraDrawsType = '',
intraNDraws = 0,
intraUnifDraws = c(),
intraNormDraws = c()
)

### Create random parameters
apollo_randCoeff=function(apollo_beta, apollo_inputs){
randcoeff = list()

randcoeff[["FuncionalidadAuto"]] = gamma_edad_FuncionalidadAuto*EDAD +
gamma_numAuto_FuncionalidadAuto*cantidad_vehiculos +
gamma_IngDef_FuncionalidadAuto*IngDef +
eta_FuncionalidadAuto

return(randcoeff)
}

# ################################################################# #
#### GROUP AND VALIDATE INPUTS ####
# ################################################################# #

apollo_inputs = apollo_validateInputs()

# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION ####
# ################################################################# #

apollo_probabilities=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 of probabilities P
P = list()

### Likelihood of indicators
ol_settings1 = list(outcomeOrdered = p1,
V = zeta_disp * FuncionalidadAuto,
tau = c(tau_disp_1, tau_disp_2, tau_disp_3, tau_disp_4),
rows = (enc==1),
componentName = "indic_disp")
ol_settings2 = list(outcomeOrdered = p5,
V = zeta_comodo * FuncionalidadAuto,
tau = c(tau_comodo_1, tau_comodo_2, tau_comodo_3, tau_comodo_4),
rows = (enc==1),
componentName = "indic_comodo")
ol_settings3 = list(outcomeOrdered = p9,
V = zeta_rapido * FuncionalidadAuto,
tau = c(tau_rapido_1, tau_rapido_2, tau_rapido_3, tau_rapido_4),
rows = (enc==1),
componentName = "indic_rapido")
ol_settings4 = list(outcomeOrdered = p13,
V = zeta_libertad * FuncionalidadAuto,
tau = c(tau_libertad_1, tau_libertad_2, tau_libertad_3, tau_libertad_4),
rows = (enc==1),
componentName = "indic_libertad")

P[["indic_disp"]] = apollo_ol(ol_settings1, functionality)
P[["indic_comodo"]] = apollo_ol(ol_settings2, functionality)
P[["indic_rapido"]] = apollo_ol(ol_settings3, functionality)
P[["indic_libertad"]] = apollo_ol(ol_settings4, functionality)


### Likelihood of choices
### List of utilities: these must use the same names as in mnl_settings, order is irrelevant
V = list()
V[['cero']] = asc_cero

V[['moto']] = asc_moto + b_inc2_1 * inc2 + b_inc3_1 * inc3 + b_inc4_1 * inc4 + b_inc5_1 * inc5 + b_inc6_1 * inc6 + b_inc7_1 * inc7 + b_inc8_1 * inc8 + b_inc9_1 * inc9 + b_estr2_1 * estruct2 + b_estr3_1 * estruct3 + b_estr4_1 * estruct4 + b_com500_1 * com_500 + b_Dens_500_1 * Dens_500 + b_Est_TM_1 * Estaciones_TM_1000 + b_Est_SITP_1 * Estaciones_SITP_300 + b_periferia_1 * periferia + b_acthom1_1 * acthom1 + b_acthom2_1 * acthom2 + b_acthom3m_1 * acthom3m

V[['carro']] = asc_carro + b_inc2_2 * inc2 + b_inc3_2 * inc3 + b_inc4_2 * inc4 + b_inc5_2 * inc5 + b_inc6_2 * inc6 + b_inc7_2 * inc7 + b_inc8_2 * inc8 + b_inc9_2 * inc9 + b_estr2_2 * estruct2 + b_estr3_2 * estruct3 + b_estr4_2 * estruct4 + b_com500_2 * com_500 + b_Dens_500_2 * Dens_500 + b_Est_TM_2 * Estaciones_TM_1000 + b_Est_SITP_2 * Estaciones_SITP_300 + b_periferia_2 * periferia + b_acthom1_2 * acthom1 + b_acthom2_2 * acthom2 + b_acthom3m_2 * acthom3m + lambda_FuncionalidadAuto*FuncionalidadAuto

V[['ambos']] = asc_ambos + b_inc2_3 * inc2 + b_inc3_3 * inc3 + b_inc4_3 * inc4 + b_inc5_3 * inc5 + b_inc6_3 * inc6 + b_inc7_3 * inc7 + b_inc8_3 * inc8 + b_inc9_3 * inc9 + b_estr2_3 * estruct2 + b_estr3_3 * estruct3 + b_estr4_3 * estruct4 + b_com500_3 * com_500 + b_Dens_500_3 * Dens_500 + b_Est_TM_3 * Estaciones_TM_1000 + b_Est_SITP_3 * Estaciones_SITP_300 + b_periferia_3 * periferia + b_acthom1_3 * acthom1 + b_acthom2_3 * acthom2 + b_acthom3m_3 * acthom3m


### Define settings for MNL model component
mnl_settings = list(
alternatives = c(cero = 0, moto = 1, carro = 2, ambos = 3),
avail = list(cero = 1, moto = 1, carro = 1, ambos = 1),
choiceVar = respuesta,
V = lapply(V, "*", mu_eodh),
rows = (eodh == 1),
componentName = "MNL_eodh"
)

### Compute probabilities using MNL model

P[['eodh']] = apollo_mnl(mnl_settings, functionality)

### Compute probabilities for the enc part of the data using MNL model
mnl_settings$V = lapply(V, "*", mu_enc)
mnl_settings$rows = (enc == 1)
mnl_settings$componentName = "MNL_enc"

P[['enc']] = apollo_mnl(mnl_settings, functionality)

### Likelihood of the whole model
P = apollo_combineModels(P, apollo_inputs, 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)
}

# ################################################################# #
#### MODEL ESTIMATION ####
# ################################################################# #

### Optional: calculate LL before model estimation
apollo_llCalc(apollo_beta, apollo_probabilities, apollo_inputs)

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

dpalma
Posts: 136
Joined: 24 Apr 2020, 17:54

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

Post by dpalma » 03 Feb 2021, 18:13

Hi,

It is hard to say exactly what is causing the problem, but I would try two things before going into more detail:

1. Try running the model with only one core (so setting nCores = 1 inside apollo_control). Make this change and run the model again.

2. If the previous doesn't work, try adding analyticGrad = FALSE inside apollo_control. Make this change and run the model again.

Let us know if none of this works, and we'll look into ti again.

Cheers
David

samesag
Posts: 4
Joined: 28 Jan 2021, 15:56

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

Post by samesag » 16 Feb 2021, 14:54

Thank you so much, using 1 core solved my issue. May I ask why is necessary to use only 1 core? as this makes the model run considerably slower.

Santiago.

dpalma
Posts: 136
Joined: 24 Apr 2020, 17:54

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

Post by dpalma » 17 Feb 2021, 16:38

Hi Santiago,

Glad to hear the model runs now, but I'm still not sure what the issue is with multiple cores. I would recommend doing these two changes:
  • If you haven't done it yet, please update to the latest version of Apollo (v0.2.3)
  • Define the thresholds inside a list instead of a vector inside ol_settings, so for example:

Code: Select all

ol_settings1 = list(outcomeOrdered = p1,
                    V = zeta_disp * FuncionalidadAuto,
                    tau = list(tau_disp_1, tau_disp_2, tau_disp_3, tau_disp_4),
                    rows = (enc==1),
                    componentName = "indic_disp")
And then try running it again, first with just one core, and then with multiple cores. Please let us know how it goes.

Cheers
David

cybey
Posts: 56
Joined: 26 Apr 2020, 19:38

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

Post by cybey » 02 Mar 2021, 07:22

Hi David,

I found this forum entry as I am currently facing the same problem as Santiago. I am trying to estimate an HCM with parallelization. However, I get the error message mentioned above. Interestingly, this is only the case on some machines, on others it is not, and I do not get an error when I use a very low number of cores (e.g. two instead of a maximum of 95). I have followed all your tips, but unfortunately without success. Do you have any other ideas what the problem could be?

The broad specifications of a workstation where the error occurs:
• Win Server 2019
• Intel Xeon Gold 6248R, 3,0GHz, 24 Cores, 48 Threads, 2TB SSD
• 64 GB Ram

Compared to the other machines I used, this one has much less ram (64 Gb instead of 128 Gb or 256 Gb). Therefore, computationen works with one core and two cores, but with more, let’s say ten, the machine reaches its ram limit. I suspect a low memory to be the problem.

Best
Nico

stephanehess
Site Admin
Posts: 632
Joined: 24 Apr 2020, 16:29

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

Post by stephanehess » 05 Mar 2021, 18:34

Nico/Santiago

we'd like to investigate this issue in more detail. Would you be able to share your data and code with us outside the forum so we can test. We will of course then delete it again

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk

tomas.rossetti
Posts: 18
Joined: 16 Jul 2020, 14:51

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

Post by tomas.rossetti » 17 Mar 2021, 22:03

Hi David and Stephane,

I also bumped into this issue when I tried to use more than one core (nCores = 1 works fine). This happened in a Mac and a Windows machine running Apollo v0.2.4. If you haven't been able to track down the problem, I can also share my code and dataset.

Thanks,

Tomás

stephanehess
Site Admin
Posts: 632
Joined: 24 Apr 2020, 16:29

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

Post by stephanehess » 21 Mar 2021, 17:49

Hi, yes, could you please share the code and data offline with us?
--------------------------------
Stephane Hess
www.stephanehess.me.uk

firstenor
Posts: 8
Joined: 11 Aug 2021, 20:24

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

Post by firstenor » 02 Aug 2022, 00:49

I am getting the same error with a data-fusion model. The code works for MNL estimation, but I get the "logical subscript too long" error even with 1 core. Was there any success in diagnosing this problem last year?

Here is the code:

##### Program based on Example 22 Joint Estimation and Example 14 Uncorrelated Mixed Logit

library(apollo)
apollo_initialise()
apollo_control = list(
modelName ="try2",
modelDescr ="Trying mixed logit.",
indivID ="fuse_ID",
mixing = TRUE,
nCores = 1)

database = read.csv("Fusion_8 studies.csv",header=TRUE)

apollo_beta=c( b_REMDUR =0,
b_MILDDURp =0,
b_MODDURp =0,
b_SEVDURp =0,
b_STERDUR =0,
b_INFRISK =0,
b_CNCRISKANY1pc=0,
b_CNCRISKANY1pu=0,
b_SINFRISK =0,
b_SRGRISKpc =0,
b_JPOUCH =0,
b_SRGASC =0,
mu_PCORICD =1,
mu_PCORIUC =1)

apollo_fixed = c("b_SEVDURp","mu_PCORICD")

# apollo_draws = list(
# interDrawsType = "halton",
# interNDraws = 500,
# interUnifDraws = c(),
# interNormDraws = c("draws_REMDUR","draws_INFRISK"),
# intraDrawsType = "halton",
# intraNDraws = 0,
# intraUnifDraws = c(),
# intraNormDraws = c()
# )
#
# apollo_randCoeff = function(apollo_beta, apollo_inputs){
# randcoeff = list()
#
# randcoeff[["b_REMDUR"]] = -exp( mu_b_REMDUR + sigma_b_REMDUR * draws_REMDUR )
# randcoeff[["b_INFRISK"]] = -exp( mu_b_INFRISK + sigma_b_INFRISK * draws_INFRISK )
#
# 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))

P = list()

V = list()
V[['TREATACD']] = b_REMDUR*PCORICD_REMDUR1 + b_MILDDURp*PCORICD_MILDDUR1 + b_MODDURp*PCORICD_MODDUR1 + b_SEVDURp*PCORICD_SEVDUR1+ b_STERDUR*PCORICD_STERDUR1 + b_INFRISK*PCORICD_INFRISK1 + b_CNCRISKANY1pc*PCORICD_CNCRISK1 + b_SRGRISKpc*PCORICD_SRGRISK1
V[['TREATBCD']] = b_REMDUR*PCORICD_REMDUR2 + b_MILDDURp*PCORICD_MILDDUR2 + b_MODDURp*PCORICD_MODDUR2 + b_SEVDURp*PCORICD_SEVDUR2+ b_STERDUR*PCORICD_STERDUR2 + b_INFRISK*PCORICD_INFRISK2 + b_CNCRISKANY1pc*PCORICD_CNCRISK2 + b_SRGRISKpc*PCORICD_SRGRISK2
V[['TREATAUC']] = b_REMDUR*PCORIUC_REMDUR1 + b_MILDDURp*PCORIUC_MILDDUR1 + b_MODDURp*PCORIUC_MODDUR1 + b_SEVDURp*PCORIUC_SEVDUR1 + b_STERDUR*PCORIUC_STERDUR1 + b_INFRISK*PCORIUC_MINFRISK1 + b_CNCRISKANY1pu*PCORIUC_MCANRISK1
V[['TREATBUC']] = b_REMDUR*PCORIUC_REMDUR2 + b_MILDDURp*PCORIUC_MILDDUR2 + b_MODDURp*PCORIUC_MODDUR2 + b_SEVDURp*PCORIUC_SEVDUR2 + b_STERDUR*PCORIUC_STERDUR2 + b_INFRISK*PCORIUC_MINFRISK2 + b_CNCRISKANY1pu*PCORIUC_MCANRISK2
V[['SURGERYUC']] = b_SRGASC + b_REMDUR*PCORIUC_REMDUR3 + b_SINFRISK*PCORIUC_SINFRISK3 + b_JPOUCH*PCORIUC_JPOUCH3

mnl_settings = list(
alternatives = c(TREATACD=1, TREATBCD=2),
avail = list(TREATACD=1, TREATBCD=1),
choiceVar = PCORICD_CHOICE,
V = lapply(V, "*", mu_PCORICD),
rows = (fuse_PCORICD==1),
componentName = "MNL-PCORICD"
)

P[['PCORICD']] = apollo_mnl(mnl_settings, functionality)

mnl_settings = list(
alternatives = c(TREATAUC=1, TREATBUC=2, SURGERYUC=3),
avail = list(TREATAUC=PCORIUC_TREATAUC, TREATBUC=PCORIUC_TREATBUC, SURGERYUC=PCORIUC_SURGERYUC),
choiceVar = PCORIUC_CHOICE,
V = lapply(V, "*", mu_PCORIUC),
rows = (fuse_PCORIUC==1),
componentName= "RANK-PCORIUC"
)

P[['PCORIUC']]=apollo_mnl(mnl_settings, functionality)


# ### Combined model
P = apollo_combineModels(P, apollo_inputs, 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)
}

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



OUTPUT

Testing likelihood function...
Overview of choices for MNL model component MNL-PCORICD:

Pre-processing likelihood function...
Preparing workers for multithreading...

Testing influence of parameters
Error in checkForRemote
Errors(lapply(cl, recvResult)) :
2 nodes produced errors; first error: (subscript) logical subscript too long

stephanehess
Site Admin
Posts: 632
Joined: 24 Apr 2020, 16:29

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

Post by stephanehess » 09 Aug 2022, 16:32

Hi, what version of Apollo are you using?
--------------------------------
Stephane Hess
www.stephanehess.me.uk

Post Reply