Important: Read this before posting to this forum

  1. 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.
  2. 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
  3. Before asking a question on the forum, users are kindly requested to follow these steps:
    1. Check that the same issue has not already been addressed in the forum - there is a search tool.
    2. 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
    3. Check the frequently asked questions section on the Apollo website, which discusses some common issues/failures. Please see http://www.apollochoicemodelling.com/faq.html
    4. Make sure that R is using the latest official release of Apollo.
  4. If the above steps do not resolve the issue, then users should follow these steps when posting a question:
    1. provide full details on the issue, including the entire code and output, including any error messages
    2. posts will not immediately appear on the forum, but will be checked by a moderator first. This may take a day or two at busy times. There is no need to submit the post multiple times.

All observations have zero probability at starting value for model component

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
Post Reply
billyuoft
Posts: 5
Joined: 05 May 2022, 21:01

All observations have zero probability at starting value for model component

Post by billyuoft »

Hi there,

I am running a MDCEV model on location choice dataset and at first I ran into an error as "Log-likelihood calculation fails at values close to the starting values!" so I changed some starting values and now I am getting this eror:

Error in if (all(testL == 0)) stop("All observations have zero probability at starting value for model component \"", :
missing value where TRUE/FALSE needed

Could anyone give me some suggestions? Much appreciated!

And here is my code:
### Clear memory
rm(list = ls())

### Load Apollo library
library(apollo)

### Initialise code
apollo_initialise()


### Set core controls
apollo_control = list(
modelName = "MDCEV_no_outside_good",
modelDescr = "MDCEV model on housing supply data, alpha-gamma profile, no outside good and constants only in utilities",
indivID = "indivID",
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)
database = read.csv("Project_MDCEV.csv",header=TRUE)
alt = read.csv("alternatives.csv",header=TRUE)
attach(database)
View(database)
### for data dictionary, use ?apollo_timeUseData

# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(alpha_base = 10,
gamma_gen = -1,
delta_acar = 100,
sig = 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("sig")

# ################################################################# #
#### GROUP AND VALIDATE INPUTS ####
# ################################################################# #
apollo_inputs = apollo_validateInputs()

# ################################################################# #
#### 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()

### Define individual alternatives
alternatives = as.character(alt$DAUID)

### Define availabilities
avail = list()
for(i in alt$DAUID){
avail[paste0(i)] = 1
}

### Define continuous consumption for individual alternatives
continuousChoice = list()
for (i in alt$DAUID){
continuousChoice[[paste0(i)]] = get(paste0("X",i))
}

### Define utilities for individual alternatives
V = list()
for (i in alt$DAUID){
V[[paste0(i)]] = delta_acar *alt$ACAR[which(alt$DAUID==paste0(i))]
}


### Define alpha parameters
alpha = list()
for (i in alt$DAUID){
alpha[paste0(i)]=1/(1+exp(-alpha_base))
}


### Define gamma parameters
gamma =list()
for (i in alt$DAUID){
gamma[paste0(i)]=gamma_gen
}

### Define costs for individual alternatives
cost = list()
for(i in alt$DAUID){
cost[paste0(i)] = 1
}

budget <- budget_cal
### Define settings for MDCEV model
mdcev_settings <- list(alternatives = alternatives,
avail = avail,
continuousChoice = continuousChoice,
utilities = V,
alpha = alpha,
gamma = gamma,
sigma = sig,
cost = cost,
budget = budget)

### Compute probabilities using MDCEV model
P[["model"]] = apollo_mdcev(mdcev_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)

# ################################################################# #
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: All observations have zero probability at starting value for model component

Post by stephanehess »

Hi

we would needs to know a bit more about your setup, alternatives, attributes, etc. But the starting values are likely causing the problems. Gamma for example should be positive

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
billyuoft
Posts: 5
Joined: 05 May 2022, 21:01

Re: All observations have zero probability at starting value for model component

Post by billyuoft »

Hi Stephane,

Thank you for replying! My alternatives are 2057 locations, each alternative has 11 attributes (accessibility, housing price, etc.) but now I am just testing with one attribute (accessibility, indicated as ACAR in the code). I tried a positve gamma just now and the error shows as "Log-likelihood calculation fails at values close to the starting values!" so I think you are right, and starting value issue is likely causing this. Should I try with more other values for the betas?

Thanks,
Billy
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: All observations have zero probability at starting value for model component

Post by stephanehess »

Yes. Also, the starting value for your delta term is very high, and this will cause problems too
--------------------------------
Stephane Hess
www.stephanehess.me.uk
billyuoft
Posts: 5
Joined: 05 May 2022, 21:01

Re: All observations have zero probability at starting value for model component

Post by billyuoft »

I think I can partly answer for myself now.

My preliminary code is running fine now with these two changes:
1. I changed the individualID as simply 1,2,3,.. and then removed the panel feature in apollo function.
2. I removed delta in apollo_beta as this parameter does not influence the loglikelihood.
3. I only tested with one variable for now and it's working.

Not sure if this is the right way of fixing this issue but I will continue to test with more variables.
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: All observations have zero probability at starting value for model component

Post by stephanehess »

I would change the starting value of delta rather than drop it. Regarding the removal of the panel structure, how many observations do you have per individual?
--------------------------------
Stephane Hess
www.stephanehess.me.uk
billyuoft
Posts: 5
Joined: 05 May 2022, 21:01

Re: All observations have zero probability at starting value for model component

Post by billyuoft »

Thank you so much Stephane! I tried with delta = -1 as starting value and it worked. My model is a little bit fuzzy on the individual ID, as I am assigning housing units to different locations. So here my "individual" is actually each structure type and I have the observation for around 20 years each month. I think I will try to use separate models for each structure type and that way I would completely remove the panel structure.
Post Reply