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

More Yu Zhang's questions See All
Similar questions and discussions