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. In addition, help files are available for all functions, using e.g. ?apollo_mnl
  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.

"Paramter does not influence the log-likelihood of your model" after included LV

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
Boris
Posts: 4
Joined: 10 Dec 2021, 14:37

"Paramter does not influence the log-likelihood of your model" after included LV

Post by Boris »

Hi Stephane and David,

I am stuck with this problem for some time already and your assistance would be of great help.
I have data from an unlabelled ch. experiment. Choice sets consist of 3 alternatives: two "products" plus an optout option. Before adding the LV, a specified MNL model was working without problems. In this model, there were two attributes with 3 levels (type of online presentation) and (type of product) and a price attribute with 5 levels.

In addition to it, I wanted to add LV of trust towards certifying institutions (inst.trust), which possibly influences the choice in a choice experiments. This trust is determined by 4 indicators (columns x1-x4) in the dataset. Because the mentioned trust is towards the institutions which certify organic food, the underlying LV component should influence the choice of organic products. After trying to run such a model I get information that one of the b parameters does not influence the LL. Can you check, please, where the problem could be?

Also, can you briefly explain the reason for not using asc in your LV example (Drugs data)? I know the definition of the ASC but somehow it is not quite clear to me. Until now, in my analysis, I was using one asc in both Vs following the principle used for unlabelled exp. with opt out shown in http://lab.agr.hokudai.ac.jp/nmvr/02-dce.html.

Sorry for the long post,
Boris


rm(list = ls())
library(apollo)
apollo_initialise()
apollo_control = list(
modelName = "ICLV",
modelDescr = "ICLV model, LV is trust towards cert. institututions, continuous measurement model",
indivID = "id.respondent",
mixing = TRUE,
nCores = 3
)

database = read.csv2("5.2 Survey N=140_all.csv",header=TRUE)
apollo_beta = c(asc = 0,
b_Conventional = 0,
b_Conversion = 0,
b_Organic = 0,
b_Offline = 0,
b_Web = 0,
b_FB = 0,
b_Prices_abs = 0,
lambda = 0,
zeta_inst.trust1 = 1,
zeta_inst.trust2 = 1,
zeta_inst.trust3 = 1,
zeta_inst.trust4 = 1,
mu_inst.trust1 = 0,
mu_inst.trust2 = 0,
mu_inst.trust3 = 0,
mu_inst.trust4 = 0,
sigma_inst.trust1 = 1,
sigma_inst.trust2 = 1,
sigma_inst.trust3 = 1,
sigma_inst.trust4 = 1)
apollo_fixed = c("b_Conventional", "b_Offline")


apollo_draws = list(
interDrawsType="halton",
interNDraws=100,
interUnifDraws=c(),
interNormDraws=c("eta"),
intraDrawsType='',
intraNDraws=0,
intraUnifDraws=c(),
intraNormDraws=c()
)

apollo_randCoeff=function(apollo_beta, apollo_inputs){
randcoeff = list()
randcoeff[["LV"]] = eta
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()
normalDensity_settings1 = list(outcomeNormal=x1,
xNormal=zeta_inst.trust1*LV,
mu=mu_inst.trust1,
sigma=sigma_inst.trust1,
rows=(ch.set==1))
normalDensity_settings2 = list(outcomeNormal=x2,
xNormal=zeta_inst.trust2*LV,
mu=mu_inst.trust2,
sigma=sigma_inst.trust2,
rows=(ch.set==1))
normalDensity_settings3 = list(outcomeNormal=x3,
xNormal=zeta_inst.trust3*LV,
mu=mu_inst.trust3,
sigma=sigma_inst.trust3,
rows=(ch.set==1))
normalDensity_settings4 = list(outcomeNormal=x4,
xNormal=zeta_inst.trust4*LV,
mu=mu_inst.trust4,
sigma=sigma_inst.trust4,
rows=(ch.set==1))
P[["indic_inst.trust1"]] = apollo_normalDensity(normalDensity_settings1, functionality)
P[["indic_inst.trust2"]] = apollo_normalDensity(normalDensity_settings2, functionality)
P[["indic_inst.trust3"]] = apollo_normalDensity(normalDensity_settings3, functionality)
P[["indic_inst.trust4"]] = apollo_normalDensity(normalDensity_settings4, functionality)

V = list()
V[['alt1']] = asc + b_Conventional*Conventional.1 + b_Conversion*Conversion.1+ b_Offline*Offline.1
+ b_Offline*Offline.1 + b_Web*Web.1 + b_FB*FB.1
+ b_Prices_abs*Prices_abs.1
+ Organic.1*lambda*LV;
V[['alt2']] = asc + b_Conventional*Conventional.2 + b_Conversion*Conversion.2+ b_Offline*Offline.2
+ b_Offline*Offline.2 + b_Web*Web.2 + b_FB*FB.2
+ b_Prices_abs*Prices_abs.2
+ Organic.2*lambda*LV;
V[['alt3']] = 0;


mnl_settings = list(
alternatives = c(alt1=1, alt2=2, alt3=3),
avail = list(alt1=1, alt2=1, alt3=1),
choiceVar = choice,
V = V
)

P[["choice"]] = apollo_mnl(mnl_settings, functionality)
P = apollo_combineModels(P, apollo_inputs, functionality)
P = apollo_panelProd(P, apollo_inputs, functionality)
P = apollo_avgInterDraws(P, apollo_inputs, functionality)
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}

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

apollo_modelOutput(model)
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: "Paramter does not influence the log-likelihood of your model" after included LV

Post by stephanehess »

Boris

can you please show us the output?

Regarding ASCs in the drug choice data, you could test for position effects by using ASCs in this data too

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Boris
Posts: 4
Joined: 10 Dec 2021, 14:37

Re: "Paramter does not influence the log-likelihood of your model" after included LV

Post by Boris »

Thank you for the fast answer,
Please find the complete console output below.
As additional information, f I exclude the parameter which doesn't influence the LL (level for Organic products) the problem continues to appear with another b.


