I am working on a DCE with a willingness to accept setting. So instead of price there is a hypothetical financial remuneration "b_rmn" . The problem is that I get a negative and significant coefficient for this attribute and I would expect a positive sign. I would expect a positive sign for "b_dc" as it refers to offered discounts but my main concern is not the coefficient for remuneration
This is the code that I am using in the MNL model:
Code: Select all
### Clear memory
rm(list = ls())
### Load Apollo library
library(apollo)
### Initialise code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName = "MNL_SC_nwsm",
modelDescr = "Simple MNL model on SP data",
indivID = "ID",
outputDirectory = "output"
)
# with ID, you tell R, what is the ID variable
# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #
### Loading data from package
database <- readRDS("C:\\Users\\posso-gonzalez.n\\Documents\\PhD\\Ch2\\jointdataSC.rds")
class(database$Time)
database$Time <- as.numeric(database$Time)
database <- database %>%
filter(Time >= 300)
database <- database %>%
filter(AgeGr != 1)
database$spd_0 <- as.integer(database$spd_0)
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(asc = 0,
b_vhm = 0,
b_elp = 0,
b_cpo = 0,
b_rn = 0,
b_dc = 0,
b_flx =0,
b_spd =0,
b_exm =0,
b_rmn =0
)
### 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()
# ################################################################# #
#### GROUP AND VALIDATE INPUTS ####
# ################################################################# #
apollo_inputs = apollo_validateInputs()
# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION ####
# ################################################################# #
apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
### Function initialisation: do not change the following three commands
### 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[["alt0"]] = b_spd * spd_0
V[["alt1"]] = asc + b_vhm * (cnt_1 == "vh_m") + b_elp * (cnt_1 == "el_p") + b_cpo * (cnt_1 == "cp_o") + b_rn * (adv_1 == "50_rn") + b_dc * (adv_1 == "10_dc") + b_flx * (adv_1 == "flx") + b_spd * spd_1 + b_exm * exm_1 + b_rmn * rmn_1
V[["alt2"]] = asc + b_vhm * (cnt_2 == "vh_m") + b_elp * (cnt_2 == "el_p") + b_cpo * (cnt_2 == "cp_o") + b_rn * (adv_2 == "50_rn") + b_dc * (adv_2 == "20_dc") + b_flx * (adv_2 == "flx") + b_spd * spd_2 + b_exm * exm_2 + b_rmn * rmn_2
#####Im here######
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(alt0=0, alt1=1, alt2=2), #choice coding of the variable
avail = list(alt0=1, alt1=1, alt2=1), ####check if 1 means the choice is available
choiceVar = choice,
utilities = V
)
### Compute probabilities using MNL model
P[["model"]] = apollo_mnl(mnl_settings, 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)
return(P)
}
# ################################################################# #
#### 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)
### Print outputs of additional diagnostics to new output file (remember to close file writing when complete)
apollo_sink()
Code: Select all
Model name : MNL_SC_nwsm
Model description : Simple MNL model on SP data
Model run at : 2025-12-31 11:23:20.252316
Estimation method : bgw
Estimation diagnosis : Relative function convergence
Optimisation diagnosis : Maximum found
hessian properties : Negative definite
maximum eigenvalue : -202.913671
reciprocal of condition number : 1.73622e-05
Number of individuals : 2357
Number of rows in database : 14142
Number of modelled outcomes : 14142
Number of cores used : 1
Model without mixing
LL(start) : -15536.57
LL at equal shares, LL(0) : -15536.57
LL at observed shares, LL(C) : -15123.98
LL(final) : -14941.03
Rho-squared vs equal shares : 0.0383
Adj.Rho-squared vs equal shares : 0.0377
Rho-squared vs observed shares : 0.0121
Adj.Rho-squared vs observed shares : 0.0116
AIC : 29902.07
BIC : 29977.64
Estimated parameters : 10
Time taken (hh:mm:ss) : 00:00:4.75
pre-estimation : 00:00:1.93
estimation : 00:00:0.59
post-estimation : 00:00:2.23
Iterations : 6
Unconstrained optimisation.
Estimates:
Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0)
asc 0.075520 0.052417 1.4408 0.061428 1.2294
b_vhm 0.005746 0.037777 0.1521 0.037699 0.1524
b_elp 0.070133 0.035211 1.9918 0.037440 1.8732
b_cpo -0.056804 0.039360 -1.4432 0.036962 -1.5368
b_rn 0.127496 0.033809 3.7711 0.030374 4.1975
b_dc -0.139167 0.046128 -3.0170 0.047752 -2.9144
b_flx 0.095625 0.033794 2.8296 0.030334 3.1524
b_spd 0.010065 5.6020e-04 17.9674 6.0220e-04 16.7144
b_exm 0.117746 0.024568 4.7927 0.025350 4.6448
b_rmn -0.010881 0.001682 -6.4687 0.002042 -5.3279
Overview of choices for MNL model component :
alt0 alt1 alt2
Times available 14142.00 14142.00 14142.00
Times chosen 6280.00 3538.00 4324.00
Percentage chosen overall 44.41 25.02 30.58
Percentage chosen when available 44.41 25.02 30.58
Thanks a lot in advance