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.

ICLV model specification in unlabelled form

Ask questions about model specifications. Ideally include a mathematical explanation of your proposed model.
Post Reply
Peter_C
Posts: 17
Joined: 03 May 2020, 13:52

ICLV model specification in unlabelled form

Post by Peter_C »

Dear Stephane and David,

I would like to ask that, is the following ICLV model (with random parameters) specification correct?

(I have three alternatives (in unlabelled form), 4 attributes (price (4 level), investment cost (4 level), level of environmental friendliness (4 level), comfort (2 level), and I have results from 12 statements (1-5 agreement scale) relate to environmental friendliness)

rm(list = ls())
library(apollo)
apollo_initialise()
apollo_control = list(
modelName = "ICLV",
modelDescr = "ICLV model with random parameters",
indivID = "ID",
mixing = TRUE,
nCores = 1
)

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

apollo_beta = c(asc_alt1 = 0,
asc_alt2 = 0,
asc_alt3 = 0,
mu_log_b_price = 0,
sigma_log_b_price = 0,
mu_log_b_cost = 0,
sigma_log_b_cost = 0,
b_envflow = 0,
mu_b_envfmedium = 0,
sigma_b_envfmedium = 0,
mu_b_envfhigh = 0,
sigma_b_envfhigh = 0,
mu_b_envfveryhigh = 0,
sigma_b_envfveryhigh = 0,
b_automatic = 0,
mu_b_manual = 0,
sigma_b_manual = 0,
b_envfmedium_shift_lambda = 0,
b_envfhigh_shift_lambda = 0,
b_envfveryhigh_shift_lambda = 0,
gamma_edu2 = 0,
gamma_edu3 = 0,
gamma_edu4 = 0,
gamma_residence2 = 0,
gamma_residence3 = 0,
gamma_residence4 = 0,
gamma_income2 = 0,
gamma_income3 = 0,
zeta_q1 = 1,
zeta_q2 = 1,
zeta_q3 = 1,
zeta_q4 = 1,
zeta_q5 = 1,
zeta_q6 = 1,
zeta_q7 = 1,
zeta_q8 = 1,
zeta_q9 = 1,
zeta_q10 = 1,
zeta_q11 = 1,
zeta_q12 = 1,
tau_q1_1 =-2,
tau_q1_2 =-1,
tau_q1_3 = 1,
tau_q1_4 = 2,
tau_q2_1 =-2,
tau_q2_2 =-1,
tau_q2_3 = 1,
tau_q2_4 = 2,
tau_q3_1 =-2,
tau_q3_2 =-1,
tau_q3_3 = 1,
tau_q3_4 = 2,
tau_q4_1 =-2,
tau_q4_2 =-1,
tau_q4_3 = 1,
tau_q4_4 = 2,
tau_q5_1 =-2,
tau_q5_2 =-1,
tau_q5_3 = 1,
tau_q5_4 = 2,
tau_q6_1 =-2,
tau_q6_2 =-1,
tau_q6_3 = 1,
tau_q6_4 = 2,
tau_q7_1 =-2,
tau_q7_2 =-1,
tau_q7_3 = 1,
tau_q7_4 = 2,
tau_q8_1 =-2,
tau_q8_2 =-1,
tau_q8_3 = 1,
tau_q8_4 = 2,
tau_q9_1 =-2,
tau_q9_2 =-1,
tau_q9_3 = 1,
tau_q9_4 = 2,
tau_q10_1 =-2,
tau_q10_2 =-1,
tau_q10_3 = 1,
tau_q10_4 = 2,
tau_q11_1 =-2,
tau_q11_2 =-1,
tau_q11_3 = 1,
tau_q11_4 = 2,
tau_q12_1 =-2,
tau_q12_2 =-1,
tau_q12_3 = 1,
tau_q12_4 = 2)

apollo_fixed = c("asc_alt1", "b_envflow", "b_automatic")

apollo_beta = apollo_readBeta(apollo_beta, apollo_fixed, "MLM model", overwriteFixed=FALSE)

apollo_draws = list(
interDrawsType="halton",
interNDraws=500,
interUnifDraws=c(),
interNormDraws=c("eta","draws_price","draws_cost","draws_envfmedium","draws_envfhigh","draws_envfveryhigh","draws_manual"),

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

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

randcoeff[["LV"]] = gamma_edu2*edu2 + gamma_edu3*edu3 + gamma_edu4*edu4 + gamma_residence2*residence2 + gamma_residence3*residence3 + gamma_residence4*residence4 + gamma_income2*income2 + gamma_income3*income3 + eta
randcoeff[["b_price"]] = -exp( mu_log_b_price + sigma_log_b_price * draws_price )
randcoeff[["b_cost"]] = -exp( mu_log_b_cost + sigma_log_b_cost * draws_cost )
randcoeff[["b_envfmedium"]] = ( mu_b_envfmedium + sigma_b_envfmedium * draws_envfmedium )
randcoeff[["b_envfhigh"]] = ( mu_b_envfhigh + sigma_b_envfhigh * draws_envfhigh )
randcoeff[["b_envfveryhigh"]] = ( mu_b_envfveryhigh + sigma_b_envfveryhigh * draws_envfveryhigh )
randcoeff[["b_manual"]] = ( mu_b_manual + sigma_b_manual * draws_manual )

return(randcoeff)
}


apollo_inputs = apollo_validateInputs()

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()


### Create coefficients using interactions with socio-demographics
b_envfmedium_value = b_envfmedium + b_envfmedium_shift_lambda * LV
b_envfhigh_value = b_envfhigh + b_envfhigh_shift_lambda * LV
b_envfveryhigh_value = b_envfveryhigh + b_envfveryhigh_shift_lambda * LV

### Likelihood of indicators
ol_settings1 = list(outcomeOrdered = q1,
V = zeta_q1*LV,
tau = c(tau_q1_1, tau_q1_2, tau_q1_3, tau_q1_4),
rows = (helyzet==1),
componentName = "indic_q1")
ol_settings2 = list(outcomeOrdered = q2,
V = zeta_q2*LV,
tau = c(tau_q2_1, tau_q2_2, tau_q2_3, tau_q2_4),
rows = (helyzet==1),
componentName = "indic_q2")
ol_settings3 = list(outcomeOrdered = q3,
V = zeta_q3*LV,
tau = c(tau_q3_1, tau_q3_2, tau_q3_3, tau_q3_4),
rows = (helyzet==1),
componentName = "indic_q3")
ol_settings4 = list(outcomeOrdered = q4,
V = zeta_q4*LV,
tau = c(tau_q4_1, tau_q4_2, tau_q4_3, tau_q4_4),
rows = (helyzet==1),
componentName = "indic_q4")
ol_settings5 = list(outcomeOrdered = q5,
V = zeta_q5*LV,
tau = c(tau_q5_1, tau_q5_2, tau_q5_3, tau_q5_4),
rows = (helyzet==1),
componentName = "indic_q5")
ol_settings6 = list(outcomeOrdered = q6,
V = zeta_q6*LV,
tau = c(tau_q6_1, tau_q6_2, tau_q6_3, tau_q6_4),
rows = (helyzet==1),
componentName = "indic_q6")
ol_settings7 = list(outcomeOrdered = q7,
V = zeta_q7*LV,
tau = c(tau_q7_1, tau_q7_2, tau_q7_3, tau_q7_4),
rows = (helyzet==1),
componentName = "indic_q7")
ol_settings8 = list(outcomeOrdered = q8,
V = zeta_q8*LV,
tau = c(tau_q8_1, tau_q8_2, tau_q8_3, tau_q8_4),
rows = (helyzet==1),
componentName = "indic_q8")
ol_settings9 = list(outcomeOrdered = q9,
V = zeta_q9*LV,
tau = c(tau_q9_1, tau_q9_2, tau_q9_3, tau_q9_4),
rows = (helyzet==1),
componentName = "indic_q9")
ol_settings10 = list(outcomeOrdered = q10,
V = zeta_q10*LV,
tau = c(tau_q10_1, tau_q10_2, tau_q10_3, tau_q10_4),
rows = (helyzet==1),
componentName = "indic_q10")
ol_settings11 = list(outcomeOrdered = q11,
V = zeta_q11*LV,
tau = c(tau_q11_1, tau_q11_2, tau_q11_3, tau_q11_4),
rows = (helyzet==1),
componentName = "indic_q11")
ol_settings12 = list(outcomeOrdered = q12,
V = zeta_q12*LV,
tau = c(tau_q12_1, tau_q12_2, tau_q12_3, tau_q12_4),
rows = (helyzet==1),
componentName = "indic_q12")
P[["indic_q1"]] = apollo_ol(ol_settings1, functionality)
P[["indic_q2"]] = apollo_ol(ol_settings2, functionality)
P[["indic_q3"]] = apollo_ol(ol_settings3, functionality)
P[["indic_q4"]] = apollo_ol(ol_settings4, functionality)
P[["indic_q5"]] = apollo_ol(ol_settings5, functionality)
P[["indic_q6"]] = apollo_ol(ol_settings6, functionality)
P[["indic_q7"]] = apollo_ol(ol_settings7, functionality)
P[["indic_q8"]] = apollo_ol(ol_settings8, functionality)
P[["indic_q9"]] = apollo_ol(ol_settings9, functionality)
P[["indic_q10"]] = apollo_ol(ol_settings10, functionality)
P[["indic_q11"]] = apollo_ol(ol_settings11, functionality)
P[["indic_q12"]] = apollo_ol(ol_settings12, functionality)


V = list()
V[['alt1']] = asc_alt1 + b_envflow * ( env_alt1 == 1 ) + b_envfmedium_value * ( env_alt1 == 2 ) + b_envfhigh_value * ( env_alt1 == 3 ) + b_envfveryhigh_value * ( env_alt1 == 4 ) + b_manual * ( comf_alt1 == 0 ) + b_automatic * ( comf_alt1 == 1 ) + b_cost * cost_alt1 + b_price * price_alt1
V[['alt2']] = asc_alt2 + b_envflow * ( env_alt2 == 1 ) + b_envfmedium_value * ( env_alt2 == 2 ) + b_envfhigh_value * ( env_alt2 == 3 ) + b_envfveryhigh_value * ( env_alt2 == 4 ) + b_manual * ( comf_alt2 == 0 ) + b_automatic * ( comf_alt2 == 1 ) + b_cost * cost_alt2 + b_price * price_alt2
V[['alt3']] = asc_alt3 + b_envflow * ( env_alt3 == 1 ) + b_envfmedium_value * ( env_alt3 == 2 ) + b_envfhigh_value * ( env_alt3 == 3 ) + b_envfveryhigh_value * ( env_alt3 == 4 ) + b_manual * ( comf_alt3 == 0 ) + b_automatic * ( comf_alt3 == 1 ) + b_cost * cost_alt3 + b_price * price_alt3

mnl_settings = list(
alternatives = c(alt1=1, alt2=2, alt3=3),
avail = list(alt1=av_alt1, alt2=av_alt2, alt3=av_alt3),
choiceVar = choice,
V = V,
componentName= "choice"
)

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)

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