> rm(list = ls())
>
>
> library(apollo)
Apollo 0.2.4
www.ApolloChoiceModelling.com
See url for a detailed manual, examples and a help forum.
Sign up to our mailing list for updates on new releases.
>
> apollo_initialise()
Apollo ignition sequence completed
>
>
> apollo_control = list(
+ modelName = "ICLV",
+ modelDescr = "ICLV model, LV is trust towards cert. institututions, continuous measurement model",
+ indivID = "id.respondent",
+ mixing = TRUE,
+ nCores = 3
+ )
>
>
> database = read.csv2("5.2 Survey N=140_all.csv",header=TRUE)
>
>
> apollo_beta = c(asc = 0,
+ b_Conventional = 0,
+ b_Conversion = 0,
+ b_Organic = 0,
+ b_Offline = 0,
+ b_Web = 0,
+ b_FB = 0,
+ b_Prices_abs = 0,
+ lambda = 0,
+ zeta_inst.trust1 = 1,
+ zeta_inst.trust2 = 1,
+ zeta_inst.trust3 = 1,
+ zeta_inst.trust4 = 1,
+ mu_inst.trust1 = 0,
+ mu_inst.trust2 = 0,
+ mu_inst.trust3 = 0,
+ mu_inst.trust4 = 0,
+ sigma_inst.trust1 = 1,
+ sigma_inst.trust2 = 1,
+ sigma_inst.trust3 = 1,
+ sigma_inst.trust4 = 1)
>
> apollo_fixed = c("b_Conventional", "b_Offline")
>
>
> apollo_draws = list(
+ interDrawsType="halton",
+ interNDraws=100,
+ interUnifDraws=c(),
+ interNormDraws=c("eta"),
+
+ intraDrawsType='',
+ intraNDraws=0,
+ intraUnifDraws=c(),
+ intraNormDraws=c()
+ )
>
> apollo_randCoeff=function(apollo_beta, apollo_inputs){
+ randcoeff = list()
+
+ randcoeff[["LV"]] = eta
+
+ return(randcoeff)
+ }
>
>
> apollo_inputs = apollo_validateInputs()
Several observations per individual detected based on the value of id.respondent. Setting panelData in apollo_control set
to TRUE.
All checks on apollo_control completed.
All checks on database completed.
Generating inter-individual draws . Done
>
>
> 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()
+
+ normalDensity_settings1 = list(outcomeNormal=x1,
+ xNormal=zeta_inst.trust1*LV,
+ mu=mu_inst.trust1,
+ sigma=sigma_inst.trust1,
+ rows=(ch.set==1))
+ normalDensity_settings2 = list(outcomeNormal=x2,
+ xNormal=zeta_inst.trust2*LV,
+ mu=mu_inst.trust2,
+ sigma=sigma_inst.trust2,
+ rows=(ch.set==1))
+ normalDensity_settings3 = list(outcomeNormal=x3,
+ xNormal=zeta_inst.trust3*LV,
+ mu=mu_inst.trust3,
+ sigma=sigma_inst.trust3,
+ rows=(ch.set==1))
+ normalDensity_settings4 = list(outcomeNormal=x4,
+ xNormal=zeta_inst.trust4*LV,
+ mu=mu_inst.trust4,
+ sigma=sigma_inst.trust4,
+ rows=(ch.set==1))
+ P[["indic_inst.trust1"]] = apollo_normalDensity(normalDensity_settings1, functionality)
+ P[["indic_inst.trust2"]] = apollo_normalDensity(normalDensity_settings2, functionality)
+ P[["indic_inst.trust3"]] = apollo_normalDensity(normalDensity_settings3, functionality)
+ P[["indic_inst.trust4"]] = apollo_normalDensity(normalDensity_settings4, functionality)
+
+ V = list()
+ V[['alt1']] = asc + b_Conventional*Conventional.1 + b_Conversion*Conversion.1+ b_Offline*Offline.1
+ + b_Offline*Offline.1 + b_Web*Web.1 + b_FB*FB.1
+ + b_Prices_abs*Prices_abs.1
+ + Organic.1*lambda*LV;
+ V[['alt2']] = asc + b_Conventional*Conventional.2 + b_Conversion*Conversion.2+ b_Offline*Offline.2
+ + b_Offline*Offline.2 + b_Web*Web.2 + b_FB*FB.2
+ + b_Prices_abs*Prices_abs.2
+ + Organic.2*lambda*LV;
+ V[['alt3']] = 0;
+
+
+ mnl_settings = list(
+ alternatives = c(alt1=1, alt2=2, alt3=3),
+ avail = list(alt1=1, alt2=1, alt3=1),
+ choiceVar = choice,
+ V = V
+ )
+
+ P[["choice"]] = apollo_mnl(mnl_settings, functionality)
+
+ P = apollo_combineModels(P, apollo_inputs, functionality)
+
+ P = apollo_panelProd(P, apollo_inputs, functionality)
+
+ P = apollo_avgInterDraws(P, apollo_inputs, functionality)
+
+ P = apollo_prepareProb(P, apollo_inputs, functionality)
+ return(P)
+ }
>
> model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)

Testing likelihood function...
Apollo found a model component of type NormD without a componentName. The name was set to "indic_inst.trust1" by default.

Summary statistics for NORMD model component indic_inst.trust1:
Min. 1st Qu. Median Mean 3rd Qu. Max.
2 4 5 5.15 6 7
Apollo found a model component of type NormD without a componentName. The name was set to "indic_inst.trust2" by default.

Summary statistics for NORMD model component indic_inst.trust2:
Min. 1st Qu. Median Mean 3rd Qu. Max.
1 3 5 4.8714 6 7
Apollo found a model component of type NormD without a componentName. The name was set to "indic_inst.trust3" by default.

Summary statistics for NORMD model component indic_inst.trust3:
Min. 1st Qu. Median Mean 3rd Qu. Max.
1 4 5 4.9714 6 7
Apollo found a model component of type NormD without a componentName. The name was set to "indic_inst.trust4" by default.

