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)
Important: Read this before posting to this forum
- This forum is for questions related to the use of Apollo. We will answer some general choice modelling questions too, where appropriate, and time permitting. We cannot answer questions about how to estimate choice models with other software packages.
- There is a very detailed manual for Apollo available at http://www.ApolloChoiceModelling.com/manual.html. This contains detailed descriptions of the various Apollo functions, and numerous examples are available at http://www.ApolloChoiceModelling.com/examples.html. In addition, help files are available for all functions, using e.g. ?apollo_mnl
- Before asking a question on the forum, users are kindly requested to follow these steps:
- Check that the same issue has not already been addressed in the forum - there is a search tool.
- Ensure that the correct syntax has been used. For any function, detailed instructions are available directly in Apollo, e.g. by using ?apollo_mnl for apollo_mnl
- Check the frequently asked questions section on the Apollo website, which discusses some common issues/failures. Please see http://www.apollochoicemodelling.com/faq.html
- Make sure that R is using the latest official release of Apollo.
- Users can check which version they are running by entering packageVersion("apollo").
- Then check what is the latest full release (not development version) at http://www.ApolloChoiceModelling.com/code.html.
- To update to the latest official version, just enter install.packages("apollo"). To update to a development version, download the appropriate binary file from http://www.ApolloChoiceModelling.com/code.html, and install the package from file
- If the above steps do not resolve the issue, then users should follow these steps when posting a question:
- provide full details on the issue, including the entire code and output, including any error messages
- posts will not immediately appear on the forum, but will be checked by a moderator first. We check the forum at least twice a week. It may thus take a couple of days for your post to appear and before we reply. There is no need to submit the post multiple times.
Log-likelihood calculation fails at values close to the starting values!
Log-likelihood calculation fails at values close to the starting values!
- Attachments
-
- Screenshot 2025-07-16 154404.png (44.45 KiB) Viewed 40638 times
-
stephanehess
- Site Admin
- Posts: 1348
- Joined: 24 Apr 2020, 16:29
Re: Log-likelihood calculation fails at values close to the starting values!
Hi
you are using non-zero starting values to multiply very large attribute values, and when they then get exponentiated, you get some zero probs. SImply start your betas at zero and it should work fine
Stephane
you are using non-zero starting values to multiply very large attribute values, and when they then get exponentiated, you get some zero probs. SImply start your betas at zero and it should work fine
Stephane
Re: Log-likelihood calculation fails at values close to the starting values!
Thank you! I appreciate your help. After adapting the starting values and catching one other issue with the attribute definitions the MNL now converges.
And thank you for getting Apollo out the the world! It quickly became my go to for choice modeling.
Mike
And thank you for getting Apollo out the the world! It quickly became my go to for choice modeling.
Mike