Once again, thank you for your efforts in building and supporting the Apollo Software.
I observed an issue while trying to accounting for scale difference in my estimation. My dataset consists of three experimental groups in food choice experiment. Two of the groups were treated in information and the control group received no information. My aim is to estimate scale parameters for the treated groups relative to the control for which I fixed the scale to 1. I observe that when I fix the scale control group to 1 and estimated for others, I get the following values :
Estimate Rob.std.err.
price -4.669 0.221
sigma_price_inter -4.146 1.203
afla -5.449 0.994
sigma_afla_inter 5.742 1.218
nafdac 1.657 0.527
sigma_nafdac_inter -5.900 0.978
untested 2.471 0.542
sigma_untested_inter 1.573 0.322
mu_control 1.000 NA
mu_FT -0.445 0.103
mu_ST -0.466 0.100
sigma_afla_nafdac -0.632 0.341
sigma_afla_untested -0.103 0.546
sigma_nafdac_untested 1.299 0.399
sigma_afla_price 6.931 1.065
sigma_nafdac_price -1.340 0.265
sigma_untested_price -2.970 0.604
However, when I normalize one of the treated groups and estimate the scale parameters for the control and the other treated group, I get the following values:
Estimate Std.err.
price -4.536 0.119
sigma_price_inter -3.304 0.378
afla 8.997 0.849
sigma_afla_inter -2.034 0.343
nafdac 6.887 0.684
sigma_nafdac_inter -0.958 0.268
untested 4.549 0.514
sigma_untested_inter -0.322 0.422
mu_control 1.223 0.157
mu_FT 1.363 0.196
mu_ST 1.000 NA
sigma_afla_nafdac 0.535 0.259
sigma_afla_untested 2.244 0.363
sigma_nafdac_untested 0.609 0.279
sigma_afla_price 4.755 0.557
sigma_nafdac_price 1.451 0.276
sigma_untested_price -1.018 0.368
My concern is:
In the first output, the estimated scale parameters were negative and apparently below 0.5 but in the second output, the values seem to align with the normal pattern of positive scale parameters I am used to
My experience with values of scale parameters of this nature is that the are usually a positive value either above 1 or below 1. Please, I need your advise on what may be responsible for such noticeable difference in the values of scale parameters depending on which group I normalize. Out of curiosity, I will like to ask if it has anything to do with whether I specified the distribution of price parameter as negative log-uniform?
Please, find below my full code. Thank you
Code: Select all
# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS ####
# ################################################################# #
### Clear memory
rm(list = ls())
### Load Apollo library
library(apollo)
library(lmtest)
library(dplyr)
### Initialise code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName = "MMNL_Pref_Pooled_SBA_LU_Scaled_TE_September_2024_04_B",
modelDescr = "Mixed logit model, Pooled Log Uniform Price, Scaled ",
indivID = "id",
mixing = TRUE,
nCores = 7,
analyticGrad = TRUE, # Needs to be set explicitly for models with inter-intra draws (requires extra RAM).
outputDirectory = "output"
)
# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #
### Loading data from package
### if data is to be loaded from a file (e.g. called data.csv),
### the code would be: database = read.csv("data.csv",header=TRUE)
apollo_database = read.csv(file = file.choose())
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(
price = -5, sigma_price_inter = 0,
afla = 0, sigma_afla_inter = 0,
nafdac = 0, sigma_nafdac_inter = 0,
untested = 0, sigma_untested_inter = 0,
fafla = 0, fnafdac = 0, funtested = 0,
safla = 0, snafdac = 0, suntested = 0,
#For Scale
mu_control = 1,
mu_FT = 1,
mu_ST = 1,
#Correlations in parameters
sigma_afla_nafdac = 0, sigma_afla_untested = 0, sigma_nafdac_untested = 0,
sigma_afla_price = 0, sigma_nafdac_price = 0, sigma_untested_price = 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("mu_control")
### Overwrite beta starting values
#apollo_readBeta(apollo_beta, apollo_fixed, "MMNL_Pref_Pooled_LU_Scaled_TE_September_2024_04_A", overwriteFixed = FALSE)
# ################################################################# #
#### DEFINE RANDOM COMPONENTS ####
# ################################################################# #
### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "sobol",
interNDraws = 500,
interUnifDraws = c("unif_draws_price_inter"),
interNormDraws = c(
##Draws for alternative-specific parameters for the three groups
"draws_afla_inter","draws_nafdac_inter", "draws_untested_inter",
#Draw for correlation among price parameters
"draws_afla_price", "draws_nafdac_price",
"draws_afla_nprice", "draws_nafdac_nprice", "draws_untested_price",
#Draws for correlation among alternative-specific parameters
"draws_afla_nafdac", "draws_afla_untested", "draws_nafdac_untested"
)
)
### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()
# Log-Uniform distribution
randcoeff[["b_price"]] = -exp(price + sigma_price_inter * unif_draws_price_inter)
# Normal distribution
#randcoeff[["b_price"]] = (price + sigma_price_inter * unif_draws_price_inter)
randcoeff[["b_afla"]] = (afla + sigma_afla_inter*draws_afla_inter + sigma_afla_price*draws_afla_price)
randcoeff[["b_nafdac"]] = (nafdac + sigma_nafdac_inter*draws_nafdac_inter +
sigma_afla_nafdac*draws_afla_nafdac +
sigma_nafdac_price*draws_nafdac_price)
randcoeff[["b_untested"]] = (untested + sigma_untested_inter*draws_untested_inter +
sigma_afla_untested*draws_afla_untested + sigma_nafdac_untested*draws_nafdac_untested +
sigma_untested_price*draws_untested_price)
return(randcoeff)
}
# ################################################################# #
#### 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[["alt1"]] = (b_price*Price1 + b_afla*afla1 + fafla*first_treated_afla1 + safla*second_treated_afla1)
V[["alt2"]] = (b_price*Price2 + b_nafdac*nafdac2 + fnafdac*first_treated_nafdac2 + snafdac*second_treated_nafdac2)
V[["alt3"]] = (b_price*Price3 + b_untested*untested3 + funtested*first_treated_untested3 + suntested*second_treated_untested3)
V[["alt4"]] = 0
### Define settings for MNL model component
# mnl_settings = list(
# alternatives = c(alt1=1, alt2=2, alt3=3, alt4=4),
# avail = list(alt1=1, alt2=1, alt3=1, alt4=1),
# choiceVar = Choice,
# utilities = V
# )
#
### Compute probabilities using MNL model
### Compute probabilities for the ST using MNL model
mnl_settings_ST = list(
alternatives = c(alt1=1, alt2=2, alt3=3, alt4=4),
avail = list(alt1=1, alt2=1, alt3=1, alt4=1),
choiceVar = Choice,
utilities = list(alt1 = mu_ST*V[["alt1"]],
alt2 = mu_ST*V[["alt2"]],
alt3 = mu_ST*V[["alt3"]],
alt4 = mu_ST*V[["alt4"]]),
rows = (group==3)
)
P[["ST"]] = apollo_mnl(mnl_settings_ST, functionality)
### Compute probabilities for the FT using MNL model
mnl_settings_FT = list(
alternatives = c(alt1=1, alt2=2, alt3=3, alt4=4),
avail = list(alt1=1, alt2=1, alt3=1, alt4=1),
choiceVar = Choice,
utilities = list(alt1 = mu_FT*V[["alt1"]],
alt2 = mu_FT*V[["alt2"]],
alt3 = mu_FT*V[["alt3"]],
alt4 = mu_FT*V[["alt4"]]),
rows = (group==2)
)
P[["FT"]] = apollo_mnl(mnl_settings_FT, functionality)
### Compute probabilities for the control using MNL model
mnl_settings_control = list(
alternatives = c(alt1=1, alt2=2, alt3=3, alt4=4),
avail = list(alt1=1, alt2=1, alt3=1, alt4=1),
choiceVar = Choice,
utilities = list(alt1 = mu_control*V[["alt1"]],
alt2 = mu_control*V[["alt2"]],
alt3 = mu_control*V[["alt3"]],
alt4 = mu_control*V[["alt4"]]),
rows = (group==1)
)
P[["Control"]] = apollo_mnl(mnl_settings_control, functionality)
#
# ### Combined model
P = apollo_combineModels(P, apollo_inputs, functionality)
#P[["model"]] = apollo_mnl(mnl_settings, 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)
}
# ################################################################# #
#### MODEL ESTIMATION ####
# ################################################################# #
model = apollo_estimate(apollo_beta, apollo_fixed,apollo_probabilities, apollo_inputs, estimate_settings=list(maxIterations=400))
# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #
modelOutput_settings = list(
printPVal =2,
printClassical = FALSE
)
apollo_modelOutput(model, modelOutput_settings)
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO FILE, using model name) ----
# ----------------------------------------------------------------- #
apollo_saveOutput(model, modelOutput_settings)