Summary statistics for NORMD model component indic_inst.trust4:
Min. 1st Qu. Median Mean 3rd Qu. Max.
1 4 5 4.8571 6 7
Apollo found a model component of type MNL without a componentName. The name was set to "choice" by default.

Overview of choices for MNL model component choice:
alt1 alt2 alt3
Times available 2100.0 2100.00 2100.00
Times chosen 821.0 837.00 442.00
Percentage chosen overall 39.1 39.86 21.05
Percentage chosen when available 39.1 39.86 21.05

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

Testing influence of parameters..Error in apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, :
Parameter b_Organic does not influence the log-likelihood of your model!
>
> apollo_modelOutput(model)
Error in apollo_modelOutput(model) : object 'model' not found
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: "Paramter does not influence the log-likelihood of your model" after included LV

Post by stephanehess »

Looking at your code, you have the parameter b_Organic defined in apollo_beta, but it is not used anywhere in your model.
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Boris
Posts: 4
Joined: 10 Dec 2021, 14:37

Re: "Paramter does not influence the log-likelihood of your model" after included LV

Post by Boris »

Oh, that is quite embarrassing, I apologise for posting such a code with an error. The posted code was an intermediate step of my different tries to make the code work, and I mistakenly posted it here. Unfortunately, even after including b_Organic in the utility functions, the error appears again, now for b_Prices_abs (code below). For the sake of trying to make the code just work, I excluded b_Prices_abs from defined betas and from utility functions (together with Organic.1 and .2) and the error just moves to another parameter, in this case, lambda.


> rm(list = ls())
>
>
> library(apollo)
Apollo 0.2.6
www.ApolloChoiceModelling.com
See url for a detailed manual, examples and a help forum.
Sign up to our mailing list for updates on new releases.
Warning message:
package ‘apollo’ was built under R version 4.1.2
>
> apollo_initialise()
Apollo ignition sequence completed
>
>
> apollo_control = list(
+ modelName = "ICLV",
+ modelDescr = "ICLV model, LV is trust towards cert. institututions, continuous measurement model",
+ indivID = "id.respondent",
+ mixing = TRUE,
+ nCores = 3
+ )
>
>
> database = read.csv2("5.2 Survey N=140_all.csv",header=TRUE)
>
>
> apollo_beta = c(asc = 0,
+ b_Conventional = 0,
+ b_Conversion = 0,
+ b_Organic = 0,
+ b_Offline = 0,
+ b_Web = 0,
+ b_FB = 0,
+ b_Prices_abs = 0,
+ lambda = 0,
+ zeta_inst.trust1 = 1,
+ zeta_inst.trust2 = 1,
+ zeta_inst.trust3 = 1,
+ zeta_inst.trust4 = 1,
+ mu_inst.trust1 = 0,
+ mu_inst.trust2 = 0,
+ mu_inst.trust3 = 0,
+ mu_inst.trust4 = 0,
+ sigma_inst.trust1 = 1,
+ sigma_inst.trust2 = 1,
+ sigma_inst.trust3 = 1,
+ sigma_inst.trust4 = 1)
>
> apollo_fixed = c("b_Conventional", "b_Offline")
>
>
> apollo_draws = list(
+ interDrawsType="halton",
+ interNDraws=100,
+ interUnifDraws=c(),
+ interNormDraws=c("eta"),
+
+ intraDrawsType='',
+ intraNDraws=0,
+ intraUnifDraws=c(),
+ intraNormDraws=c()
+ )
>
> apollo_randCoeff=function(apollo_beta, apollo_inputs){
+ randcoeff = list()
+
+ randcoeff[["LV"]] = eta
+
+ return(randcoeff)
+ }
>
>
> apollo_inputs = apollo_validateInputs()
Several observations per individual detected based on the value of id.respondent. Setting panelData in apollo_control set to TRUE.
All checks on apollo_control completed.
All checks on database completed.
Generating inter-individual draws . Done
>
>
> 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()
+
+ normalDensity_settings1 = list(outcomeNormal=x1,
+ xNormal=zeta_inst.trust1*LV,
+ mu=mu_inst.trust1,
+ sigma=sigma_inst.trust1,
+ rows=(ch.set==1))
+ normalDensity_settings2 = list(outcomeNormal=x2,
+ xNormal=zeta_inst.trust2*LV,
+ mu=mu_inst.trust2,
+ sigma=sigma_inst.trust2,
+ rows=(ch.set==1))
+ normalDensity_settings3 = list(outcomeNormal=x3,
+ xNormal=zeta_inst.trust3*LV,
+ mu=mu_inst.trust3,
+ sigma=sigma_inst.trust3,
+ rows=(ch.set==1))
+ normalDensity_settings4 = list(outcomeNormal=x4,
+ xNormal=zeta_inst.trust4*LV,
+ mu=mu_inst.trust4,
+ sigma=sigma_inst.trust4,
+ rows=(ch.set==1))
+ P[["indic_inst.trust1"]] = apollo_normalDensity(normalDensity_settings1, functionality)
+ P[["indic_inst.trust2"]] = apollo_normalDensity(normalDensity_settings2, functionality)
+ P[["indic_inst.trust3"]] = apollo_normalDensity(normalDensity_settings3, functionality)
+ P[["indic_inst.trust4"]] = apollo_normalDensity(normalDensity_settings4, functionality)
+
+ V = list()
+ V[['alt1']] = asc + b_Conventional*Conventional.1 + b_Conversion*Conversion.1 + b_Organic*Organic.1 +
+ + b_Offline*Offline.1 + b_Web*Web.1 + b_FB*FB.1
+ + b_Prices_abs*Prices_abs.1
+ + Organic.1*lambda*LV;
+ V[['alt2']] = asc + b_Conventional*Conventional.2 + b_Conversion*Conversion.2 + b_Organic*Organic.2 +
+ + b_Offline*Offline.2 + b_Web*Web.2 + b_FB*FB.2
+ + b_Prices_abs*Prices_abs.2
+ + Organic.2*lambda*LV;
+ V[['alt3']] = 0;
+
+
+ mnl_settings = list(
+ alternatives = c(alt1=1, alt2=2, alt3=3),
+ avail = list(alt1=1, alt2=1, alt3=1),
+ choiceVar = choice,
+ V = V
+ )
+
+ P[["choice"]] = apollo_mnl(mnl_settings, functionality)
+
+ P = apollo_combineModels(P, apollo_inputs, functionality)
+
+ P = apollo_panelProd(P, apollo_inputs, functionality)
+
+ P = apollo_avgInterDraws(P, apollo_inputs, functionality)
+
+ P = apollo_prepareProb(P, apollo_inputs, functionality)
+ return(P)
+ }
>
> model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)