saveOutput_settings = list()
saveOutput_settings$printPVal=TRUE
apollo_saveOutput(model,modelOutput_settings)



Thank you very much for your answer!

Best regards,
Peter
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: ICLV model specification in unlabelled form

Post by stephanehess »

Peter

from a programming perspective, this is fine, but of course there are many other specifications you could try, e.g. which attributes to interact the LV with, etc.

But one thing that I would really suggest you to address is not to use Halton draws with your specification - you have seven random terms, and Halton draws will become highly collinear

Best wishes

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Peter_C
Posts: 17
Joined: 03 May 2020, 13:52

Re: ICLV model specification in unlabelled form

Post by Peter_C »

Dear Stephane,

Thank you very much for your answer!

Which type of draws you could suggest in this case? Which one is the least sensitive for collinearity?

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

Re: ICLV model specification in unlabelled form

Post by stephanehess »

Peter

you can use MLHS or Sobol in Apollo, or load other types of draws from elsewhere

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Peter_C
Posts: 17
Joined: 03 May 2020, 13:52

Re: ICLV model specification in unlabelled form

Post by Peter_C »

Thank you Stephane!
lukasz
Posts: 0
Joined: 22 Feb 2024, 18:09

Re: ICLV model specification in unlabelled form

Post by lukasz »

