Log-likelihood calculation fails at values close to the starting values!
Posted: 16 Jul 2025, 20:45
Hi,
I've been using Apollo for about 5 years now. This is the first time I've encountered the log-likelihood calculation error. I am attempting to estimate a MNL to conduct preliminary analysis on the first wave of DCE respondents collected and get starting values for MXL to be used later. After reading through previous questions on this topic, I attempted many different starting values and setting panelData =F in apollo_control all with the same result. So, I am now at a bit of a loss. I've estimated much more complicated models with much larger data sets without issue which makes me wonder if there is an issue with how my data is set up.
My model code is below and a screen shot of the data is attached for reference.
all attributes enter the model continuously except for the "prov" attribute (insurance provider) which I generate dummy variables for at the beginning of the script.
I appreciate any guidance and input folks can share. Thank you.
Mike
### Clear memory
rm(list = ls())
### Load Apollo library
library(apollo)
### Initialise code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName ="MNL_14july2025",
modelDescr ="NA",
indivID ="access",
seed=1234,
panelData = T
#workInLogs=TRUE
)
# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #
database = read.csv("C:/Users/weirm/Dropbox/Research/slr/analysis/data/choice_dat.csv",header=TRUE) # reads csv files
# create status quo variables
database$sq_1<-database$sq_2<-0
database$sq_3<-1
database$alt1.priv<-as.numeric(database$alt1.prov==2)
database$alt1.both<-as.numeric(database$alt1.prov==3)
database$alt2.priv<-as.numeric(database$alt2.prov==2)
database$alt2.both<-as.numeric(database$alt2.prov==3)
database$alt3.priv<-as.numeric(database$alt3.prov==2)
database$alt3.both<-as.numeric(database$alt3.prov==3)
database<-database[!is.na(database$choice),]
database<-database[order(database$access,database$ques),]
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(
b_prem = -1,
b_cov = 1,
b_ded = -1 ,
b_priv = 1,
b_both = 1,
b_asc=1,
b_100=1)
### 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 ####
# ################################################################# #
# ################################################################# #
#### 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_prem * alt1.premium + b_cov *alt1.cov + b_ded * alt1.deductible+b_priv*alt1.priv+b_both*alt1.both+b_100*ver100
V[['alt2']] = b_prem * alt2.premium + b_cov *alt2.cov + b_ded * alt2.deductible+b_priv*alt2.priv+b_both*alt2.both+b_100*ver100
V[['alt3']] = b_asc * sq_3
## Define settings for MNL model component
mnl_settings = list(
alternatives = c(alt1=1, alt2=2, alt3=3),
avail = list(alt1=1, alt2=1, alt3=1),
choiceVar = choice,
V = 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)
### 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=3000))
# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #
apollo_modelOutput(model)
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO FILE, using model name) ----
# ----------------------------------------------------------------- #
apollo_saveOutput(model)
I've been using Apollo for about 5 years now. This is the first time I've encountered the log-likelihood calculation error. I am attempting to estimate a MNL to conduct preliminary analysis on the first wave of DCE respondents collected and get starting values for MXL to be used later. After reading through previous questions on this topic, I attempted many different starting values and setting panelData =F in apollo_control all with the same result. So, I am now at a bit of a loss. I've estimated much more complicated models with much larger data sets without issue which makes me wonder if there is an issue with how my data is set up.
My model code is below and a screen shot of the data is attached for reference.
all attributes enter the model continuously except for the "prov" attribute (insurance provider) which I generate dummy variables for at the beginning of the script.
I appreciate any guidance and input folks can share. Thank you.
Mike
### Clear memory
rm(list = ls())
### Load Apollo library
library(apollo)
### Initialise code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName ="MNL_14july2025",
modelDescr ="NA",
indivID ="access",
seed=1234,
panelData = T
#workInLogs=TRUE
)
# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #
database = read.csv("C:/Users/weirm/Dropbox/Research/slr/analysis/data/choice_dat.csv",header=TRUE) # reads csv files
# create status quo variables
database$sq_1<-database$sq_2<-0
database$sq_3<-1
database$alt1.priv<-as.numeric(database$alt1.prov==2)
database$alt1.both<-as.numeric(database$alt1.prov==3)
database$alt2.priv<-as.numeric(database$alt2.prov==2)
database$alt2.both<-as.numeric(database$alt2.prov==3)
database$alt3.priv<-as.numeric(database$alt3.prov==2)
database$alt3.both<-as.numeric(database$alt3.prov==3)
database<-database[!is.na(database$choice),]
database<-database[order(database$access,database$ques),]
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(
b_prem = -1,
b_cov = 1,
b_ded = -1 ,
b_priv = 1,
b_both = 1,
b_asc=1,
b_100=1)
### 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 ####
# ################################################################# #
# ################################################################# #
#### 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_prem * alt1.premium + b_cov *alt1.cov + b_ded * alt1.deductible+b_priv*alt1.priv+b_both*alt1.both+b_100*ver100
V[['alt2']] = b_prem * alt2.premium + b_cov *alt2.cov + b_ded * alt2.deductible+b_priv*alt2.priv+b_both*alt2.both+b_100*ver100
V[['alt3']] = b_asc * sq_3
## Define settings for MNL model component
mnl_settings = list(
alternatives = c(alt1=1, alt2=2, alt3=3),
avail = list(alt1=1, alt2=1, alt3=1),
choiceVar = choice,
V = 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)
### 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=3000))
# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #
apollo_modelOutput(model)
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO FILE, using model name) ----
# ----------------------------------------------------------------- #
apollo_saveOutput(model)