Testing likelihood function...
Apollo found a model component of type NormD without a componentName. The name was set to "indic_inst.trust1" by default.

Summary statistics for NORMD model component indic_inst.trust1:
Min. 1st Qu. Median Mean 3rd Qu. Max.
2 4 5 5.15 6 7
Apollo found a model component of type NormD without a componentName. The name was set to "indic_inst.trust2" by default.

Summary statistics for NORMD model component indic_inst.trust2:
Min. 1st Qu. Median Mean 3rd Qu. Max.
1 3 5 4.8714 6 7
Apollo found a model component of type NormD without a componentName. The name was set to "indic_inst.trust3" by default.

Summary statistics for NORMD model component indic_inst.trust3:
Min. 1st Qu. Median Mean 3rd Qu. Max.
1 4 5 4.9714 6 7
Apollo found a model component of type NormD without a componentName. The name was set to "indic_inst.trust4" by default.

Summary statistics for NORMD model component indic_inst.trust4:
Min. 1st Qu. Median Mean 3rd Qu. Max.
1 4 5 4.8571 6 7
Apollo found a model component of type MNL without a componentName. The name was set to "choice" by default.

Overview of choices for MNL model component choice:
alt1 alt2 alt3
Times available 2100.0 2100.00 2100.00
Times chosen 821.0 837.00 442.00
Percentage chosen overall 39.1 39.86 21.05
Percentage chosen when available 39.1 39.86 21.05

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

Testing influence of parameters.....Error in apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, :
Parameter b_Prices_abs does not influence the log-likelihood of your model!
>
> apollo_modelOutput(model)
Error in apollo_modelOutput(model) : object 'model' not found
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: "Paramter does not influence the log-likelihood of your model" after included LV

Post by stephanehess »

Boris

would you be able to share your code and data with us via e-mail, so we can fix this for you?

Thanks

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: "Paramter does not influence the log-likelihood of your model" after included LV

Post by stephanehess »

Boris

this is all to do with the way you have written your utility functions.

You had:

Code: Select all

  V[['alt1']] = asc + b_Conventional*Conventional.1 + b_Conventional*Conventional.1 + b_Organic*Organic.1 
                    + b_Offline*Offline.1 + b_Web*Web.1 + b_FB*FB.1
                    + b_Prices_abs*Prices_abs.1
                    + Organic.1*lambda*LV;
R will then only use the first line. If you want to write your utiilties across multiple lines, you either need to put the + at the end of the line, or use brackets, as in this example:

Code: Select all

V[['alt1']] = (asc + b_Conventional*Conventional.1 + b_Conventional*Conventional.1 + b_Organic*Organic.1 
                    + b_Offline*Offline.1 + b_Web*Web.1 + b_FB*FB.1
                    + b_Prices_abs*Prices_abs.1
                    + Organic.1*lambda*LV)
And no ;

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Boris
Posts: 4
Joined: 10 Dec 2021, 14:37

Re: "Paramter does not influence the log-likelihood of your model" after included LV

Post by Boris »

A great start for the year, problem solved!
Thanks a lot.
DavideContu
Posts: 3
Joined: 02 Aug 2020, 19:14

Re: "Paramter does not influence the log-likelihood of your model" after included LV

Post by DavideContu »

Hi-I am getting a similar error with the code below, however I do not see where the mistake is (even after consulting this thread).

Thanks a lot for your help!

Code: Select all

# ################################################################# #
#### 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  = "Ireland_HLCM",
  modelDescr = "Firt HlCM test Ireland",
  indivID    = "ID",
  mixing     = TRUE,
  nCores     = 2
)

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