Dear Stephane,

I have similar case as Peter had but in my experiment I have 2 alternatives that differ between task and repondents and the third alternative which is always Status quo. I have six attributes - subsidies attribute which is continuous and treated as non-random and five other attributes (plan, organic, rotation, contract, support) with 3 levels in each attribute. SQ alternative consists of the first level of each of the attribute. The first levels of attributes can also appear in different alternatives with the exception of "contract" attribute. Here, the first level means "no contract" and can only be used in SQ. In other alternatives 3 or 5 years contract must be chosen. I also have a latent variable (attitude) which is expressed by 4 indicators (1-7 Likert scale) and some further socio-demographic charasteristic that should influence the latent variable. My idea was that all attribute levels should be treated as random (except for subsidies) and also all these levels should be interacted with the LV. I also included ASC to know whether there is general tendency to move away from status quo but I am not sure if I coded properly (in variable asc_alt1 and asc_alt2 I put only "0" and in asc_alt3 I put "1" in the whole column).

I run a code below - it works but I received warning: Estimation failed. No covariance matrix to compute. I received parameters but no standard errors. Could you give my some hints where could be the problem?

# ################################################################# #
#### 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 = "Hybrid_with_OL_and_MMNL",
modelDescr = "Hybrid choice model on carbon agriculture in Serbia",
indivID = "ID",
nCores = 3,
outputDirectory = "output"
)

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


