Thank you for your prompt reply.
As I said before, I want to use ordered logit instead of MNL in the choice part in ICLV.
it somehow works, but some of the results give n/a though it should have the value.
Therefore, the problem is the code. It will be really appreciated if you can give the comments on the problem.
I will explain the detail of my assumption in detail as well as the code.
First, I will attach the framework of the model that I thought.
Second, I will briefly explain the name that I used in the code.
There are two latent variables, "ai" and "risk". Those are Likert scales.
For the choice part, it named "att" in the code. Also Likert scale, the tau is "tau_choice"
I also add some explanation in the beta definition part for your understanding
-----------------------------------------------------------------------------------------------
Code: Select all
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(
# attributes for choice part
gamma_tram = 0,
gamma_auto_tram = 0,
gamma_auto_vehi = 0,
gamma_bus = 0,
gamma_truck_person = 0,
gamma_truck_guard = 0,
# lambda_ai = 1,
#lambda_risk = 1,
# socio-economic variables for choice part
gamma_age = 0,
gamma_license = 0,
gamma_k_tram = 0, #knowledge of tram
gamma_k_social = 0, #knowledge of social experiment
gamma_experi = 0, # experiment method, binary
gamma_video = 0, # experiment method, binary
gamma_none = 0,
# socio-economic of latent variable part
gamma_ai_age = 0,
gamma_ai_license = 0,
gamma_ai_k_tram = 0,
gamma_ai_k_social = 0,
gamma_ai_experi = 0,
gamma_ai_video = 0,
gamma_ai_none = 0,
gamma_risk_age = 0,
gamma_risk_license = 0,
gamma_risk_experi = 0,
gamma_risk_video = 0,
gamma_risk_none = 0,
# tau for choice part (choice part is using ordered logit)
tau_choice_1 = -2,
tau_choice_2 = -1,
tau_choice_3 = 1,
tau_choice_4 = 2,
# tau for latent variables
zeta_ai_1 = 1,
zeta_ai_2 = 0,
zeta_ai_3 = 0,
zeta_ai_4 = 0,
tau_ai1_1 =-2,
tau_ai1_2 =-1,
tau_ai1_3 = 1,
tau_ai1_4 = 2,
tau_ai2_1 =-2,
tau_ai2_2 =-1,
tau_ai2_3 = 1,
tau_ai2_4 = 2,
tau_ai3_1 =-2,
tau_ai3_2 =-1,
tau_ai3_3 = 1,
tau_ai3_4 = 2,
tau_ai4_1 =-2,
tau_ai4_2 =-1,
tau_ai4_3 = 1,
tau_ai4_4 = 2,
zeta_risk_1 = 1,
zeta_risk_2 = 0,
zeta_risk_3 = 0,
tau_risk1_1 =-2,
tau_risk1_2 =-1,
tau_risk1_3 = 1,
tau_risk1_4 = 2,
tau_risk2_1 =-2,
tau_risk2_2 =-1,
tau_risk2_3 = 1,
tau_risk2_4 = 2,
tau_risk3_1 =-2,
tau_risk3_2 =-1,
tau_risk3_3 = 1,
tau_risk3_4 = 2
)
### 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()
# ################################################################# #
#### DEFINE RANDOM COMPONENTS ####
# ################################################################# #
### Set parameters for generating draws
apollo_draws = list(
interDrawsType="halton",
interNDraws=100,
interUnifDraws=c(),
interNormDraws=c("eta_ai", "eta_risk", "eta_att"),
intraDrawsType='',
intraNDraws=0,
intraUnifDraws=c(),
intraNormDraws=c()
)
### Create random parameters
apollo_randCoeff=function(apollo_beta, apollo_inputs){
randcoeff = list()
randcoeff[["LV_ai"]] = gamma_ai_age*age + gamma_ai_license*license + gamma_ai_k_tram*k_tram +
gamma_ai_k_social*k_social + gamma_ai_video*video1 + gamma_ai_none*video2 + gamma_ai_experi*exp_group+ eta_ai
randcoeff[["LV_risk"]] = gamma_risk_age*age + gamma_risk_license*license + gamma_risk_video*video1 +
gamma_risk_none*video2 + gamma_risk_experi*exp_group + eta_risk
randcoeff[["LV_att"]] = gamma_tram*tram + gamma_auto_tram*auto_tram + gamma_auto_vehi*auto_vehi + gamma_bus*bus +
gamma_truck_person*truck_person + gamma_truck_guard*truck_guard + gamma_age* age + gamma_license*license +
gamma_k_tram*k_tram + gamma_k_social*k_social + gamma_experi*exp_group + gamma_none*video2 + gamma_video*video1 +eta_att
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 = s19_6,
V = zeta_ai_1*LV_ai,
tau = c(tau_ai1_1, tau_ai1_2, tau_ai1_3, tau_ai1_4),
rows = (task==1))
ol_settings2 = list(outcomeOrdered = s19_7,
V = zeta_ai_2*LV_ai,
tau = c(tau_ai2_1, tau_ai2_2, tau_ai2_3, tau_ai2_4),
rows = (task==1))
ol_settings3 = list(outcomeOrdered = s19_8,
V = zeta_ai_3*LV_ai,
tau = c(tau_ai3_1, tau_ai3_2, tau_ai3_3, tau_ai3_4),
rows = (task==1))
ol_settings4 = list(outcomeOrdered = s19_9,
V = zeta_ai_4*LV_ai,
tau = c(tau_ai4_1, tau_ai4_2, tau_ai4_3, tau_ai4_4),
rows = (task==1))
ol_settings5 = list(outcomeOrdered = s20_3,
V = zeta_risk_1*LV_risk,
tau = c(tau_risk1_1, tau_risk1_2, tau_risk1_3, tau_risk1_4),
rows = (task==1))
ol_settings6 = list(outcomeOrdered = s20_4,
V = zeta_risk_2*LV_risk,
tau = c(tau_risk2_1, tau_risk2_2, tau_risk2_3, tau_risk2_4),
rows = (task==1))
ol_settings7 = list(outcomeOrdered = s20_5,
V = zeta_risk_3*LV_risk,
tau = c(tau_risk3_1, tau_risk3_2, tau_risk3_3, tau_risk3_4),
rows = (task==1))
P[["ai_1"]] = apollo_ol(ol_settings1, functionality)
P[["ai_2"]] = apollo_ol(ol_settings2, functionality)
P[["ai_3"]] = apollo_ol(ol_settings3, functionality)
P[["ai_4"]] = apollo_ol(ol_settings4, functionality)
P[["risk_1"]] = apollo_ol(ol_settings5, functionality)
P[["risk_2"]] = apollo_ol(ol_settings6, functionality)
P[["risk_3"]] = apollo_ol(ol_settings7, functionality)
### Likelihood of choices
### List of utilities: these must use the same names as in ol_settings, order is irrelevant
ol_settings = list(outcomeOrdered = choice,
V = LV_att*LV_risk*LV_ai,
tau = c(tau_choice_1, tau_choice_2, tau_choice_3, tau_choice_4),
componentName = "choice_part")
### Compute ordered logit probabilites for choice part
P[["choice"]] = apollo_ol(ol_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)
### Prepare and return outputs of function
#P = apollo_prepareProb(P, apollo_inputs, functionality)
### Compute probabilities for MNL model component
# P[["model"]] = apollo_mnl(mnl_settings, 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)
# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #
apollo_modelOutput(model)
Some parameters show unavailable values. I will be really appreciated it if you give some comments on where I need to revise.
Thank you so much for the best tool for choice modeling, again.