When I run the example "hybrid_model_bayesian.r" in this website using Apollo v 0.2.1, the following error message appears:
Apollo found a model component of type OL without a componentName. The name was set to "OL" by default.
Error in apollo_ol(ol_settings2, functionality) :
Duplicated componentName found (OL). Names must be different for each component.
This happens not only for the ordered logit model component. When I used the continuous measurement model component with the following likelihood of indicators,
### Likelihood of indicators
normalDensity_settings1 = list(outcomeNormal= comop,
xNormal=zeta_LV1_comop * LV1,
mu=0,
sigma=sigma_LV1_comop,
rows=(ques==1))
normalDensity_settings2 = list(outcomeNormal= dirop,
xNormal=zeta_LV2_dirop * LV2,
mu=0,
sigma=sigma_LV2_dirop,
rows=(ques==1))
normalDensity_settings3 = list(outcomeNormal= dis_op,
xNormal=zeta_LV3_dis_op * LV3,
mu=0,
sigma=sigma_LV3_dis_op,
rows=(ques==1))
normalDensity_settings4 = list(outcomeNormal= un_avoid,
xNormal=zeta_LV4_un_avoid * LV4,
mu=0,
sigma=sigma_LV4_un_avoid,
rows=(ques==1))
P[["indic_comop"]] = apollo_normalDensity(normalDensity_settings1, functionality)
P[["indic_dirop"]] = apollo_normalDensity(normalDensity_settings2, functionality)
P[["indic_dis_op"]] = apollo_normalDensity(normalDensity_settings3, functionality)
P[["indic_un_avoid"]] = apollo_normalDensity(normalDensity_settings4, functionality)
A similar error message appears:
Apollo found a model component of type NormD without a componentName. The name was set to "NormD" by
default.
Summary statistics for NORMD model component NormD:
Min. 1st Qu. Median Mean 3rd Qu. Max.
-2.7529 -0.7529 0.2471 0 0.2471 3.2471
Apollo found a model component of type NormD without a componentName. The name was set to "NormD" by
default.
Error in apollo_normalDensity(normalDensity_settings2, functionality) :
Duplicated componentName found (NormD). Names must be different for each component.
Thanks a lot.
Important: Read this before posting to this forum
- 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.
- 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
- Before asking a question on the forum, users are kindly requested to follow these steps:
- Check that the same issue has not already been addressed in the forum - there is a search tool.
- 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
- Check the frequently asked questions section on the Apollo website, which discusses some common issues/failures. Please see http://www.apollochoicemodelling.com/faq.html
- Make sure that R is using the latest official release of Apollo.
- Users can check which version they are running by entering packageVersion("apollo").
- Then check what is the latest full release (not development version) at http://www.ApolloChoiceModelling.com/code.html.
- To update to the latest official version, just enter install.packages("apollo"). To update to a development version, download the appropriate binary file from http://www.ApolloChoiceModelling.com/code.html, and install the package from file
- If the above steps do not resolve the issue, then users should follow these steps when posting a question:
- provide full details on the issue, including the entire code and output, including any error messages
- 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 message "duplicated componentName" in Hybrid Choice Model using Bayesian approach
Re: Error message "duplicated componentName" in Hybrid Choice Model using Bayesian approach
Hi Derek,
Thank you for letting us know about this bug. The issue arises in v0.2.1 when using multiple components of the same type (e.g. ordered logit) in a model using Bayesian estimation.
We have fixed the bug in version 0.2.2, which you can find on the webpage, section "code": http://www.apollochoicemodelling.com/code.html
Best wishes
David
Thank you for letting us know about this bug. The issue arises in v0.2.1 when using multiple components of the same type (e.g. ordered logit) in a model using Bayesian estimation.
We have fixed the bug in version 0.2.2, which you can find on the webpage, section "code": http://www.apollochoicemodelling.com/code.html
Best wishes
David
Re: Error message "duplicated componentName" in Hybrid Choice Model using Bayesian approach
Hi,
I get the same error message.
"Error in apollo_normalDensity(Qq2, functionality) :
Duplicated componentName found (NormD). Names must be different for each component."
My specification is the following:
I use the latest (0.2.4) version of Apollo.
How could I solve this problem?
Thank you!
David
I get the same error message.
"Error in apollo_normalDensity(Qq2, functionality) :
Duplicated componentName found (NormD). Names must be different for each component."
My specification is the following:
Code: Select all
# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS ####
# ################################################################# #
### Initialise
rm(list = ls())
library(apollo)
apollo_initialise()
### Set core controls
apollo_control = list(
modelName = "HLC",
modelDescr = "Hybrid latent class model",
indivID = "ID",
mixing = TRUE,
nCores = 5
)
database = read.csv("data.csv",header=TRUE)
database$Q19_r1 <- database$Q19_r1 - mean(database$Q19_r1)
database$Q19_r2 <- database$Q19_r2 - mean(database$Q19_r2)
database$Q19_r3 <- database$Q19_r3 - mean(database$Q19_r3)
database$Q19_r4 <- database$Q19_r4 - mean(database$Q19_r4)
database$Q19_r5 <- database$Q19_r5 - mean(database$Q19_r5)
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters
apollo_beta = c(# Structural equation params
gamma_city= 0, gamma_age_above_49= 0, gamma_high_income= 0,
# measurement model params
zeta_q1= 0, zeta_q2= 0, zeta_q3= 0,
zeta_q4= 0, zeta_q5= 0,
sigma_q1= 1, sigma_q2= 1, sigma_q3= 1,
sigma_q4= 1, sigma_q5= 1,
# Class allocation params
piConsA= 0, piLVA= 0,
# Choice params
asc_nc= 0,
# class 1 params
b_eP_a= 0, b_sQ_a= 0,
b_gF_a= 0, b_aF_a= 0, b_price_a= 0,
# class 2 params
b_eP_b= 0, b_sQ_b= 0,
b_gF_b= 0, b_aF_b= 0, b_price_b= 0)
### Name of fixed parameters. c() for none.
apollo_fixed = c()
# ################################################################# #
#### DEFINE RANDOM COMPONENTS ####
# ################################################################# #
### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "halton",
interNDraws = 500,
interUnifDraws = c(),
interNormDraws = c("eta")
)
### Create random parameters
apollo_randCoeff=function(apollo_beta, apollo_inputs){
r = list()
r[["LV"]] = gamma_city*city + gamma_age_above_49*age_above_49 + gamma_high_income*high_income + eta
return(r)
}
# ################################################################# #
#### DEFINE LATENT CLASS COMPONENTS ####
# ################################################################# #
apollo_lcPars=function(apollo_beta, apollo_inputs){
lcpars = list()
### Define lists of parameters for each class
### classA classB ...
lcpars[["b_eP"]] = list(b_eP_a, b_eP_b)
lcpars[["b_sQ"]] = list(b_sQ_a, b_sQ_b)
lcpars[["b_gF"]] = list(b_gF_a, b_gF_b)
lcpars[["b_aF"]] = list(b_aF_a, b_aF_b)
lcpars[["b_price"]] = list(b_price_a, b_price_b)
VA = piConsA + piLVA*LV
VB = 0
piA = exp(VA)/(exp(VA) + exp(VB))
piB = exp(VB)/(exp(VA) + exp(VB))
lcpars[["pi_values"]] = apollo_firstRow(list(piA, piB),
apollo_inputs)
return(lcpars)
}
# ################################################################# #
#### 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 = list()
PClass = list()
### Likelihood of indicators
Qq1 = list(outcomeNormal=Q19_r1, xNormal=zeta_q1*LV, mu=0, sigma=sigma_q1, rows=(task==1))
Qq2 = list(outcomeNormal=Q19_r2, xNormal=zeta_q2*LV, mu=0, sigma=sigma_q2, rows=(task==1))
Qq3 = list(outcomeNormal=Q19_r3, xNormal=zeta_q3*LV, mu=0, sigma=sigma_q3, rows=(task==1))
Qq4 = list(outcomeNormal=Q19_r4, xNormal=zeta_q4*LV, mu=0, sigma=sigma_q4, rows=(task==1))
Qq5 = list(outcomeNormal=Q19_r5, xNormal=zeta_q5*LV, mu=0, sigma=sigma_q5, rows=(task==1))
### Keep only the first row, as it is the only one that matters
P[["Indicator_1"]] = apollo_firstRow( apollo_normalDensity(Qq1, functionality), apollo_inputs )
P[["Indicator_2"]] = apollo_firstRow( apollo_normalDensity(Qq2, functionality), apollo_inputs )
P[["Indicator_3"]] = apollo_firstRow( apollo_normalDensity(Qq3, functionality), apollo_inputs )
P[["Indicator_4"]] = apollo_firstRow( apollo_normalDensity(Qq4, functionality), apollo_inputs )
P[["Indicator_5"]] = apollo_firstRow( apollo_normalDensity(Qq5, functionality), apollo_inputs )
### Likelihood of CHOICES
### Define settings for MNL model component that are generic across classes
cho = list(
alternatives = c(alt1=1, alt2=2, alt3=3, altnc=4),
avail = list(alt1=av_alt1, alt2=av_alt2, alt3=av_alt3, altnc=av_altnc),
choiceVar = choice,
V = list() )
### Loop over classes
S = 2
for(s in 1:S){
### Class-specific utilities
cho$V[['alt1']] = b_eP[[s]] * ( l_alt1 == 2) + b_sQ[[s]] * ( l_alt1 == 3) + b_gF[[s]] * ( h_alt1 == 2) + b_aF[[s]] * ( h_alt1 == 3) + b_price[[s]] * price_alt1
cho$V[['alt2']] = b_eP[[s]] * ( l_alt2 == 2) + b_sQ[[s]] * ( l_alt2 == 3) + b_gF[[s]] * ( h_alt2 == 2) + b_aF[[s]] * ( h_alt2 == 3) + b_price[[s]] * price_alt2
cho$V[['alt3']] = b_eP[[s]] * ( l_alt3 == 2) + b_sQ[[s]] * ( l_alt3 == 3) + b_gF[[s]] * ( h_alt3 == 2) + b_aF[[s]] * ( h_alt3 == 3) + b_price[[s]] * price_alt3
cho$V[['altnc']] = asc_nc
label = paste0("choiceClass",s)
PClass[[label]] = apollo_mnl(cho, functionality)
PClass[[label]] = apollo_panelProd(PClass[[label]], apollo_inputs, functionality)
}
### Mix the probabilities from each class
lc_settings = list(inClassProb=PClass, classProb=pi_values)
P[["choice"]] = apollo_lc(lc_settings, apollo_inputs, functionality)
### Likelihood
P = apollo_combineModels(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 AND OUTPUT ####
# ################################################################# #
s = list(writeIter=FALSE)#, estimationRoutine="bhhh")
model = apollo_estimate(apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs,
estimate_settings=s)
apollo_modelOutput(model)
s = list(saveEst=FALSE, saveCov=FALSE, saveCorr=FALSE,
saveModelObject=FALSE)
apollo_saveOutput(model, saveOutput_settings=s)
How could I solve this problem?
Thank you!
David
Re: Error message "duplicated componentName" in Hybrid Choice Model using Bayesian approach
Hi David,
Please try modifying the settings of your linear models (measurement equations) as follows:
Apollo needs unique names for each model component. Normally, it should automatically assign the name used inside the list P to each component, but for some reason that doesn't seem to be working in your case. We will look into that. In the meantime, try manually assigning the component names, as described above.
If that doesn't work, please share a bit of your data (a few lines will do) so that we can look into the problem in more detail. You can email me the data piece if you prefer to d.palma [at] leeds.ac.uk
Best
David
Please try modifying the settings of your linear models (measurement equations) as follows:
Code: Select all
### Likelihood of indicators
Qq1 = list(outcomeNormal=Q19_r1, xNormal=zeta_q1*LV, mu=0, sigma=sigma_q1, rows=(task==1), componentName='Indicator_1')
Qq2 = list(outcomeNormal=Q19_r2, xNormal=zeta_q2*LV, mu=0, sigma=sigma_q2, rows=(task==1), componentName='Indicator_2')
Qq3 = list(outcomeNormal=Q19_r3, xNormal=zeta_q3*LV, mu=0, sigma=sigma_q3, rows=(task==1), componentName='Indicator_3')
Qq4 = list(outcomeNormal=Q19_r4, xNormal=zeta_q4*LV, mu=0, sigma=sigma_q4, rows=(task==1), componentName='Indicator_4')
Qq5 = list(outcomeNormal=Q19_r5, xNormal=zeta_q5*LV, mu=0, sigma=sigma_q5, rows=(task==1), componentName='Indicator_5')
If that doesn't work, please share a bit of your data (a few lines will do) so that we can look into the problem in more detail. You can email me the data piece if you prefer to d.palma [at] leeds.ac.uk
Best
David
Re: Error message "duplicated componentName" in Hybrid Choice Model using Bayesian approach
Hi David!
Thank you very much!
It worked perfectly!
Best wishes,
David
Thank you very much!
It worked perfectly!
Best wishes,
David