database = read_excel("C:/Users/KMiGŻ-FSKNMH2/Desktop/SECOFARM/Eksperymenty/Eksperyment i ankieta - Serbia/SerbiaR.xlsx")



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

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(mu_b_ASC=0, sig_b_ASC=0,
b_No_plan_No_analysis = 0, mu_b_Analysis_no_plan = 0,
sig_b_Analysis_no_plan = 0, mu_b_Analysis_and_plan = 0,
sig_b_Analysis_and_plan = 0,
b_No_organic = 0, mu_b_50plus_organic = 0,
sig_b_50plus_organic = 0, mu_b_full_organic = 0,
sig_b_full_organic =0, b_no_rotation = 0,
mu_b_usual_rotation = 0, sig_b_usual_rotation = 0,
mu_b_advanced_rotation = 0, sig_b_advanced_rotation = 0,
b_no_contract = 0,
mu_b_three_years = 0, sig_b_three_years = 0,
mu_b_five_years = 0, sig_b_five_years = 0,
b_no_support = 0, mu_b_administrative_support = 0,
sig_b_administrative_support = 0, mu_b_Full_expertise = 0,
sig_b_Full_expertise = 0, b_subsidies = 0,
gamma_LV__over_50 = 0, gamma_LV_Gender = 0,
gamma_LV_member_organization = 0, gamma_LV_agri_education = 0,
gamma_LV_farm_area = 0, gamma_LV_workload = 0,
gamma_LV_production_sold =0, b_ASC_shift_lambda=0,
b_Analysis_no_plan_shift_lambda=0,
b_Analysis_and_plan_shift_lambda=0, b_50plus_organic_shift_lambda=0,
b_full_organic_shift_lambda=0, b_usual_rotation_shift_lambda=0,
b_advanced_rotation_shift_lambda= 0, b_three_years_shift_lambda= 0,
b_five_years_shift_lambda= 0, b_administrative_support_shift_lambda= 0,
b_Full_expertise_shift_lambda= 0,
zeta_attitude_1 = 1, zeta_attitude_2 = 1,
zeta_attitude_3 = 1, zeta_attitude_4 = 1,
tau_attitude_1_1 =-3, tau_attitude_1_2 =-2,
tau_attitude_1_3 = -1, tau_attitude_1_4 = 1,
tau_attitude_1_5 =2, tau_attitude_1_6 = 3,
tau_attitude_2_1 =-3, tau_attitude_2_2 =-2,
tau_attitude_2_3 = -1, tau_attitude_2_4 = 1,
tau_attitude_2_5 = 2, tau_attitude_2_6 =3,
tau_attitude_3_1 =-3, tau_attitude_3_2 =-2,
tau_attitude_3_3 = -1, tau_attitude_3_4 = 1,
tau_attitude_3_5 = 2, tau_attitude_3_6 = 3,
tau_attitude_4_1 =-3, tau_attitude_4_2 =-2,
tau_attitude_4_3 = -1, tau_attitude_4_4 = 1,
tau_attitude_4_5 = 2, tau_attitude_4_6 = 3)

### 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("b_No_plan_No_analysis", "b_No_organic", "b_no_rotation", "b_no_contract", "b_no_support")


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

### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "mlhs",
interNDraws = 500,
interNormDraws = c("eta","draws_ASC", "draws_Analysis_no_plan", "draws_Analysis_and_plan", "draws_50plus_organic", "draws_full_organic", "draws_usual_rotation", "draws_advanced_rotation", "draws_three_years", "draws_five_years", "draws_administrative_support", "draws_Full_expertise")
)

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

randcoeff[["LV"]] = gamma_LV__over_50*over_50 + gamma_LV_Gender*Gender + gamma_LV_member_organization*member_organization + gamma_LV_agri_education*agri_education + gamma_LV_farm_area*farm_area + gamma_LV_workload*workload + gamma_LV_production_sold*production_sold + eta
randcoeff[["b_ASC"]] = mu_b_ASC + sig_b_ASC * draws_ASC
randcoeff[["b_Analysis_no_plan"]] = mu_b_Analysis_no_plan + sig_b_Analysis_no_plan * draws_Analysis_no_plan
randcoeff[["b_Analysis_and_plan"]] = mu_b_Analysis_and_plan + sig_b_Analysis_and_plan * draws_Analysis_and_plan
randcoeff[["b_50plus_organic"]] = mu_b_50plus_organic + sig_b_50plus_organic * draws_50plus_organic
randcoeff[["b_full_organic"]] = mu_b_full_organic + sig_b_full_organic * draws_full_organic
randcoeff[["b_usual_rotation"]] = mu_b_usual_rotation + sig_b_usual_rotation * draws_usual_rotation
randcoeff[["b_advanced_rotation"]] = mu_b_advanced_rotation + sig_b_advanced_rotation * draws_advanced_rotation
randcoeff[["b_three_years"]] = mu_b_three_years + sig_b_three_years * draws_three_years
randcoeff[["b_five_years"]] = mu_b_five_years + sig_b_five_years * draws_five_years
randcoeff[["b_administrative_support"]] = mu_b_administrative_support + sig_b_administrative_support * draws_administrative_support
randcoeff[["b_Full_expertise"]] = mu_b_Full_expertise + sig_b_Full_expertise * draws_Full_expertise
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()
### Create coefficients using interactions with socio-demographics
b_ASC_value = b_ASC + b_ASC_shift_lambda * LV
b_Analysis_no_plan_value = b_Analysis_no_plan + b_Analysis_no_plan_shift_lambda * LV
b_Analysis_and_plan_value = b_Analysis_and_plan + b_Analysis_and_plan_shift_lambda * LV
b_50plus_organic_value = b_50plus_organic + b_50plus_organic_shift_lambda * LV
b_full_organic_value = b_full_organic + b_full_organic_shift_lambda * LV
b_usual_rotation_value = b_usual_rotation + b_usual_rotation_shift_lambda * LV
b_advanced_rotation_value = b_advanced_rotation + b_advanced_rotation_shift_lambda * LV
b_three_years_value = b_three_years + b_three_years_shift_lambda * LV
b_five_years_value = b_five_years + b_five_years_shift_lambda * LV
b_administrative_support_value = b_administrative_support + b_administrative_support_shift_lambda * LV
b_Full_expertise_value = b_Full_expertise + b_Full_expertise_shift_lambda * LV