database = read.csv("ireland_VBN.csv",header=TRUE)


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

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(
    bt1_a           = 1.927,
    bt1_b           = 0.369,
    bt1_c           = -0.677,
    
    bt2_a           = 2.02,
    bt2_b           = 0.687,
    bt2_c           = 0.256,
    
    bt3_a           = 1.99,
    bt3_b           = 1.67,
    bt3_c           = 0.814,
    
    bsave_a         = 0.783,
    bsave_b         = 0.750,
    bsave_c         = 3.3,
    
    bind_a          =0.21,
    bind_b          =-0.01,
    bind_c          =0.264,
    
    bpay_a          =-0.02,
    bpay_b          =-0.140,
    bpay_c          =-0.206,
    
    bcost_a         =-0.201,
    bcost_b        =-0.363,
    bcost_c        =-0.123,
    
    bemi_a         =0.709,
    bemi_b        =-0.06,
    bemi_c        =2.33,
    
    delta_a         = 0,
    delta_b         = -1.29,
    delta_c         = -0.62,
    pi_LV1_a=0,
    pi_LV1_b=-0.3,
    pi_LV1_c=-0.2,
    zeta_Cons01=-4,
    zeta_Cons02=-3,
    zeta_Cons03=-2,
    zeta_Cons04=-1,
    zeta_Cons05=-1,
    zeta_Cons06=-1,
    zeta_Cons07=-1.8,
    zeta_Cons08=-1,
    zeta_Cons09=-1,
    zeta_Cons10=-1,
    zeta_Cons11=-2,
    zeta_Cons12=-1,
    zeta_Cons13=-1,
    zeta_Cons14=-3,
    zeta_Cons15=-1,
    zeta_Cons16=-1,
    
    
    tau_Cons01_1=-2.5,
    tau_Cons01_2=-1.3,
    tau_Cons01_3=0.25,
    tau_Cons01_4=1.6,
    
    tau_Cons02_1=-3.2,
    tau_Cons02_2=-1.8,
    tau_Cons02_3=0.11,
    tau_Cons02_4=1.58,
    
    tau_Cons03_1=-2.9,
    tau_Cons03_2=-1.65,
    tau_Cons03_3=0.11,
    tau_Cons03_4=1.67,
    
    tau_Cons04_1=-2.38,
    tau_Cons04_2=-1.14,
    tau_Cons04_3=0.42,
    tau_Cons04_4=1.85,
    
    tau_Cons05_1=-2.38,
    tau_Cons05_2=-1.14,
    tau_Cons05_3=0.42,
    tau_Cons05_4=3,
    
    tau_Cons06_1=-2.38,
    tau_Cons06_2=-1.14,
    tau_Cons06_3=0.42,
    tau_Cons06_4=1.85,
    
    tau_Cons07_1=-2.38,
    tau_Cons07_2=-1.14,
    tau_Cons07_3=0.42,
    tau_Cons07_4=1.85,
    
    tau_Cons08_1=-2.38,
    tau_Cons08_2=-1.14,
    tau_Cons08_3=0.42,
    tau_Cons08_4=1.85,
    
    
    tau_Cons09_1=-2.38,
    tau_Cons09_2=-1.14,
    tau_Cons09_3=0.42,
    tau_Cons09_4=1.85,
    
    
    tau_Cons10_1=-2.38,
    tau_Cons10_2=-1.14,
    tau_Cons10_3=0.42,
    tau_Cons10_4=1.85,
    
    tau_Cons11_1=-2.38,
    tau_Cons11_2=-1.14,
    tau_Cons11_3=0.42,
    tau_Cons11_4=1.85,
    
    tau_Cons12_1=-2.38,
    tau_Cons12_2=-1.14,
    tau_Cons12_3=0.42,
    tau_Cons12_4=1.85,
    
    tau_Cons13_1=-2.38,
    tau_Cons13_2=-1.14,
    tau_Cons13_3=0.42,
    tau_Cons13_4=1.85,
    
    tau_Cons14_1=-2.38,
    tau_Cons14_2=-1.14,
    tau_Cons14_3=0.42,
    tau_Cons14_4=1.85,
    
    tau_Cons15_1=-2.38,
    tau_Cons15_2=-1.14,
    tau_Cons15_3=0.42,
    tau_Cons15_4=1.85,
    
    tau_Cons16_1=-2.38,
    tau_Cons16_2=-1.14,
    tau_Cons16_3=0.42,
    tau_Cons16_4=1.85,
    
    
    
    gamma_pb=1,
    
    
    gamma_envb=0.5,
    
    
    gamma_feas=0.7,
    
    
    gamma_trial=0.8,
    
    
    gamma_health=0.9

  
)


### 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("delta_a", "pi_LV1_a")



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

### Set parameters for generating draws
apollo_draws = list(
  interDrawsType="mlhs", 
  interNDraws=100,          
  interUnifDraws=c(),      
  interNormDraws=c("eta_LV1","eta_LV2","eta_LV3","eta_LV4", "eta_LV5", "eta_LV6")
)

### Create random parameters
apollo_randCoeff=function(apollo_beta, apollo_inputs){
  randcoeff = list()
  
  randcoeff[["LV6"]] = eta_LV6
  randcoeff[["LV5"]] = eta_LV5
  randcoeff[["LV4"]] = eta_LV4
  randcoeff[["LV3"]] = eta_LV3
  randcoeff[["LV2"]] = eta_LV2
  randcoeff[["LV1"]] = eta_LV1+gamma_pb*eta_LV2+gamma_envb*eta_LV3+gamma_feas*eta_LV4+gamma_trial*eta_LV5+gamma_health*eta_LV6
  
  
  
  return(randcoeff)
}

# ################################################################# #
#### DEFINE LATENT CLASS COMPONENTS                              ####
# ################################################################# #

