After ICLV: Simulate WTP along range of LV
Posted: 20 Apr 2023, 11:11
Hello,
I'm running an ICLV model with 4 LVs and (currently still) uncorrelated random parameters in the choice equation. The model is in preference space, parameters are normally distributed, cost parameter is mirrored log-normally distributed, so I need to use unconditional draws to simulate marg. WTP. The LVs are interacted with all mean preference weights in the choice equation, i.e. they are included as mean shifters in randcoeff.
Having obtained the model output, I would like to simulate marg. WTP along the range of one specific LV. If an LV has a range of, say, -2 to +2, I would like to simulate the betas (or ratios of betas, i.e. WTP) for a sequence of LV values in this range.
What modification do I need before or after apollo_unconditionals() to do that? My problem is that the LVs shift the mean of the mu-shifted normal distribution of the cost parameter, so would have to be manipulated before extracting the unconditionals. But I'm not sure how to do that.
Many thanks and best wishes
Tobias
#### 1. 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 = "ICLV2-150-mushift",
modelDescr = "ICLV model",
indivID = "respid",
mixing = TRUE,
panelData = TRUE,
nCores = 10,
outputDirectory = "output"
)
# ####
#### 2. LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
source(file.path("data","setup-data.R"))
# ####
#### 3. DEFINE MODEL PARAMETERS ####
apollo_beta <- c(-0.263595890535925, -0.877795850406257, -1.46344729891276, 0.147388444654724, 0.0390812095766384, 0.219709394190709, -0.799789012376286, 0.685112121998949, 0.599680211654783, -0.176523966310319, 0.282894574144486, -2.51201445505734, 0.272036373551889, 0.0332499251950733, 0.451203710652852, 1.34039859475733, 0.168696467734364, -0.108644079732149, -0.184546338358116, -0.167039591246857, 0.678313375901563, 0.00649748980399031, 0.119646775974343, 0.0541048771481104, 0.0765850666280197, 0.0565537759586298, -0.0675482693231369, -0.192130072142295, -0.237721801547889, 0.156275935628932, 0.00923718433670055, 0.0326967198250995, -0.331890474653538, 0.693294720154439, -0.202504153666109, -0.300658809503898, 0.5394520366849, 0.555214600134694, -0.631653069293468, -0.068464225198733, -0.125651236927408, 0.252588730458113, -0.19469515292462, 0.133251994702141, 0.229361171948157, 1.66093931774463, 2.03048033540746, 0.293279477451139, 0.515986679160807, 0.680053263965322, 0.642750908719204, 0.477154626682397, 0.435722886845636, 0.526343128666326, 0.510646610943036, -1.57705514838932, -0.290552787887763, 0.809697406410988, 2.1522460119667, 1.42058118017912, -5.31171851339919, -3.52483934292071, -1.91049361802076, -0.206134415975181, 1.2602718440872, -6.35389961387888, -4.39715559799527, -2.43237174739628, -0.494970265718682, 1.36470741681215, -3.21389797168539, -0.824580919685466, 1.04418211473543, 3.09323687247162, 0.226755311861272, -1.94185361685057, -0.62982791434553, 0.674785926801447, 2.29639678120512, 1.43397042790907, -2.79218775468885, -0.639429324102643, 1.15258899839659, 2.86645611440518, 1.72227910443098, -2.15741593846108, -0.395724020688492, 1.11724537440749, 2.50924138499162, 1.53835872447696, -2.23168426414781, 0.161973349517357, 1.81672559393544, 3.55217647495339, 1.43515909090826, -3.5958166607788, -2.34098849892343, -0.834158438538792, 0.883690753675783, 1.91520822051063, -4.61290441070375, -2.08301736820464, -0.187628692875705, 2.06093742492254, 1.78100004236781, -3.97974220346656, -1.73334229076737, 0.261563511571412, 2.40250140438525, 1.5513010415419, -3.20545693957606, -0.949739610620965, 0.73451895299203, 2.64296875094346, 1.71720636363008, -4.72463223747029, -2.43315456926038, -0.55191231779791, 1.58949186049228, 1.35019405476924, -4.73754166820096, -2.97494711006753, -1.07032680137781, 0.871314665559812, 1.49938566131686, -3.06010487773117, -0.649792040683238, 1.12942579241114, 2.84298872505797, 1.34299775272937, -2.84298457109242, -0.545496586116384, 1.14427011223512, 2.97656792759587, -0.381869679374898, -0.00554298247346097, -0.348459637563478, -0.0970235217691445, 0.00488948909566323, 0.0122537838386344, -0.248041669633993, -0.0209654120298913, -0.214324271969543, -0.00319588917523904, -0.163219773478612, 0.0102583537771804, 0.00176231500356036, 0.0097992195987407, 0.087232621457131, 0.0436750467353999
names(apollo_beta) <- c("mu_altb","mu_altc","mu_steuer","mu_truppe1","mu_truppe2","mu_euro","mu_wehrpf","mu_schirm1","mu_schirm2",
"sigma_altb","sigma_altc","sigma_steuer","sigma_truppe1","sigma_truppe2","sigma_euro","sigma_wehrpf",
"sigma_schirm1","sigma_schirm2",
"lam_altb_1","lam_altc_1","lam_steuer_1","lam_truppe1_1","lam_truppe2_1","lam_euro_1","lam_wehrpf_1","lam_schirm1_1","lam_schirm2_1",
"lam_altb_2","lam_altc_2","lam_steuer_2","lam_truppe1_2","lam_truppe2_2","lam_euro_2","lam_wehrpf_2","lam_schirm1_2","lam_schirm2_2",
"lam_altb_3","lam_altc_3","lam_steuer_3","lam_truppe1_3","lam_truppe2_3","lam_euro_3","lam_wehrpf_3","lam_schirm1_3","lam_schirm2_3",
"lam_altb_4","lam_altc_4","lam_steuer_4","lam_truppe1_4","lam_truppe2_4","lam_euro_4","lam_wehrpf_4","lam_schirm1_4","lam_schirm2_4",
"zeta_ind1" ,"tau_ind1_1" ,"tau_ind1_2" ,"tau_ind1_3" ,"tau_ind1_4",
"zeta_ind2" ,"tau_ind2_1" ,"tau_ind2_2" ,"tau_ind2_3" ,"tau_ind2_4",
"zeta_ind11","tau_ind11_1","tau_ind11_2","tau_ind11_3","tau_ind11_4",
"zeta_ind6" ,"tau_ind6_1" ,"tau_ind6_2" ,"tau_ind6_3" ,"tau_ind6_4",
"zeta_ind8" ,"tau_ind8_1" ,"tau_ind8_2" ,"tau_ind8_3" ,"tau_ind8_4",
"zeta_ind9" ,"tau_ind9_1" ,"tau_ind9_2" ,"tau_ind9_3" ,"tau_ind9_4",
"zeta_ind10","tau_ind10_1","tau_ind10_2","tau_ind10_3","tau_ind10_4",
"zeta_ind12","tau_ind12_1","tau_ind12_2","tau_ind12_3","tau_ind12_4",
"zeta_ind3" ,"tau_ind3_1" ,"tau_ind3_2" ,"tau_ind3_3" ,"tau_ind3_4",
"zeta_ind4" ,"tau_ind4_1" ,"tau_ind4_2" ,"tau_ind4_3" ,"tau_ind4_4",
"zeta_ind7" ,"tau_ind7_1" ,"tau_ind7_2" ,"tau_ind7_3" ,"tau_ind7_4",
"zeta_ind13","tau_ind13_1","tau_ind13_2","tau_ind13_3","tau_ind13_4",
"zeta_ind5" ,"tau_ind5_1" ,"tau_ind5_2" ,"tau_ind5_3" ,"tau_ind5_4",
"zeta_ind14","tau_ind14_1","tau_ind14_2","tau_ind14_3","tau_ind14_4",
"zeta_ind15","tau_ind15_1","tau_ind15_2","tau_ind15_3","tau_ind15_4",
"zeta_ind17","tau_ind17_1","tau_ind17_2","tau_ind17_3","tau_ind17_4",
"gamma_male_1","gamma_age_1","gamma_uni_1","gamma_inc_1",
"gamma_male_2","gamma_age_2","gamma_uni_2","gamma_inc_2",
"gamma_male_3","gamma_age_3","gamma_uni_3","gamma_inc_3",
"gamma_male_4","gamma_age_4","gamma_uni_4","gamma_inc_4")
apollo_fixed = c()
# ####
#### 4. DEFINE RANDOM COMPONENTS ####
### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "sobol",
interNDraws = 150,
# interUnifDraws = c(),
interNormDraws = c("draws_altb","draws_altc","draws_truppe1","draws_truppe2","draws_euro","draws_wehrpf",
"draws_schirm1","draws_schirm2","draws_steuer",
"eta1","eta2","eta3","eta4")
)
### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()
randcoeff[["LV_1"]] = eta1 + gamma_male_1*male + gamma_age_1*RESP_AGE + gamma_uni_1*uni + gamma_inc_1*inc_imputed
randcoeff[["LV_2"]] = eta2 + gamma_male_2*male + gamma_age_2*RESP_AGE + gamma_uni_2*uni + gamma_inc_2*inc_imputed
randcoeff[["LV_3"]] = eta3 + gamma_male_3*male + gamma_age_3*RESP_AGE + gamma_uni_3*uni + gamma_inc_3*inc_imputed
randcoeff[["LV_4"]] = eta4 + gamma_male_4*male + gamma_age_4*RESP_AGE + gamma_uni_4*uni + gamma_inc_4*inc_imputed
randcoeff[["b_steuer"]] = -exp(mu_steuer +lam_steuer_1*randcoeff[["LV_1"]] +lam_steuer_2*randcoeff[["LV_2"]] +lam_steuer_3*randcoeff[["LV_3"]] +lam_steuer_4*randcoeff[["LV_4"]] + sigma_steuer*draws_steuer) -exp(mu_steuer+lam_steuer_1*randcoeff[["LV_1"]] +lam_steuer_2*randcoeff[["LV_2"]] +lam_steuer_3*randcoeff[["LV_3"]] +lam_steuer_4*randcoeff[["LV_4"]])
randcoeff[["b_altb"]] = mu_altb +lam_altb_1*randcoeff[["LV_1"]] +lam_altb_2*randcoeff[["LV_2"]] +lam_altb_3*randcoeff[["LV_3"]] +lam_altb_4*randcoeff[["LV_4"]] + sigma_altb*draws_altb + sigma_altb_steuer*draws_steuer
randcoeff[["b_altc"]] = mu_altc +lam_altc_1*randcoeff[["LV_1"]] +lam_altc_2*randcoeff[["LV_2"]] +lam_altc_3*randcoeff[["LV_3"]] +lam_altc_4*randcoeff[["LV_4"]] + sigma_altc*draws_altc + sigma_altc_steuer*draws_steuer + sigma_altc_altb*draws_altb
randcoeff[["b_schirm1"]] = mu_schirm1 + lam_schirm1_1*randcoeff[["LV_1"]]+lam_schirm1_2*randcoeff[["LV_2"]]+lam_schirm1_3*randcoeff[["LV_3"]]+lam_schirm1_4*randcoeff[["LV_4"]] + sigma_schirm1*draws_schirm1 + sigma_schirm1_steuer*draws_steuer + sigma_schirm1_altb*draws_altb + sigma_schirm1_altc*draws_altc
randcoeff[["b_schirm2"]] = mu_schirm2 + lam_schirm2_1*randcoeff[["LV_1"]]+lam_schirm2_2*randcoeff[["LV_2"]]+lam_schirm2_3*randcoeff[["LV_3"]]+lam_schirm2_4*randcoeff[["LV_4"]] + sigma_schirm2*draws_schirm2 + sigma_schirm2_steuer*draws_steuer + sigma_schirm2_altb*draws_altb + sigma_schirm2_altc*draws_altc + sigma_schirm2_schirm1*draws_schirm1
randcoeff[["b_truppe1"]] = mu_truppe1 + lam_truppe1_1*randcoeff[["LV_1"]]+lam_truppe1_2*randcoeff[["LV_2"]]+lam_truppe1_3*randcoeff[["LV_3"]]+lam_truppe1_4*randcoeff[["LV_4"]] + sigma_truppe1*draws_truppe1 + sigma_truppe1_steuer*draws_steuer + sigma_truppe1_altb*draws_altb + sigma_truppe1_altc*draws_altc + sigma_truppe1_schirm1*draws_schirm1 + sigma_truppe1_schirm2*draws_schirm2
randcoeff[["b_truppe2"]] = mu_truppe2 + lam_truppe2_1*randcoeff[["LV_1"]]+lam_truppe2_2*randcoeff[["LV_2"]]+lam_truppe2_3*randcoeff[["LV_3"]]+lam_truppe2_4*randcoeff[["LV_4"]] + sigma_truppe2*draws_truppe2 + sigma_truppe2_steuer*draws_steuer + sigma_truppe2_altb*draws_altb + sigma_truppe2_altc*draws_altc + sigma_truppe2_schirm1*draws_schirm1 + sigma_truppe2_schirm2*draws_schirm2 + sigma_truppe2_truppe1*draws_truppe1
randcoeff[["b_euro"]] = mu_euro + lam_euro_1*randcoeff[["LV_1"]] +lam_euro_2*randcoeff[["LV_2"]] +lam_euro_3*randcoeff[["LV_3"]] +lam_euro_4*randcoeff[["LV_4"]] + sigma_euro*draws_euro + sigma_euro_steuer*draws_steuer + sigma_euro_altb*draws_altb + sigma_euro_altc*draws_altc + sigma_euro_schirm1*draws_schirm1 + sigma_euro_schirm2*draws_schirm2 + sigma_euro_truppe1*draws_truppe1 + sigma_euro_truppe2*draws_truppe2
randcoeff[["b_wehrpf"]] = mu_wehrpf + lam_wehrpf_1*randcoeff[["LV_1"]] +lam_wehrpf_2*randcoeff[["LV_2"]] +lam_wehrpf_3*randcoeff[["LV_3"]] +lam_wehrpf_4*randcoeff[["LV_4"]]+ sigma_wehrpf*draws_wehrpf + sigma_wehrpf_steuer*draws_steuer + sigma_wehrpf_altb*draws_altb + sigma_wehrpf_altc*draws_altc + sigma_wehrpf_schirm1*draws_schirm1 + sigma_wehrpf_schirm2*draws_schirm2 + sigma_wehrpf_truppe1*draws_truppe1 + sigma_wehrpf_truppe2*draws_truppe2 + sigma_wehrpf_euro*draws_euro
return(randcoeff)
}
# ####
#### 5. GROUP AND VALIDATE INPUTS ####
apollo_inputs = apollo_validateInputs()
# ####
#### 6. 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()
### List of utilities: these must use the same names as in mnl_settings, order is irrelevant
V = list()
V[['sq']] = b_steuer*steuer.A + b_truppe1*truppe1.A + b_truppe2*truppe2.A + b_euro*euro.A + b_wehrpf*wehrpf.A + b_schirm1*schirm1.A + b_schirm2*schirm2.A
V[['alt2']] = b_steuer*steuer.B + b_altb + b_truppe1*truppe1.B + b_truppe2*truppe2.B + b_euro*euro.B + b_wehrpf*wehrpf.B + b_schirm1*schirm1.B + b_schirm2*schirm2.B
V[['alt3']] = b_steuer*steuer.C + b_altc + b_truppe1*truppe1.C + b_truppe2*truppe2.C + b_euro*euro.C + b_wehrpf*wehrpf.C + b_schirm1*schirm1.C + b_schirm2*schirm2.C
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(sq=1, alt2=2, alt3=3),
avail = 1,
choiceVar = choice,
V = V
)
### Compute probabilities for MNL model component
P[["choice"]] = apollo_mnl(mnl_settings, functionality)
### Likelihood of indicators
ol_settings1_1 = list(outcomeOrdered = r15_1,
V = zeta_ind1*LV_1,
tau = list(tau_ind1_1, tau_ind1_2, tau_ind1_3, tau_ind1_4),
rows = (round==1))
ol_settings1_2 = list(outcomeOrdered = r15_2,
V = zeta_ind2*LV_1,
tau = list(tau_ind2_1, tau_ind2_2, tau_ind2_3, tau_ind2_4),
rows = (round==1))
ol_settings1_3 = list(outcomeOrdered = r15_11,
V = zeta_ind11*LV_1,
tau = list(tau_ind11_1, tau_ind11_2, tau_ind11_3, tau_ind11_4),
rows = (round==1))
P[["indic_1_1"]] = apollo_ol(ol_settings1_1, functionality)
P[["indic_1_2"]] = apollo_ol(ol_settings1_2, functionality)
P[["indic_1_3"]] = apollo_ol(ol_settings1_3, functionality)
ol_settings2_1 = list(outcomeOrdered = r15_6,
V = zeta_ind6*LV_2,
tau = list(tau_ind6_1, tau_ind6_2, tau_ind6_3, tau_ind6_4),
rows = (round==1))
ol_settings2_2 = list(outcomeOrdered = r15_8,
V = zeta_ind8*LV_2,
tau = list(tau_ind8_1, tau_ind8_2, tau_ind8_3, tau_ind8_4),
rows = (round==1))
ol_settings2_3 = list(outcomeOrdered = r15_9,
V = zeta_ind9*LV_2,
tau = list(tau_ind9_1, tau_ind9_2, tau_ind9_3, tau_ind9_4),
rows = (round==1))
ol_settings2_4 = list(outcomeOrdered = r15_10,
V = zeta_ind10*LV_2,
tau = list(tau_ind10_1, tau_ind10_2, tau_ind10_3, tau_ind10_4),
rows = (round==1))
ol_settings2_5 = list(outcomeOrdered = r15_12,
V = zeta_ind12*LV_2,
tau = list(tau_ind12_1, tau_ind12_2, tau_ind12_3, tau_ind12_4),
rows = (round==1))
P[["indic_2_1"]] = apollo_ol(ol_settings2_1, functionality)
P[["indic_2_2"]] = apollo_ol(ol_settings2_2, functionality)
P[["indic_2_3"]] = apollo_ol(ol_settings2_3, functionality)
P[["indic_2_4"]] = apollo_ol(ol_settings2_4, functionality)
P[["indic_2_5"]] = apollo_ol(ol_settings2_5, functionality)
ol_settings3_1 = list(outcomeOrdered = r15_3,
V = zeta_ind3*LV_3,
tau = list(tau_ind3_1, tau_ind3_2, tau_ind3_3, tau_ind3_4),
rows = (round==1))
ol_settings3_2 = list(outcomeOrdered = r15_4,
V = zeta_ind4*LV_3,
tau = list(tau_ind4_1, tau_ind4_2, tau_ind4_3, tau_ind4_4),
rows = (round==1))
ol_settings3_3 = list(outcomeOrdered = r15_7,
V = zeta_ind7*LV_3,
tau = list(tau_ind7_1, tau_ind7_2, tau_ind7_3, tau_ind7_4),
rows = (round==1))
ol_settings3_4 = list(outcomeOrdered = r15_13,
V = zeta_ind13*LV_3,
tau = list(tau_ind13_1, tau_ind13_2, tau_ind13_3, tau_ind13_4),
rows = (round==1))
P[["indic_3_1"]] = apollo_ol(ol_settings3_1, functionality)
P[["indic_3_2"]] = apollo_ol(ol_settings3_2, functionality)
P[["indic_3_3"]] = apollo_ol(ol_settings3_3, functionality)
P[["indic_3_4"]] = apollo_ol(ol_settings3_4, functionality)
ol_settings4_1 = list(outcomeOrdered = r15_5,
V = zeta_ind5*LV_3,
tau = list(tau_ind5_1, tau_ind5_2, tau_ind5_3, tau_ind5_4),
rows = (round==1))
ol_settings4_2 = list(outcomeOrdered = r15_14,
V = zeta_ind14*LV_3,
tau = list(tau_ind14_1, tau_ind14_2, tau_ind14_3, tau_ind14_4),
rows = (round==1))
ol_settings4_3 = list(outcomeOrdered = r15_15,
V = zeta_ind15*LV_3,
tau = list(tau_ind15_1, tau_ind15_2, tau_ind15_3, tau_ind15_4),
rows = (round==1))
ol_settings4_4 = list(outcomeOrdered = r15_17,
V = zeta_ind17*LV_3,
tau = list(tau_ind17_1, tau_ind17_2, tau_ind17_3, tau_ind17_4),
rows = (round==1))
P[["indic_4_1"]] = apollo_ol(ol_settings4_1, functionality)
P[["indic_4_2"]] = apollo_ol(ol_settings4_2, functionality)
P[["indic_4_3"]] = apollo_ol(ol_settings4_3, functionality)
P[["indic_4_4"]] = apollo_ol(ol_settings4_4, 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)
}
# ####
#### 7. MODEL ESTIMATION ####
estimate_settings = list(hessianRoutine="none")
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs) # , estimate_settings)
# #####
#### 8. MODEL OUTPUTS ####
apollo_modelOutput(model, modelOutput_settings = list(printPVal=TRUE, printClassical=FALSE))
# apollo_saveOutput(model)
# ####
Model name : ICLV2-150-mushift
Model description : ICLV model
Model run at : 2023-04-17 20:09:06
Estimation method : bfgs
Model diagnosis : successful convergence
Number of individuals : 1808
Number of rows in database : 14464
Number of modelled outcomes : 43392
choice : 14464
indic_1_1 : 1808
indic_1_2 : 1808
indic_1_3 : 1808
indic_2_1 : 1808
indic_2_2 : 1808
indic_2_3 : 1808
indic_2_4 : 1808
indic_2_5 : 1808
indic_3_1 : 1808
indic_3_2 : 1808
indic_3_3 : 1808
indic_3_4 : 1808
indic_4_1 : 1808
indic_4_2 : 1808
indic_4_3 : 1808
indic_4_4 : 1808
Number of cores used : 10
Number of inter-individual draws : 150 (sobol)
LL(start) : -50531.78
LL (whole model) at equal shares, LL(0) : -62448.15
LL (whole model) at observed shares, LL(C) : -57974.32
LL(final, whole model) : -50188.01
Rho-squared vs equal shares : 0.1963
Adj.Rho-squared vs equal shares : 0.1939
Rho-squared vs observed shares : 0.1343
Adj.Rho-squared vs observed shares : 0.1317
AIC : 100676
BIC : 101812.9
LL(0,choice) : -15890.33
LL(final,choice) : -10493.81
LL(0,indic_1_1) : -2909.86
LL(final,indic_1_1) : -2751.09
LL(0,indic_1_2) : -2909.86
LL(final,indic_1_2) : -2551.27
LL(0,indic_1_3) : -2909.86
LL(final,indic_1_3) : -2248.66
LL(0,indic_2_1) : -2909.86
LL(final,indic_2_1) : -2606.34
LL(0,indic_2_2) : -2909.86
LL(final,indic_2_2) : -2757.72
LL(0,indic_2_3) : -2909.86
LL(final,indic_2_3) : -2694.73
LL(0,indic_2_4) : -2909.86
LL(final,indic_2_4) : -2820.87
LL(0,indic_2_5) : -2909.86
LL(final,indic_2_5) : -2731.46
LL(0,indic_3_1) : -2909.86
LL(final,indic_3_1) : -2682.81
LL(0,indic_3_2) : -2909.86
LL(final,indic_3_2) : -2662.6
LL(0,indic_3_3) : -2909.86
LL(final,indic_3_3) : -2677.13
LL(0,indic_3_4) : -2909.86
LL(final,indic_3_4) : -2691
LL(0,indic_4_1) : -2909.86
LL(final,indic_4_1) : -2616.53
LL(0,indic_4_2) : -2909.86
LL(final,indic_4_2) : -2472.84
LL(0,indic_4_3) : -2909.86
LL(final,indic_4_3) : -2627.11
LL(0,indic_4_4) : -2909.86
LL(final,indic_4_4) : -2612.95
Estimated parameters : 150
Time taken (hh:mm:ss) : 29:32:19.43
pre-estimation : 01:03:33.49
estimation : 03:29:49.02
post-estimation : 24:58:56.92
Iterations : 162
Min abs eigenvalue of Hessian : 2.222011
Unconstrained optimisation.
These outputs have had the scaling used in estimation applied to them.
Estimates:
Estimate Rob.s.e. Rob.t.rat.(0) p(1-sided)
mu_altb -0.263596 0.322610 -0.81707 0.206943
mu_altc -0.877796 0.350521 -2.50426 0.006135
mu_steuer -1.463447 0.142324 -10.28250 0.000000
mu_truppe1 0.147388 0.123559 1.19285 0.116463
mu_truppe2 0.039081 0.146140 0.26742 0.394572
mu_euro 0.219709 0.128581 1.70872 0.043751
mu_wehrpf -0.799789 0.166186 -4.81262 7.448e-07
mu_schirm1 0.685112 0.136121 5.03311 2.413e-07
mu_schirm2 0.599680 0.167164 3.58738 1.6701e-04
sigma_altb -0.176524 0.127084 -1.38903 0.082412
sigma_altc 0.282895 0.161680 1.74972 0.040083
sigma_steuer -2.512014 0.280388 -8.95906 0.000000
sigma_truppe1 0.272036 0.095349 2.85304 0.002165
sigma_truppe2 0.033250 0.145226 0.22895 0.409453
sigma_euro 0.451204 0.116386 3.87679 5.292e-05
sigma_wehrpf 1.340399 0.119364 11.22946 0.000000
sigma_schirm1 0.168696 0.118787 1.42016 0.077780
sigma_schirm2 -0.108644 0.122922 -0.88385 0.188389
lam_altb_1 -0.184546 0.194622 -0.94823 0.171506
lam_altc_1 -0.167040 0.213478 -0.78247 0.216970
lam_steuer_1 0.678313 0.159003 4.26605 9.948e-06
lam_truppe1_1 0.006497 0.069511 0.09347 0.462764
lam_truppe2_1 0.119647 0.094550 1.26544 0.102858
lam_euro_1 0.054105 0.086263 0.62721 0.265260
lam_wehrpf_1 0.076585 0.112944 0.67808 0.248860
lam_schirm1_1 0.056554 0.085870 0.65860 0.255077
lam_schirm2_1 -0.067548 0.095411 -0.70797 0.239482
lam_altb_2 -0.192130 0.166337 -1.15506 0.124032
lam_altc_2 -0.237722 0.172991 -1.37418 0.084692
lam_steuer_2 0.156276 0.181187 0.86251 0.194203
lam_truppe1_2 0.009237 0.076618 0.12056 0.452019
lam_truppe2_2 0.032697 0.085390 0.38291 0.350893
lam_euro_2 -0.331890 0.070897 -4.68133 1.425e-06
lam_wehrpf_2 0.693295 0.104394 6.64116 1.556e-11
lam_schirm1_2 -0.202504 0.085721 -2.36235 0.009080
lam_schirm2_2 -0.300659 0.093445 -3.21748 6.4660e-04
lam_altb_3 0.539452 0.176056 3.06409 0.001092
lam_altc_3 0.555215 0.189734 2.92629 0.001715
lam_steuer_3 -0.631653 0.121308 -5.20703 9.594e-08
lam_truppe1_3 -0.068464 0.070571 -0.97015 0.165985
lam_truppe2_3 -0.125651 0.086002 -1.46103 0.072004
lam_euro_3 0.252589 0.080352 3.14354 8.3459e-04
lam_wehrpf_3 -0.194695 0.097576 -1.99532 0.023004
lam_schirm1_3 0.133252 0.084407 1.57868 0.057205
lam_schirm2_3 0.229361 0.092677 2.47484 0.006665
lam_altb_4 1.660939 0.179290 9.26396 0.000000
lam_altc_4 2.030480 0.184142 11.02669 0.000000
lam_steuer_4 0.293279 0.084855 3.45624 2.7389e-04
lam_truppe1_4 0.515987 0.073632 7.00760 1.212e-12
lam_truppe2_4 0.680053 0.087975 7.73004 5.329e-15
lam_euro_4 0.642751 0.083012 7.74285 4.885e-15
lam_wehrpf_4 0.477155 0.104831 4.55165 2.661e-06
lam_schirm1_4 0.435723 0.091444 4.76493 9.446e-07
lam_schirm2_4 0.526343 0.092576 5.68551 6.521e-09
zeta_ind1 0.510647 0.082548 6.18606 3.084e-10
tau_ind1_1 -1.577055 0.197291 -7.99353 6.661e-16
tau_ind1_2 -0.290553 0.180448 -1.61017 0.053680
tau_ind1_3 0.809697 0.173562 4.66517 1.542e-06
tau_ind1_4 2.152246 0.179871 11.96550 0.000000
zeta_ind2 1.420581 0.139055 10.21599 0.000000
tau_ind2_1 -5.311719 0.486244 -10.92397 0.000000
tau_ind2_2 -3.524839 0.431423 -8.17026 1.110e-16
tau_ind2_3 -1.910494 0.397014 -4.81216 7.465e-07
tau_ind2_4 -0.206134 0.372273 -0.55372 0.289886
zeta_ind11 1.260272 0.123581 10.19798 0.000000
tau_ind11_1 -6.353900 0.401280 -15.83410 0.000000
tau_ind11_2 -4.397156 0.319116 -13.77918 0.000000
tau_ind11_3 -2.432372 0.296281 -8.20968 1.110e-16
tau_ind11_4 -0.494970 0.298544 -1.65795 0.048664
zeta_ind6 1.364707 0.095403 14.30467 0.000000
tau_ind6_1 -3.213898 0.219997 -14.60883 0.000000
tau_ind6_2 -0.824581 0.177181 -4.65390 1.629e-06
tau_ind6_3 1.044182 0.176415 5.91889 1.621e-09
tau_ind6_4 3.093237 0.194281 15.92146 0.000000
zeta_ind8 0.226755 0.073526 3.08401 0.001021
tau_ind8_1 -1.941854 0.078447 -24.75370 0.000000
tau_ind8_2 -0.629828 0.058067 -10.84657 0.000000
tau_ind8_3 0.674786 0.058309 11.57261 0.000000
tau_ind8_4 2.296397 0.084224 27.26534 0.000000
zeta_ind9 1.433970 0.092071 15.57461 0.000000
tau_ind9_1 -2.792188 0.210007 -13.29570 0.000000
tau_ind9_2 -0.639429 0.184246 -3.47051 2.5974e-04
tau_ind9_3 1.152589 0.189416 6.08495 5.826e-10
tau_ind9_4 2.866456 0.204469 14.01901 0.000000
zeta_ind10 1.722279 0.102342 16.82870 0.000000
tau_ind10_1 -2.157416 0.226555 -9.52272 0.000000
tau_ind10_2 -0.395724 0.217005 -1.82357 0.034108
tau_ind10_3 1.117245 0.222647 5.01801 2.610e-07
tau_ind10_4 2.509241 0.236236 10.62175 0.000000
zeta_ind12 1.538359 0.094649 16.25334 0.000000
tau_ind12_1 -2.231684 0.213608 -10.44756 0.000000
tau_ind12_2 0.161973 0.193543 0.83689 0.201328
tau_ind12_3 1.816726 0.192745 9.42556 0.000000
tau_ind12_4 3.552176 0.212505 16.71572 0.000000
zeta_ind3 1.435159 0.104581 13.72299 0.000000
tau_ind3_1 -3.595817 0.225897 -15.91791 0.000000
tau_ind3_2 -2.340988 0.210770 -11.10684 0.000000
tau_ind3_3 -0.834158 0.204605 -4.07692 2.282e-05
tau_ind3_4 0.883691 0.205671 4.29662 8.671e-06
zeta_ind4 1.915208 0.124931 15.33008 0.000000
tau_ind4_1 -4.612904 0.339145 -13.60158 0.000000
tau_ind4_2 -2.083017 0.295153 -7.05742 8.481e-13
tau_ind4_3 -0.187629 0.274710 -0.68301 0.247301
tau_ind4_4 2.060937 0.270455 7.62026 1.266e-14
zeta_ind7 1.781000 0.111435 15.98247 0.000000
tau_ind7_1 -3.979742 0.274446 -14.50103 0.000000
tau_ind7_2 -1.733342 0.254814 -6.80239 5.145e-12
tau_ind7_3 0.261564 0.250034 1.04611 0.147755
tau_ind7_4 2.402501 0.260381 9.22686 0.000000
zeta_ind13 1.551301 0.100940 15.36856 0.000000
tau_ind13_1 -3.205457 0.242049 -13.24303 0.000000
tau_ind13_2 -0.949740 0.224225 -4.23566 1.139e-05
tau_ind13_3 0.734519 0.220126 3.33681 4.2373e-04
tau_ind13_4 2.642969 0.235961 11.20088 0.000000
zeta_ind5 1.717206 0.130746 13.13389 0.000000
tau_ind5_1 -4.724632 0.272766 -17.32119 0.000000
tau_ind5_2 -2.433155 0.235966 -10.31148 0.000000
tau_ind5_3 -0.551912 0.234566 -2.35290 0.009314
tau_ind5_4 1.589492 0.251073 6.33079 1.220e-10
zeta_ind14 1.350194 0.112189 12.03500 0.000000
tau_ind14_1 -4.737542 0.238185 -19.89015 0.000000
tau_ind14_2 -2.974947 0.193629 -15.36420 0.000000
tau_ind14_3 -1.070327 0.185300 -5.77619 3.821e-09
tau_ind14_4 0.871315 0.194438 4.48120 3.711e-06
zeta_ind15 1.499386 0.099219 15.11182 0.000000
tau_ind15_1 -3.060105 0.224121 -13.65380 0.000000
tau_ind15_2 -0.649792 0.208918 -3.11027 9.3457e-04
tau_ind15_3 1.129426 0.211754 5.33367 4.812e-08
tau_ind15_4 2.842989 0.232726 12.21602 0.000000
zeta_ind17 1.342998 0.095563 14.05348 0.000000
tau_ind17_1 -2.842985 0.208143 -13.65879 0.000000
tau_ind17_2 -0.545497 0.192361 -2.83580 0.002286
tau_ind17_3 1.144270 0.193005 5.92872 1.527e-09
tau_ind17_4 2.976568 0.216581 13.74342 0.000000
gamma_male_1 -0.381870 0.102848 -3.71296 1.0243e-04
gamma_age_1 -0.005543 0.004673 -1.18613 0.117786
gamma_uni_1 -0.348460 0.094122 -3.70223 1.0686e-04
gamma_inc_1 -0.097024 0.021285 -4.55827 2.579e-06
gamma_male_2 0.004889 0.073600 0.06643 0.473516
gamma_age_2 0.012254 0.002481 4.93839 3.939e-07
gamma_uni_2 -0.248042 0.076754 -3.23165 6.1540e-04
gamma_inc_2 -0.020965 0.017643 -1.18834 0.117349
gamma_male_3 -0.214324 0.073198 -2.92802 0.001706
gamma_age_3 -0.003196 0.003174 -1.00678 0.157021
gamma_uni_3 -0.163220 0.073650 -2.21615 0.013341
gamma_inc_3 0.010258 0.012313 0.83311 0.202393
gamma_male_4 0.001762 0.078982 0.02231 0.491099
gamma_age_4 0.009799 0.002411 4.06417 2.410e-05
gamma_uni_4 0.087233 0.084299 1.03480 0.150381
gamma_inc_4 0.043675 0.011070 3.94524 3.986e-05
I'm running an ICLV model with 4 LVs and (currently still) uncorrelated random parameters in the choice equation. The model is in preference space, parameters are normally distributed, cost parameter is mirrored log-normally distributed, so I need to use unconditional draws to simulate marg. WTP. The LVs are interacted with all mean preference weights in the choice equation, i.e. they are included as mean shifters in randcoeff.
Having obtained the model output, I would like to simulate marg. WTP along the range of one specific LV. If an LV has a range of, say, -2 to +2, I would like to simulate the betas (or ratios of betas, i.e. WTP) for a sequence of LV values in this range.
What modification do I need before or after apollo_unconditionals() to do that? My problem is that the LVs shift the mean of the mu-shifted normal distribution of the cost parameter, so would have to be manipulated before extracting the unconditionals. But I'm not sure how to do that.
Many thanks and best wishes
Tobias
#### 1. 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 = "ICLV2-150-mushift",
modelDescr = "ICLV model",
indivID = "respid",
mixing = TRUE,
panelData = TRUE,
nCores = 10,
outputDirectory = "output"
)
# ####
#### 2. LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
source(file.path("data","setup-data.R"))
# ####
#### 3. DEFINE MODEL PARAMETERS ####
apollo_beta <- c(-0.263595890535925, -0.877795850406257, -1.46344729891276, 0.147388444654724, 0.0390812095766384, 0.219709394190709, -0.799789012376286, 0.685112121998949, 0.599680211654783, -0.176523966310319, 0.282894574144486, -2.51201445505734, 0.272036373551889, 0.0332499251950733, 0.451203710652852, 1.34039859475733, 0.168696467734364, -0.108644079732149, -0.184546338358116, -0.167039591246857, 0.678313375901563, 0.00649748980399031, 0.119646775974343, 0.0541048771481104, 0.0765850666280197, 0.0565537759586298, -0.0675482693231369, -0.192130072142295, -0.237721801547889, 0.156275935628932, 0.00923718433670055, 0.0326967198250995, -0.331890474653538, 0.693294720154439, -0.202504153666109, -0.300658809503898, 0.5394520366849, 0.555214600134694, -0.631653069293468, -0.068464225198733, -0.125651236927408, 0.252588730458113, -0.19469515292462, 0.133251994702141, 0.229361171948157, 1.66093931774463, 2.03048033540746, 0.293279477451139, 0.515986679160807, 0.680053263965322, 0.642750908719204, 0.477154626682397, 0.435722886845636, 0.526343128666326, 0.510646610943036, -1.57705514838932, -0.290552787887763, 0.809697406410988, 2.1522460119667, 1.42058118017912, -5.31171851339919, -3.52483934292071, -1.91049361802076, -0.206134415975181, 1.2602718440872, -6.35389961387888, -4.39715559799527, -2.43237174739628, -0.494970265718682, 1.36470741681215, -3.21389797168539, -0.824580919685466, 1.04418211473543, 3.09323687247162, 0.226755311861272, -1.94185361685057, -0.62982791434553, 0.674785926801447, 2.29639678120512, 1.43397042790907, -2.79218775468885, -0.639429324102643, 1.15258899839659, 2.86645611440518, 1.72227910443098, -2.15741593846108, -0.395724020688492, 1.11724537440749, 2.50924138499162, 1.53835872447696, -2.23168426414781, 0.161973349517357, 1.81672559393544, 3.55217647495339, 1.43515909090826, -3.5958166607788, -2.34098849892343, -0.834158438538792, 0.883690753675783, 1.91520822051063, -4.61290441070375, -2.08301736820464, -0.187628692875705, 2.06093742492254, 1.78100004236781, -3.97974220346656, -1.73334229076737, 0.261563511571412, 2.40250140438525, 1.5513010415419, -3.20545693957606, -0.949739610620965, 0.73451895299203, 2.64296875094346, 1.71720636363008, -4.72463223747029, -2.43315456926038, -0.55191231779791, 1.58949186049228, 1.35019405476924, -4.73754166820096, -2.97494711006753, -1.07032680137781, 0.871314665559812, 1.49938566131686, -3.06010487773117, -0.649792040683238, 1.12942579241114, 2.84298872505797, 1.34299775272937, -2.84298457109242, -0.545496586116384, 1.14427011223512, 2.97656792759587, -0.381869679374898, -0.00554298247346097, -0.348459637563478, -0.0970235217691445, 0.00488948909566323, 0.0122537838386344, -0.248041669633993, -0.0209654120298913, -0.214324271969543, -0.00319588917523904, -0.163219773478612, 0.0102583537771804, 0.00176231500356036, 0.0097992195987407, 0.087232621457131, 0.0436750467353999
names(apollo_beta) <- c("mu_altb","mu_altc","mu_steuer","mu_truppe1","mu_truppe2","mu_euro","mu_wehrpf","mu_schirm1","mu_schirm2",
"sigma_altb","sigma_altc","sigma_steuer","sigma_truppe1","sigma_truppe2","sigma_euro","sigma_wehrpf",
"sigma_schirm1","sigma_schirm2",
"lam_altb_1","lam_altc_1","lam_steuer_1","lam_truppe1_1","lam_truppe2_1","lam_euro_1","lam_wehrpf_1","lam_schirm1_1","lam_schirm2_1",
"lam_altb_2","lam_altc_2","lam_steuer_2","lam_truppe1_2","lam_truppe2_2","lam_euro_2","lam_wehrpf_2","lam_schirm1_2","lam_schirm2_2",
"lam_altb_3","lam_altc_3","lam_steuer_3","lam_truppe1_3","lam_truppe2_3","lam_euro_3","lam_wehrpf_3","lam_schirm1_3","lam_schirm2_3",
"lam_altb_4","lam_altc_4","lam_steuer_4","lam_truppe1_4","lam_truppe2_4","lam_euro_4","lam_wehrpf_4","lam_schirm1_4","lam_schirm2_4",
"zeta_ind1" ,"tau_ind1_1" ,"tau_ind1_2" ,"tau_ind1_3" ,"tau_ind1_4",
"zeta_ind2" ,"tau_ind2_1" ,"tau_ind2_2" ,"tau_ind2_3" ,"tau_ind2_4",
"zeta_ind11","tau_ind11_1","tau_ind11_2","tau_ind11_3","tau_ind11_4",
"zeta_ind6" ,"tau_ind6_1" ,"tau_ind6_2" ,"tau_ind6_3" ,"tau_ind6_4",
"zeta_ind8" ,"tau_ind8_1" ,"tau_ind8_2" ,"tau_ind8_3" ,"tau_ind8_4",
"zeta_ind9" ,"tau_ind9_1" ,"tau_ind9_2" ,"tau_ind9_3" ,"tau_ind9_4",
"zeta_ind10","tau_ind10_1","tau_ind10_2","tau_ind10_3","tau_ind10_4",
"zeta_ind12","tau_ind12_1","tau_ind12_2","tau_ind12_3","tau_ind12_4",
"zeta_ind3" ,"tau_ind3_1" ,"tau_ind3_2" ,"tau_ind3_3" ,"tau_ind3_4",
"zeta_ind4" ,"tau_ind4_1" ,"tau_ind4_2" ,"tau_ind4_3" ,"tau_ind4_4",
"zeta_ind7" ,"tau_ind7_1" ,"tau_ind7_2" ,"tau_ind7_3" ,"tau_ind7_4",
"zeta_ind13","tau_ind13_1","tau_ind13_2","tau_ind13_3","tau_ind13_4",
"zeta_ind5" ,"tau_ind5_1" ,"tau_ind5_2" ,"tau_ind5_3" ,"tau_ind5_4",
"zeta_ind14","tau_ind14_1","tau_ind14_2","tau_ind14_3","tau_ind14_4",
"zeta_ind15","tau_ind15_1","tau_ind15_2","tau_ind15_3","tau_ind15_4",
"zeta_ind17","tau_ind17_1","tau_ind17_2","tau_ind17_3","tau_ind17_4",
"gamma_male_1","gamma_age_1","gamma_uni_1","gamma_inc_1",
"gamma_male_2","gamma_age_2","gamma_uni_2","gamma_inc_2",
"gamma_male_3","gamma_age_3","gamma_uni_3","gamma_inc_3",
"gamma_male_4","gamma_age_4","gamma_uni_4","gamma_inc_4")
apollo_fixed = c()
# ####
#### 4. DEFINE RANDOM COMPONENTS ####
### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "sobol",
interNDraws = 150,
# interUnifDraws = c(),
interNormDraws = c("draws_altb","draws_altc","draws_truppe1","draws_truppe2","draws_euro","draws_wehrpf",
"draws_schirm1","draws_schirm2","draws_steuer",
"eta1","eta2","eta3","eta4")
)
### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()
randcoeff[["LV_1"]] = eta1 + gamma_male_1*male + gamma_age_1*RESP_AGE + gamma_uni_1*uni + gamma_inc_1*inc_imputed
randcoeff[["LV_2"]] = eta2 + gamma_male_2*male + gamma_age_2*RESP_AGE + gamma_uni_2*uni + gamma_inc_2*inc_imputed
randcoeff[["LV_3"]] = eta3 + gamma_male_3*male + gamma_age_3*RESP_AGE + gamma_uni_3*uni + gamma_inc_3*inc_imputed
randcoeff[["LV_4"]] = eta4 + gamma_male_4*male + gamma_age_4*RESP_AGE + gamma_uni_4*uni + gamma_inc_4*inc_imputed
randcoeff[["b_steuer"]] = -exp(mu_steuer +lam_steuer_1*randcoeff[["LV_1"]] +lam_steuer_2*randcoeff[["LV_2"]] +lam_steuer_3*randcoeff[["LV_3"]] +lam_steuer_4*randcoeff[["LV_4"]] + sigma_steuer*draws_steuer) -exp(mu_steuer+lam_steuer_1*randcoeff[["LV_1"]] +lam_steuer_2*randcoeff[["LV_2"]] +lam_steuer_3*randcoeff[["LV_3"]] +lam_steuer_4*randcoeff[["LV_4"]])
randcoeff[["b_altb"]] = mu_altb +lam_altb_1*randcoeff[["LV_1"]] +lam_altb_2*randcoeff[["LV_2"]] +lam_altb_3*randcoeff[["LV_3"]] +lam_altb_4*randcoeff[["LV_4"]] + sigma_altb*draws_altb + sigma_altb_steuer*draws_steuer
randcoeff[["b_altc"]] = mu_altc +lam_altc_1*randcoeff[["LV_1"]] +lam_altc_2*randcoeff[["LV_2"]] +lam_altc_3*randcoeff[["LV_3"]] +lam_altc_4*randcoeff[["LV_4"]] + sigma_altc*draws_altc + sigma_altc_steuer*draws_steuer + sigma_altc_altb*draws_altb
randcoeff[["b_schirm1"]] = mu_schirm1 + lam_schirm1_1*randcoeff[["LV_1"]]+lam_schirm1_2*randcoeff[["LV_2"]]+lam_schirm1_3*randcoeff[["LV_3"]]+lam_schirm1_4*randcoeff[["LV_4"]] + sigma_schirm1*draws_schirm1 + sigma_schirm1_steuer*draws_steuer + sigma_schirm1_altb*draws_altb + sigma_schirm1_altc*draws_altc
randcoeff[["b_schirm2"]] = mu_schirm2 + lam_schirm2_1*randcoeff[["LV_1"]]+lam_schirm2_2*randcoeff[["LV_2"]]+lam_schirm2_3*randcoeff[["LV_3"]]+lam_schirm2_4*randcoeff[["LV_4"]] + sigma_schirm2*draws_schirm2 + sigma_schirm2_steuer*draws_steuer + sigma_schirm2_altb*draws_altb + sigma_schirm2_altc*draws_altc + sigma_schirm2_schirm1*draws_schirm1
randcoeff[["b_truppe1"]] = mu_truppe1 + lam_truppe1_1*randcoeff[["LV_1"]]+lam_truppe1_2*randcoeff[["LV_2"]]+lam_truppe1_3*randcoeff[["LV_3"]]+lam_truppe1_4*randcoeff[["LV_4"]] + sigma_truppe1*draws_truppe1 + sigma_truppe1_steuer*draws_steuer + sigma_truppe1_altb*draws_altb + sigma_truppe1_altc*draws_altc + sigma_truppe1_schirm1*draws_schirm1 + sigma_truppe1_schirm2*draws_schirm2
randcoeff[["b_truppe2"]] = mu_truppe2 + lam_truppe2_1*randcoeff[["LV_1"]]+lam_truppe2_2*randcoeff[["LV_2"]]+lam_truppe2_3*randcoeff[["LV_3"]]+lam_truppe2_4*randcoeff[["LV_4"]] + sigma_truppe2*draws_truppe2 + sigma_truppe2_steuer*draws_steuer + sigma_truppe2_altb*draws_altb + sigma_truppe2_altc*draws_altc + sigma_truppe2_schirm1*draws_schirm1 + sigma_truppe2_schirm2*draws_schirm2 + sigma_truppe2_truppe1*draws_truppe1
randcoeff[["b_euro"]] = mu_euro + lam_euro_1*randcoeff[["LV_1"]] +lam_euro_2*randcoeff[["LV_2"]] +lam_euro_3*randcoeff[["LV_3"]] +lam_euro_4*randcoeff[["LV_4"]] + sigma_euro*draws_euro + sigma_euro_steuer*draws_steuer + sigma_euro_altb*draws_altb + sigma_euro_altc*draws_altc + sigma_euro_schirm1*draws_schirm1 + sigma_euro_schirm2*draws_schirm2 + sigma_euro_truppe1*draws_truppe1 + sigma_euro_truppe2*draws_truppe2
randcoeff[["b_wehrpf"]] = mu_wehrpf + lam_wehrpf_1*randcoeff[["LV_1"]] +lam_wehrpf_2*randcoeff[["LV_2"]] +lam_wehrpf_3*randcoeff[["LV_3"]] +lam_wehrpf_4*randcoeff[["LV_4"]]+ sigma_wehrpf*draws_wehrpf + sigma_wehrpf_steuer*draws_steuer + sigma_wehrpf_altb*draws_altb + sigma_wehrpf_altc*draws_altc + sigma_wehrpf_schirm1*draws_schirm1 + sigma_wehrpf_schirm2*draws_schirm2 + sigma_wehrpf_truppe1*draws_truppe1 + sigma_wehrpf_truppe2*draws_truppe2 + sigma_wehrpf_euro*draws_euro
return(randcoeff)
}
# ####
#### 5. GROUP AND VALIDATE INPUTS ####
apollo_inputs = apollo_validateInputs()
# ####
#### 6. 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()
### List of utilities: these must use the same names as in mnl_settings, order is irrelevant
V = list()
V[['sq']] = b_steuer*steuer.A + b_truppe1*truppe1.A + b_truppe2*truppe2.A + b_euro*euro.A + b_wehrpf*wehrpf.A + b_schirm1*schirm1.A + b_schirm2*schirm2.A
V[['alt2']] = b_steuer*steuer.B + b_altb + b_truppe1*truppe1.B + b_truppe2*truppe2.B + b_euro*euro.B + b_wehrpf*wehrpf.B + b_schirm1*schirm1.B + b_schirm2*schirm2.B
V[['alt3']] = b_steuer*steuer.C + b_altc + b_truppe1*truppe1.C + b_truppe2*truppe2.C + b_euro*euro.C + b_wehrpf*wehrpf.C + b_schirm1*schirm1.C + b_schirm2*schirm2.C
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(sq=1, alt2=2, alt3=3),
avail = 1,
choiceVar = choice,
V = V
)
### Compute probabilities for MNL model component
P[["choice"]] = apollo_mnl(mnl_settings, functionality)
### Likelihood of indicators
ol_settings1_1 = list(outcomeOrdered = r15_1,
V = zeta_ind1*LV_1,
tau = list(tau_ind1_1, tau_ind1_2, tau_ind1_3, tau_ind1_4),
rows = (round==1))
ol_settings1_2 = list(outcomeOrdered = r15_2,
V = zeta_ind2*LV_1,
tau = list(tau_ind2_1, tau_ind2_2, tau_ind2_3, tau_ind2_4),
rows = (round==1))
ol_settings1_3 = list(outcomeOrdered = r15_11,
V = zeta_ind11*LV_1,
tau = list(tau_ind11_1, tau_ind11_2, tau_ind11_3, tau_ind11_4),
rows = (round==1))
P[["indic_1_1"]] = apollo_ol(ol_settings1_1, functionality)
P[["indic_1_2"]] = apollo_ol(ol_settings1_2, functionality)
P[["indic_1_3"]] = apollo_ol(ol_settings1_3, functionality)
ol_settings2_1 = list(outcomeOrdered = r15_6,
V = zeta_ind6*LV_2,
tau = list(tau_ind6_1, tau_ind6_2, tau_ind6_3, tau_ind6_4),
rows = (round==1))
ol_settings2_2 = list(outcomeOrdered = r15_8,
V = zeta_ind8*LV_2,
tau = list(tau_ind8_1, tau_ind8_2, tau_ind8_3, tau_ind8_4),
rows = (round==1))
ol_settings2_3 = list(outcomeOrdered = r15_9,
V = zeta_ind9*LV_2,
tau = list(tau_ind9_1, tau_ind9_2, tau_ind9_3, tau_ind9_4),
rows = (round==1))
ol_settings2_4 = list(outcomeOrdered = r15_10,
V = zeta_ind10*LV_2,
tau = list(tau_ind10_1, tau_ind10_2, tau_ind10_3, tau_ind10_4),
rows = (round==1))
ol_settings2_5 = list(outcomeOrdered = r15_12,
V = zeta_ind12*LV_2,
tau = list(tau_ind12_1, tau_ind12_2, tau_ind12_3, tau_ind12_4),
rows = (round==1))
P[["indic_2_1"]] = apollo_ol(ol_settings2_1, functionality)
P[["indic_2_2"]] = apollo_ol(ol_settings2_2, functionality)
P[["indic_2_3"]] = apollo_ol(ol_settings2_3, functionality)
P[["indic_2_4"]] = apollo_ol(ol_settings2_4, functionality)
P[["indic_2_5"]] = apollo_ol(ol_settings2_5, functionality)
ol_settings3_1 = list(outcomeOrdered = r15_3,
V = zeta_ind3*LV_3,
tau = list(tau_ind3_1, tau_ind3_2, tau_ind3_3, tau_ind3_4),
rows = (round==1))
ol_settings3_2 = list(outcomeOrdered = r15_4,
V = zeta_ind4*LV_3,
tau = list(tau_ind4_1, tau_ind4_2, tau_ind4_3, tau_ind4_4),
rows = (round==1))
ol_settings3_3 = list(outcomeOrdered = r15_7,
V = zeta_ind7*LV_3,
tau = list(tau_ind7_1, tau_ind7_2, tau_ind7_3, tau_ind7_4),
rows = (round==1))
ol_settings3_4 = list(outcomeOrdered = r15_13,
V = zeta_ind13*LV_3,
tau = list(tau_ind13_1, tau_ind13_2, tau_ind13_3, tau_ind13_4),
rows = (round==1))
P[["indic_3_1"]] = apollo_ol(ol_settings3_1, functionality)
P[["indic_3_2"]] = apollo_ol(ol_settings3_2, functionality)
P[["indic_3_3"]] = apollo_ol(ol_settings3_3, functionality)
P[["indic_3_4"]] = apollo_ol(ol_settings3_4, functionality)
ol_settings4_1 = list(outcomeOrdered = r15_5,
V = zeta_ind5*LV_3,
tau = list(tau_ind5_1, tau_ind5_2, tau_ind5_3, tau_ind5_4),
rows = (round==1))
ol_settings4_2 = list(outcomeOrdered = r15_14,
V = zeta_ind14*LV_3,
tau = list(tau_ind14_1, tau_ind14_2, tau_ind14_3, tau_ind14_4),
rows = (round==1))
ol_settings4_3 = list(outcomeOrdered = r15_15,
V = zeta_ind15*LV_3,
tau = list(tau_ind15_1, tau_ind15_2, tau_ind15_3, tau_ind15_4),
rows = (round==1))
ol_settings4_4 = list(outcomeOrdered = r15_17,
V = zeta_ind17*LV_3,
tau = list(tau_ind17_1, tau_ind17_2, tau_ind17_3, tau_ind17_4),
rows = (round==1))
P[["indic_4_1"]] = apollo_ol(ol_settings4_1, functionality)
P[["indic_4_2"]] = apollo_ol(ol_settings4_2, functionality)
P[["indic_4_3"]] = apollo_ol(ol_settings4_3, functionality)
P[["indic_4_4"]] = apollo_ol(ol_settings4_4, 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)
}
# ####
#### 7. MODEL ESTIMATION ####
estimate_settings = list(hessianRoutine="none")
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs) # , estimate_settings)
# #####
#### 8. MODEL OUTPUTS ####
apollo_modelOutput(model, modelOutput_settings = list(printPVal=TRUE, printClassical=FALSE))
# apollo_saveOutput(model)
# ####
Model name : ICLV2-150-mushift
Model description : ICLV model
Model run at : 2023-04-17 20:09:06
Estimation method : bfgs
Model diagnosis : successful convergence
Number of individuals : 1808
Number of rows in database : 14464
Number of modelled outcomes : 43392
choice : 14464
indic_1_1 : 1808
indic_1_2 : 1808
indic_1_3 : 1808
indic_2_1 : 1808
indic_2_2 : 1808
indic_2_3 : 1808
indic_2_4 : 1808
indic_2_5 : 1808
indic_3_1 : 1808
indic_3_2 : 1808
indic_3_3 : 1808
indic_3_4 : 1808
indic_4_1 : 1808
indic_4_2 : 1808
indic_4_3 : 1808
indic_4_4 : 1808
Number of cores used : 10
Number of inter-individual draws : 150 (sobol)
LL(start) : -50531.78
LL (whole model) at equal shares, LL(0) : -62448.15
LL (whole model) at observed shares, LL(C) : -57974.32
LL(final, whole model) : -50188.01
Rho-squared vs equal shares : 0.1963
Adj.Rho-squared vs equal shares : 0.1939
Rho-squared vs observed shares : 0.1343
Adj.Rho-squared vs observed shares : 0.1317
AIC : 100676
BIC : 101812.9
LL(0,choice) : -15890.33
LL(final,choice) : -10493.81
LL(0,indic_1_1) : -2909.86
LL(final,indic_1_1) : -2751.09
LL(0,indic_1_2) : -2909.86
LL(final,indic_1_2) : -2551.27
LL(0,indic_1_3) : -2909.86
LL(final,indic_1_3) : -2248.66
LL(0,indic_2_1) : -2909.86
LL(final,indic_2_1) : -2606.34
LL(0,indic_2_2) : -2909.86
LL(final,indic_2_2) : -2757.72
LL(0,indic_2_3) : -2909.86
LL(final,indic_2_3) : -2694.73
LL(0,indic_2_4) : -2909.86
LL(final,indic_2_4) : -2820.87
LL(0,indic_2_5) : -2909.86
LL(final,indic_2_5) : -2731.46
LL(0,indic_3_1) : -2909.86
LL(final,indic_3_1) : -2682.81
LL(0,indic_3_2) : -2909.86
LL(final,indic_3_2) : -2662.6
LL(0,indic_3_3) : -2909.86
LL(final,indic_3_3) : -2677.13
LL(0,indic_3_4) : -2909.86
LL(final,indic_3_4) : -2691
LL(0,indic_4_1) : -2909.86
LL(final,indic_4_1) : -2616.53
LL(0,indic_4_2) : -2909.86
LL(final,indic_4_2) : -2472.84
LL(0,indic_4_3) : -2909.86
LL(final,indic_4_3) : -2627.11
LL(0,indic_4_4) : -2909.86
LL(final,indic_4_4) : -2612.95
Estimated parameters : 150
Time taken (hh:mm:ss) : 29:32:19.43
pre-estimation : 01:03:33.49
estimation : 03:29:49.02
post-estimation : 24:58:56.92
Iterations : 162
Min abs eigenvalue of Hessian : 2.222011
Unconstrained optimisation.
These outputs have had the scaling used in estimation applied to them.
Estimates:
Estimate Rob.s.e. Rob.t.rat.(0) p(1-sided)
mu_altb -0.263596 0.322610 -0.81707 0.206943
mu_altc -0.877796 0.350521 -2.50426 0.006135
mu_steuer -1.463447 0.142324 -10.28250 0.000000
mu_truppe1 0.147388 0.123559 1.19285 0.116463
mu_truppe2 0.039081 0.146140 0.26742 0.394572
mu_euro 0.219709 0.128581 1.70872 0.043751
mu_wehrpf -0.799789 0.166186 -4.81262 7.448e-07
mu_schirm1 0.685112 0.136121 5.03311 2.413e-07
mu_schirm2 0.599680 0.167164 3.58738 1.6701e-04
sigma_altb -0.176524 0.127084 -1.38903 0.082412
sigma_altc 0.282895 0.161680 1.74972 0.040083
sigma_steuer -2.512014 0.280388 -8.95906 0.000000
sigma_truppe1 0.272036 0.095349 2.85304 0.002165
sigma_truppe2 0.033250 0.145226 0.22895 0.409453
sigma_euro 0.451204 0.116386 3.87679 5.292e-05
sigma_wehrpf 1.340399 0.119364 11.22946 0.000000
sigma_schirm1 0.168696 0.118787 1.42016 0.077780
sigma_schirm2 -0.108644 0.122922 -0.88385 0.188389
lam_altb_1 -0.184546 0.194622 -0.94823 0.171506
lam_altc_1 -0.167040 0.213478 -0.78247 0.216970
lam_steuer_1 0.678313 0.159003 4.26605 9.948e-06
lam_truppe1_1 0.006497 0.069511 0.09347 0.462764
lam_truppe2_1 0.119647 0.094550 1.26544 0.102858
lam_euro_1 0.054105 0.086263 0.62721 0.265260
lam_wehrpf_1 0.076585 0.112944 0.67808 0.248860
lam_schirm1_1 0.056554 0.085870 0.65860 0.255077
lam_schirm2_1 -0.067548 0.095411 -0.70797 0.239482
lam_altb_2 -0.192130 0.166337 -1.15506 0.124032
lam_altc_2 -0.237722 0.172991 -1.37418 0.084692
lam_steuer_2 0.156276 0.181187 0.86251 0.194203
lam_truppe1_2 0.009237 0.076618 0.12056 0.452019
lam_truppe2_2 0.032697 0.085390 0.38291 0.350893
lam_euro_2 -0.331890 0.070897 -4.68133 1.425e-06
lam_wehrpf_2 0.693295 0.104394 6.64116 1.556e-11
lam_schirm1_2 -0.202504 0.085721 -2.36235 0.009080
lam_schirm2_2 -0.300659 0.093445 -3.21748 6.4660e-04
lam_altb_3 0.539452 0.176056 3.06409 0.001092
lam_altc_3 0.555215 0.189734 2.92629 0.001715
lam_steuer_3 -0.631653 0.121308 -5.20703 9.594e-08
lam_truppe1_3 -0.068464 0.070571 -0.97015 0.165985
lam_truppe2_3 -0.125651 0.086002 -1.46103 0.072004
lam_euro_3 0.252589 0.080352 3.14354 8.3459e-04
lam_wehrpf_3 -0.194695 0.097576 -1.99532 0.023004
lam_schirm1_3 0.133252 0.084407 1.57868 0.057205
lam_schirm2_3 0.229361 0.092677 2.47484 0.006665
lam_altb_4 1.660939 0.179290 9.26396 0.000000
lam_altc_4 2.030480 0.184142 11.02669 0.000000
lam_steuer_4 0.293279 0.084855 3.45624 2.7389e-04
lam_truppe1_4 0.515987 0.073632 7.00760 1.212e-12
lam_truppe2_4 0.680053 0.087975 7.73004 5.329e-15
lam_euro_4 0.642751 0.083012 7.74285 4.885e-15
lam_wehrpf_4 0.477155 0.104831 4.55165 2.661e-06
lam_schirm1_4 0.435723 0.091444 4.76493 9.446e-07
lam_schirm2_4 0.526343 0.092576 5.68551 6.521e-09
zeta_ind1 0.510647 0.082548 6.18606 3.084e-10
tau_ind1_1 -1.577055 0.197291 -7.99353 6.661e-16
tau_ind1_2 -0.290553 0.180448 -1.61017 0.053680
tau_ind1_3 0.809697 0.173562 4.66517 1.542e-06
tau_ind1_4 2.152246 0.179871 11.96550 0.000000
zeta_ind2 1.420581 0.139055 10.21599 0.000000
tau_ind2_1 -5.311719 0.486244 -10.92397 0.000000
tau_ind2_2 -3.524839 0.431423 -8.17026 1.110e-16
tau_ind2_3 -1.910494 0.397014 -4.81216 7.465e-07
tau_ind2_4 -0.206134 0.372273 -0.55372 0.289886
zeta_ind11 1.260272 0.123581 10.19798 0.000000
tau_ind11_1 -6.353900 0.401280 -15.83410 0.000000
tau_ind11_2 -4.397156 0.319116 -13.77918 0.000000
tau_ind11_3 -2.432372 0.296281 -8.20968 1.110e-16
tau_ind11_4 -0.494970 0.298544 -1.65795 0.048664
zeta_ind6 1.364707 0.095403 14.30467 0.000000
tau_ind6_1 -3.213898 0.219997 -14.60883 0.000000
tau_ind6_2 -0.824581 0.177181 -4.65390 1.629e-06
tau_ind6_3 1.044182 0.176415 5.91889 1.621e-09
tau_ind6_4 3.093237 0.194281 15.92146 0.000000
zeta_ind8 0.226755 0.073526 3.08401 0.001021
tau_ind8_1 -1.941854 0.078447 -24.75370 0.000000
tau_ind8_2 -0.629828 0.058067 -10.84657 0.000000
tau_ind8_3 0.674786 0.058309 11.57261 0.000000
tau_ind8_4 2.296397 0.084224 27.26534 0.000000
zeta_ind9 1.433970 0.092071 15.57461 0.000000
tau_ind9_1 -2.792188 0.210007 -13.29570 0.000000
tau_ind9_2 -0.639429 0.184246 -3.47051 2.5974e-04
tau_ind9_3 1.152589 0.189416 6.08495 5.826e-10
tau_ind9_4 2.866456 0.204469 14.01901 0.000000
zeta_ind10 1.722279 0.102342 16.82870 0.000000
tau_ind10_1 -2.157416 0.226555 -9.52272 0.000000
tau_ind10_2 -0.395724 0.217005 -1.82357 0.034108
tau_ind10_3 1.117245 0.222647 5.01801 2.610e-07
tau_ind10_4 2.509241 0.236236 10.62175 0.000000
zeta_ind12 1.538359 0.094649 16.25334 0.000000
tau_ind12_1 -2.231684 0.213608 -10.44756 0.000000
tau_ind12_2 0.161973 0.193543 0.83689 0.201328
tau_ind12_3 1.816726 0.192745 9.42556 0.000000
tau_ind12_4 3.552176 0.212505 16.71572 0.000000
zeta_ind3 1.435159 0.104581 13.72299 0.000000
tau_ind3_1 -3.595817 0.225897 -15.91791 0.000000
tau_ind3_2 -2.340988 0.210770 -11.10684 0.000000
tau_ind3_3 -0.834158 0.204605 -4.07692 2.282e-05
tau_ind3_4 0.883691 0.205671 4.29662 8.671e-06
zeta_ind4 1.915208 0.124931 15.33008 0.000000
tau_ind4_1 -4.612904 0.339145 -13.60158 0.000000
tau_ind4_2 -2.083017 0.295153 -7.05742 8.481e-13
tau_ind4_3 -0.187629 0.274710 -0.68301 0.247301
tau_ind4_4 2.060937 0.270455 7.62026 1.266e-14
zeta_ind7 1.781000 0.111435 15.98247 0.000000
tau_ind7_1 -3.979742 0.274446 -14.50103 0.000000
tau_ind7_2 -1.733342 0.254814 -6.80239 5.145e-12
tau_ind7_3 0.261564 0.250034 1.04611 0.147755
tau_ind7_4 2.402501 0.260381 9.22686 0.000000
zeta_ind13 1.551301 0.100940 15.36856 0.000000
tau_ind13_1 -3.205457 0.242049 -13.24303 0.000000
tau_ind13_2 -0.949740 0.224225 -4.23566 1.139e-05
tau_ind13_3 0.734519 0.220126 3.33681 4.2373e-04
tau_ind13_4 2.642969 0.235961 11.20088 0.000000
zeta_ind5 1.717206 0.130746 13.13389 0.000000
tau_ind5_1 -4.724632 0.272766 -17.32119 0.000000
tau_ind5_2 -2.433155 0.235966 -10.31148 0.000000
tau_ind5_3 -0.551912 0.234566 -2.35290 0.009314
tau_ind5_4 1.589492 0.251073 6.33079 1.220e-10
zeta_ind14 1.350194 0.112189 12.03500 0.000000
tau_ind14_1 -4.737542 0.238185 -19.89015 0.000000
tau_ind14_2 -2.974947 0.193629 -15.36420 0.000000
tau_ind14_3 -1.070327 0.185300 -5.77619 3.821e-09
tau_ind14_4 0.871315 0.194438 4.48120 3.711e-06
zeta_ind15 1.499386 0.099219 15.11182 0.000000
tau_ind15_1 -3.060105 0.224121 -13.65380 0.000000
tau_ind15_2 -0.649792 0.208918 -3.11027 9.3457e-04
tau_ind15_3 1.129426 0.211754 5.33367 4.812e-08
tau_ind15_4 2.842989 0.232726 12.21602 0.000000
zeta_ind17 1.342998 0.095563 14.05348 0.000000
tau_ind17_1 -2.842985 0.208143 -13.65879 0.000000
tau_ind17_2 -0.545497 0.192361 -2.83580 0.002286
tau_ind17_3 1.144270 0.193005 5.92872 1.527e-09
tau_ind17_4 2.976568 0.216581 13.74342 0.000000
gamma_male_1 -0.381870 0.102848 -3.71296 1.0243e-04
gamma_age_1 -0.005543 0.004673 -1.18613 0.117786
gamma_uni_1 -0.348460 0.094122 -3.70223 1.0686e-04
gamma_inc_1 -0.097024 0.021285 -4.55827 2.579e-06
gamma_male_2 0.004889 0.073600 0.06643 0.473516
gamma_age_2 0.012254 0.002481 4.93839 3.939e-07
gamma_uni_2 -0.248042 0.076754 -3.23165 6.1540e-04
gamma_inc_2 -0.020965 0.017643 -1.18834 0.117349
gamma_male_3 -0.214324 0.073198 -2.92802 0.001706
gamma_age_3 -0.003196 0.003174 -1.00678 0.157021
gamma_uni_3 -0.163220 0.073650 -2.21615 0.013341
gamma_inc_3 0.010258 0.012313 0.83311 0.202393
gamma_male_4 0.001762 0.078982 0.02231 0.491099
gamma_age_4 0.009799 0.002411 4.06417 2.410e-05
gamma_uni_4 0.087233 0.084299 1.03480 0.150381
gamma_inc_4 0.043675 0.011070 3.94524 3.986e-05