### Likelihood of indicators
ol_settings1 = list(outcomeOrdered = attitude_1,
V = zeta_attitude_1*LV,
tau = list(tau_attitude_1_1, tau_attitude_1_2, tau_attitude_1_3, tau_attitude_1_4, tau_attitude_1_5, tau_attitude_1_6),
rows = (task==1), componentName = "indic_attitude_1")
ol_settings2 = list(outcomeOrdered = attitude_2,
V = zeta_attitude_2*LV,
tau = list(tau_attitude_2_1, tau_attitude_2_2, tau_attitude_2_3, tau_attitude_2_4, tau_attitude_2_5, tau_attitude_2_6),
rows = (task==1), componentName = "indic_attitude_2")
ol_settings3 = list(outcomeOrdered = attitude_3,
V = zeta_attitude_3*LV,
tau = list(tau_attitude_3_1, tau_attitude_3_2, tau_attitude_3_3, tau_attitude_3_4, tau_attitude_3_5, tau_attitude_3_6),
rows = (task==1), componentName = "indic_attitude_3")
ol_settings4 = list(outcomeOrdered = attitude_4,
V = zeta_attitude_4*LV,
tau = list(tau_attitude_4_1, tau_attitude_4_2, tau_attitude_4_3, tau_attitude_4_4, tau_attitude_4_5, tau_attitude_4_6),
rows = (task==1), componentName = "indic_attitude_4")
P[["indic_attitude_1"]] = apollo_ol(ol_settings1, functionality)
P[["indic_attitude_2"]] = apollo_ol(ol_settings2, functionality)
P[["indic_attitude_3"]] = apollo_ol(ol_settings3, functionality)
P[["indic_attitude_4"]] = 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[['alt1']] = ( b_ASC_value*(asc_alt1==0) + b_ASC_value*(asc_alt1==1) + b_No_plan_No_analysis*(plan_alt1==1) + b_Analysis_no_plan_value*(plan_alt1==2) + b_Analysis_and_plan_value*(plan_alt1==3)
+ b_No_organic*(organic_alt1==1) + b_50plus_organic_value*(organic_alt1==2) + b_full_organic_value*(organic_alt1==3) + b_no_rotation*(rotation_alt1==1) + b_usual_rotation_value*(rotation_alt1==2) + b_advanced_rotation_value*(rotation_alt1==3)
+ b_no_contract*(contract_alt1==1) + b_three_years_value*(contract_alt1==2) + b_five_years_value*(contract_alt1==3)
+ b_no_support*(support_alt1==1) + b_administrative_support_value*(support_alt1==2) + b_Full_expertise_value*(support_alt1==3)
+ b_subsidies*subsidies_alt1)
V[['alt2']] = ( b_ASC_value*(asc_alt2==0) + b_ASC_value*(asc_alt2==1) + b_No_plan_No_analysis*(plan_alt2==1) + b_Analysis_no_plan_value*(plan_alt2==2) + b_Analysis_and_plan_value*(plan_alt2==3)
+ b_No_organic*(organic_alt2==1) + b_50plus_organic_value*(organic_alt2==2) + b_full_organic_value*(organic_alt2==3) + b_no_rotation*(rotation_alt2==1) + b_usual_rotation_value*(rotation_alt2==2) + b_advanced_rotation_value*(rotation_alt2==3)
+ b_no_contract*(contract_alt2==1) + b_three_years_value*(contract_alt2==2) + b_five_years_value*(contract_alt2==3)
+ b_no_support*(support_alt2==2) + b_administrative_support_value*(support_alt2==2) + b_Full_expertise_value*(support_alt2==3)
+ b_subsidies*subsidies_alt2)
V[['sq']] = ( b_ASC_value*(asc_sq==0) + b_ASC_value*(asc_sq==1) + b_No_plan_No_analysis*(plan_sq==1) + b_Analysis_no_plan_value*(plan_sq==2) + b_Analysis_and_plan_value*(plan_sq==3)
+ b_No_organic*(organic_sq==1) + b_50plus_organic_value*(organic_sq==2) + b_full_organic_value*(organic_sq==3) + b_no_rotation*(rotation_sq==1) + b_usual_rotation_value*(rotation_sq==2) + b_advanced_rotation_value*(rotation_sq==3)
+ b_no_contract*(contract_sq==1) + b_three_years_value*(contract_sq==2) + b_five_years_value*(contract_sq==3)
+ b_no_support*(support_sq==1) + b_administrative_support_value*(support_sq==2) + b_Full_expertise_value*(support_sq==3)
+ b_subsidies*subsidies_sq)


### Define settings for MNL model component
mnl_settings = list(
alternatives = c(alt1=1, alt2=2, sq=3),
avail = list(alt1=1, alt2=1, sq=1),
choiceVar = choice,
V = V, componentName = "choice"
)

### Compute probabilities for MNL model component
P[["choice"]] = 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)
}

# ################################################################# #
#### CHECK FOR COMPUTATIONAL REQUIREMENTS ####
# ################################################################# #

speedTest_settings=list(
nDrawsTry = c(250, 500, 1000),
nCoresTry = 1:3,
nRep = 10
)

apollo_speedTest(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs, speedTest_settings)

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

### Estimate model
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)
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: ICLV model specification in unlabelled form

Post by stephanehess »

Hi

In order for us to help you, you need to show us the output, i.e. the parameter estimates.

Can you please also confirm that a MNL and mixed logit model worked on the data before moving to hybrid choice?

Thanks
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Post Reply