apollo_lcPars=function(apollo_beta, apollo_inputs){
  lcpars = list()
  ### Define lists of parameters for each class
  ###                      classA   classB  ClassC
  
  lcpars[["bt1"]] = list(bt1_a, bt1_b,bt1_c)
  lcpars[["bt2"]] = list(bt2_a, bt2_b,bt2_c)
  lcpars[["bt3"]] = list(bt3_a, bt3_b,bt3_c)
  lcpars[["bsave"]] = list(bsave_a, bsave_b, bsave_c)
  lcpars[["bpay"]] = list(bpay_a, bpay_b, bpay_c)
  lcpars[["bind"]] = list(bind_a, bind_b, bind_c)
  lcpars[["bemi"]] = list(bemi_a, bemi_b, bemi_c)
  lcpars[["bcost"]] = list(bcost_a, bcost_b, bcost_c)
  
  ### Class allocation probabilities
  ### These are the probabilities of a binary logit model
  ### apollo_mnl could be used too (with functionality="raw" 
  ### and choice=NA), but explicitly writing the probability 
  ### is easier.
  
  
  
  V=list()
  V[["class_a"]] = delta_a+pi_LV1_a*LV1 
  V[["class_b"]] = delta_b+pi_LV1_b*LV1
  V[["class_c"]] = delta_c+pi_LV1_c*LV1
  
  classAlloc_settings = list(
    alternatives = c(class_a=1, class_b=2, class_c=3), 
    avail        = 1, 
    choiceVar    = NA, 
     utilities           = V
  )
  lcpars[["pi_values"]] = apollo_classAlloc(classAlloc_settings)
  
  #lcpars[["pi_values"]] = apollo_firstRow(lcpars[["pi_values"]], 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
  P = list()
  
  ### Likelihood of INDICATORS
  ol_settings1 = list(outcomeOrdered=M1_IntendToUse_NearFuture, 
                      V=zeta_Cons01*LV1, 
                      tau=c(tau_Cons01_1, tau_Cons01_2, tau_Cons01_3, tau_Cons01_4),rows=(task==1),
                      componentName  = "indic_future")
  
  
  ol_settings2 = list(outcomeOrdered=M2_RecommendUse, 
                      V=zeta_Cons02*LV1, 
                      tau=c(tau_Cons02_1, tau_Cons02_2, tau_Cons02_3, tau_Cons02_4),rows=(task==1),
                      componentName  = "indic_recommend")
  
  
  ol_settings3 = list(outcomeOrdered=M3_ReadilyAvailableTechn, 
                      V=zeta_Cons03*LV1, 
                      tau=c(tau_Cons03_1, tau_Cons03_2, tau_Cons03_3, tau_Cons03_4),rows=(task==1),
                      componentName  = "indic_available")
  
  
  ol_settings4 = list(outcomeOrdered=M4_WTSpendMoney, 
                      V=zeta_Cons04*LV1, 
                      tau=c(tau_Cons04_1, tau_Cons04_2, tau_Cons04_3, tau_Cons04_4),rows=(task==1),
                      componentName  = "indic_wtp")
  
  
  
   ol_settings5 = list(outcomeOrdered=J1_Savings, 
                      V=zeta_Cons05*LV2, 
                      tau=c(tau_Cons05_1, tau_Cons05_2, tau_Cons05_3, tau_Cons05_4),rows=(task==1),
                     componentName  = "indic_savings")
  
  ol_settings6 = list(outcomeOrdered=J2_PropertyValue, 
                      V=zeta_Cons06*LV2, 
                      tau=c(tau_Cons06_1, tau_Cons06_2, tau_Cons06_3, tau_Cons06_4),rows=(task==1),
                      componentName  = "indic_prop")
  
  ol_settings7 = list(outcomeOrdered=J3_Environment, 
                      V=zeta_Cons07*LV3, 
                      tau=c(tau_Cons07_1, tau_Cons07_2, tau_Cons07_3, tau_Cons07_4),rows=(task==1),
                      componentName  = "indic_env")
  
  ol_settings8 = list(outcomeOrdered=C3_FossilFuels, 
                      V=zeta_Cons08*LV3, 
                      tau=c(tau_Cons08_1, tau_Cons08_2, tau_Cons08_3, tau_Cons08_4),rows=(task==1),
                      componentName  = "indic_ff")
  
  
  ol_settings9 = list(outcomeOrdered=K1_PV_Feasib, 
                      V=zeta_Cons09*LV4, 
                      tau=c(tau_Cons09_1, tau_Cons09_2, tau_Cons09_3, tau_Cons09_4),rows=(task==1),
                      componentName  = "indic_pv")
  
  
  ol_settings10 = list(outcomeOrdered=K2_GSHP_Feasib, 
                       V=zeta_Cons10*LV4, 
                       tau=c(tau_Cons10_1, tau_Cons10_2, tau_Cons10_3, tau_Cons10_4),rows=(task==1),
                       componentName  = "indic_gshp")
  
  
  ol_settings11 = list(outcomeOrdered=K3_TES_Feasib, 
                       V=zeta_Cons11*LV4, 
                       tau=c(tau_Cons11_1, tau_Cons11_2, tau_Cons11_3, tau_Cons11_4),rows=(task==1),
                       componentName  = "indic_tes")
  
  
  ol_settings12 = list(outcomeOrdered=L1_SeeIt, 
                       V=zeta_Cons12*LV5, 
                       tau=c(tau_Cons12_1, tau_Cons12_2, tau_Cons12_3, tau_Cons12_4),rows=(task==1),
                       componentName  = "indic_see")
  
  ol_settings13 = list(outcomeOrdered=L2_TalkToSomeone, 
                       V=zeta_Cons13*LV5, 
                       tau=c(tau_Cons13_1, tau_Cons13_2, tau_Cons13_3, tau_Cons13_4),rows=(task==1),
                       componentName  = "indic_talk")
  
  ol_settings14 = list(outcomeOrdered=L3_TryIt, 
                       V=zeta_Cons14*LV5, 
                       tau=c(tau_Cons14_1, tau_Cons14_2, tau_Cons14_3, tau_Cons14_4),rows=(task==1),
                       componentName  = "indic_try")
  
  
  ol_settings15 = list(outcomeOrdered=F1_IndoorEnvironment, 
                       V=zeta_Cons15*LV6, 
                       tau=c(tau_Cons15_1, tau_Cons15_2, tau_Cons15_3, tau_Cons15_4),rows=(task==1),
                       componentName  = "indic_ind")
  
  ol_settings16 = list(outcomeOrdered=F2_Cons_HS, 
                       V=zeta_Cons16*LV6, 
                       tau=c(tau_Cons16_1, tau_Cons16_2, tau_Cons16_3, tau_Cons16_4),rows=(task==1),
                       componentName  = "indic_cons")
  
  
  ### Keep only the first row, as it is the only one that matters
  P[["indic_future"]] = apollo_firstRow(apollo_ol(ol_settings1, functionality), apollo_inputs )
  P[["indic_recommend"]] = apollo_firstRow(apollo_ol(ol_settings2, functionality), apollo_inputs )
  P[["indic_available"]] = apollo_firstRow(apollo_ol(ol_settings3, functionality), apollo_inputs )
  P[["indic_wtp"]] = apollo_firstRow(apollo_ol(ol_settings4, functionality), apollo_inputs )
  
  P[["indic_savings"]] = apollo_firstRow(apollo_ol(ol_settings5, functionality), apollo_inputs )
  P[["indic_prop"]] = apollo_firstRow(apollo_ol(ol_settings6, functionality), apollo_inputs )
  
  P[["indic_savings"]] = apollo_firstRow(apollo_ol(ol_settings7, functionality), apollo_inputs )
  P[["indic_prop"]] = apollo_firstRow(apollo_ol(ol_settings8, functionality), apollo_inputs )
  
  P[["indic_pv"]] = apollo_firstRow(apollo_ol(ol_settings9, functionality), apollo_inputs )
  P[["indic_gshp"]] = apollo_firstRow(apollo_ol(ol_settings10, functionality), apollo_inputs )
  P[["indic_tes"]] = apollo_firstRow(apollo_ol(ol_settings11, functionality), apollo_inputs )
  
  
  P[["indic_see"]] = apollo_firstRow(apollo_ol(ol_settings12, functionality), apollo_inputs )
  P[["indic_talk"]] = apollo_firstRow(apollo_ol(ol_settings13, functionality), apollo_inputs )
  P[["indic_try"]] = apollo_firstRow(apollo_ol(ol_settings14, functionality), apollo_inputs )
  
  P[["indic_ind"]] = apollo_firstRow(apollo_ol(ol_settings15, functionality), apollo_inputs )
  P[["indic_cons"]] = apollo_firstRow(apollo_ol(ol_settings16, functionality), apollo_inputs )
  
  
  ### Likelihood of CHOICES
  S <- 3
  for(s in 1:S){
    V = list()
    ### Class-specific utilities
    V[['altA']]  = bt1[[s]]*tech1_a+bt2[[s]]*tech2_a+bt3[[s]]*tech3_a+bcost[[s]]*cost_a+bsave[[s]]*savings_a+bemi[[s]]*emission_a+bpay[[s]]*payback_a+bind[[s]]*indoor_a
    V[['altB']]  = bt1[[s]]*tech1_b+bt2[[s]]*tech2_b+bt3[[s]]*tech3_b+bcost[[s]]*cost_b+bsave[[s]]*savings_b+bemi[[s]]*emission_b+bpay[[s]]*payback_b+bind[[s]]*indoor_b
    V[['altC']]  = 0
  ### Define settings for MNL model component that are generic across classes
  mnl_settings = list(
    alternatives = c(altA=1, altB=2, altC=3),
    choiceVar    = choice,
    utilities    = V
  )

  
  ### Compute within-class choice probabilities using MNL model
  P[[paste0("Class_",s)]] = apollo_mnl(mnl_settings, functionality)
  
  ### Take product across observation for same individual
  P[[paste0("Class_",s)]] = apollo_panelProd(P[[paste0("Class_",s)]], apollo_inputs ,functionality)
  }
  
  ### Compute latent class model probabilities
  lc_settings  = list(inClassProb = P[paste0("Class_", 1:S)], classProb=pi_values)
  P[["choice"]] = apollo_lc(lc_settings, apollo_inputs, functionality)
  
  

  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                                            ####
# ################################################################# #

apollo_llCalc(apollo_beta, apollo_probabilities, apollo_inputs)

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

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

# ################################################################# #
#### MODEL OUTPUTS                                               ####
# ################################################################# #

# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN)                               ----
# ----------------------------------------------------------------- #

apollo_modelOutput(model)

# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO FILE, using model name)               ----
# ----------------------------------------------------------------- #

apollo_saveOutput(model)

The output is as follows:

Calculating LL of each model component...Done.
$model
[1] -90178.2

$indic_future
[1] -2413.189

$indic_recommend
[1] -2079.934

$indic_available
[1] -1921.038

$indic_wtp
[1] -1940.897

$indic_savings
[1] -1974.237

$indic_prop
[1] -2039.837

$indic_pv
[1] -1972.208

$indic_gshp
[1] -1979.354

$indic_tes
[1] -2040.902

$indic_see
[1] -2014.449

$indic_talk
[1] -2026.414

$indic_try
[1] -2060.828

$indic_ind
[1] -1921.295

$indic_cons
[1] -1955.527

$Class_1
[1] -14942.26

$Class_2
[1] -22427.91

$Class_3
[1] -16867.93

$choice
[1] -9901.841

>
> # ################################################################# #
> #### MODEL ESTIMATION ####
> # ################################################################# #
>
> model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
Preparing user-defined functions.

Testing likelihood function...
Apollo found a model component of type classAlloc without a componentName. The name was set to "classAlloc" by default.
No coding provided for Ordered model component "indic_future", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for OL model component indic_future:
1 2 3 4 5
Times chosen 75.00 161.00 468.00 378.0 217.00
Percentage chosen overall 5.77 12.39 36.03 29.1 16.71
No coding provided for Ordered model component "indic_recommend", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for OL model component indic_recommend:
1 2 3 4 5
Times chosen 37.00 125.00 473.00 391.0 273.00
Percentage chosen overall 2.85 9.62 36.41 30.1 21.02
No coding provided for Ordered model component "indic_available", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for OL model component indic_available:
1 2 3 4 5
Times chosen 35.00 85.00 400.00 464.00 315.00
Percentage chosen overall 2.69 6.54 30.79 35.72 24.25
No coding provided for Ordered model component "indic_wtp", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for OL model component indic_wtp:
1 2 3 4 5
Times chosen 78 156.00 435.00 390.00 240.00
Percentage chosen overall 6 12.01 33.49 30.02 18.48
No coding provided for Ordered model component "indic_savings", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for OL model component indic_savings:
1 2 3 4 5
Times chosen 17.00 78 286.00 487.00 431.00
Percentage chosen overall 1.31 6 22.02 37.49 33.18
No coding provided for Ordered model component "indic_prop", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for OL model component indic_prop:
1 2 3 4 5
Times chosen 14.00 38.00 250.00 489.00 508.00
Percentage chosen overall 1.08 2.93 19.25 37.64 39.11
No coding provided for Ordered model component "indic_env", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for OL model component indic_env:
1 2 3 4 5
Times chosen 9.00 33.00 218.00 485.00 554.00
Percentage chosen overall 0.69 2.54 16.78 37.34 42.65
No coding provided for Ordered model component "indic_ff", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for OL model component indic_ff:
1 2 3 4 5
Times chosen 28.00 56.00 198.00 421.00 596.00
Percentage chosen overall 2.16 4.31 15.24 32.41 45.88
No coding provided for Ordered model component "indic_pv", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for OL model component indic_pv:
1 2 3 4 5
Times chosen 73.00 121.00 347.00 434.00 324.00
Percentage chosen overall 5.62 9.31 26.71 33.41 24.94
No coding provided for Ordered model component "indic_gshp", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for OL model component indic_gshp:
1 2 3 4 5
Times chosen 103.00 183.00 406.00 358.00 249.00
Percentage chosen overall 7.93 14.09 31.25 27.56 19.17
No coding provided for Ordered model component "indic_tes", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for OL model component indic_tes:
1 2 3 4 5
Times chosen 76.00 142.00 410.00 404.0 267.00
Percentage chosen overall 5.85 10.93 31.56 31.1 20.55
No coding provided for Ordered model component "indic_see", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for OL model component indic_see:
1 2 3 4 5
Times chosen 18.00 36.00 217.00 449.00 579.00
Percentage chosen overall 1.39 2.77 16.71 34.57 44.57
No coding provided for Ordered model component "indic_talk", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for OL model component indic_talk:
1 2 3 4 5
Times chosen 19.00 40.00 209.00 428.00 603.00
Percentage chosen overall 1.46 3.08 16.09 32.95 46.42
No coding provided for Ordered model component "indic_try", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for OL model component indic_try:
1 2 3 4 5
Times chosen 19.00 60.00 262.00 448.00 510.00
Percentage chosen overall 1.46 4.62 20.17 34.49 39.26
No coding provided for Ordered model component "indic_ind", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for OL model component indic_ind:
1 2 3 4 5
Times chosen 25.00 98.00 371.00 485.00 320.00
Percentage chosen overall 1.92 7.54 28.56 37.34 24.63
No coding provided for Ordered model component "indic_cons", so assuming outcomeOrdered goes from 1 to 5

Overview of choices for OL model component indic_cons:
1 2 3 4 5
Times chosen 71.00 186.00 434.00 343.0 265.0
Percentage chosen overall 5.47 14.32 33.41 26.4 20.4
Apollo found a model component of type MNL without a componentName. The name was set to "Class_1" by default.
Setting "avail" is missing, so full availability is assumed.

Overview of choices for MNL model component Class_1:
altA altB altC
Times available 11691.00 11691.00 11691.00
Times chosen 4276.00 4164.00 3251.00
Percentage chosen overall 36.58 35.62 27.81
Percentage chosen when available 36.58 35.62 27.81
Apollo found a model component of type MNL without a componentName. The name was set to "Class_2" by default.
Setting "avail" is missing, so full availability is assumed.

Overview of choices for MNL model component Class_2:
altA altB altC
Times available 11691.00 11691.00 11691.00
Times chosen 4276.00 4164.00 3251.00
Percentage chosen overall 36.58 35.62 27.81
Percentage chosen when available 36.58 35.62 27.81
Apollo found a model component of type MNL without a componentName. The name was set to "Class_3" by default.
Setting "avail" is missing, so full availability is assumed.

Overview of choices for MNL model component Class_3:
altA altB altC
Times available 11691.00 11691.00 11691.00
Times chosen 4276.00 4164.00 3251.00
Percentage chosen overall 36.58 35.62 27.81
Percentage chosen when available 36.58 35.62 27.81
Apollo found a model component of type LC without a componentName. The name was set to "choice" by default.

Summary of class allocation for LC model component choice:
Mean prob.
Class_1 0.5506
Class_2 0.1535
Class_3 0.2958
Class probability for model component "choice" averaged across observations of each individual.

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

Testing influence of parameters................................Error in apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, :
Parameter zeta_Cons05 does not influence the log-likelihood of your model!
dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: "Paramter does not influence the log-likelihood of your model" after included LV

Post by dpalma »

Hi,

The problem is that in your code you are overwriting some components of your utility, see lines 388-392 of your code below:

Code: Select all

P[["indic_savings"]] = apollo_firstRow(apollo_ol(ol_settings5, functionality), apollo_inputs )
P[["indic_prop"]] = apollo_firstRow(apollo_ol(ol_settings6, functionality), apollo_inputs )
  
P[["indic_savings"]] = apollo_firstRow(apollo_ol(ol_settings7, functionality), apollo_inputs )
P[["indic_prop"]] = apollo_firstRow(apollo_ol(ol_settings8, functionality), apollo_inputs )
As you can see P[["indic_savings"]] and P[["indic_prop"]] are overwritten, so ol_settings5 and ol_settings6 do not play any role in your likelihood. You should instead change those lines to:

Code: Select all

P[["indic_savings"]] = apollo_firstRow(apollo_ol(ol_settings5, functionality), apollo_inputs )
P[["indic_prop"]] = apollo_firstRow(apollo_ol(ol_settings6, functionality), apollo_inputs )
  
P[["indic_environment"]] = apollo_firstRow(apollo_ol(ol_settings7, functionality), apollo_inputs )
P[["indic_fossiFuels"]] = apollo_firstRow(apollo_ol(ol_settings8, functionality), apollo_inputs )
Also, you seem to be including P[["Class_1"]] and P[["Class_2"]] in your final utility, when you should exclude them. So I would also change your line 436 from:

Code: Select all

P = apollo_combineModels(P, apollo_inputs, functionality)
to:

Code: Select all

P = apollo_combineModels(P, apollo_inputs, functionality, components=grep("^Class", names(P), value=TRUE, invert=TRUE))
This second line will multiply all elements insie P except those whose name start with "Class".

Best wishes
David
Post Reply