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.

Error "Some utilities for model component "MNL" contain values that are not finite numbers!"

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
Post Reply
arohamirai
Posts: 18
Joined: 28 Jun 2020, 16:26

Error "Some utilities for model component "MNL" contain values that are not finite numbers!"

Post by arohamirai »

Dear Stephane,

I was estimating a RPL model with a non-linear specification in one of the attributes.

The DCE
Attributes: air, flood, ObjCert, largetrees, mixedtrees, cost
Available options: 2 alternatives + 1 status quo

The model
The nonlinear part is specified as: R*=(exp(-((-log(R))^gamma)))), where R is one of the attribute, gamma is the parameter to be estimated representing the degree of nonlinearity. The model also accounts for full correlation between random parameters and impose a lognormal distribution on the cost attribute.

The errors
Preparing user-defined functions.
Testing likelihood function...
Apollo found a model component of type MNL without a componentName.
The name was set to "MNL" by default.
Error in apollo_validate(mnl_settings, modelType, functionality, apollo_inputs) :
Some utilities for model component "MNL" contain values that are not finite numbers!
Please see below for the codes used
.

Question
Could you kindly tell me what could be the potential reason of the error? I can provide the data if needed. Thank you very much.

Best wishes,
Tim

Codes

# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS ####
# ################################################################# #

### Clear memory
rm(list = ls())

### Load Apollo library
library(apollo)

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
modelName ="PT_NL",
modelDescr ="PT_NL",
indivID ="ID",
nCores = 4,
mixing = TRUE,
noDiagnostics = TRUE
)

# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #
#load the data
database = read.csv("choice_data.csv",header=TRUE)

##rescale
database$ObjCert1=database$ObjCert1/100

##excluding control group
database= subset(database, database$Certain==0)

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

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(asc_I = 0,

asc_III = 0,

PT_air_mu = 0,
PT_air_sig = 0,

PT_flood_mu = 0,
PT_flood_sig = 0,

largetrees_mu = 0,
largetrees_sig = 0,

mixedtrees_mu = 0,
mixedtrees_sig = 0,

logcost_mu = -3,
logcost_sig = 0,

gamma_air = 0.5,

air_flood = 0,
air_largetrees = 0,
air_mixedtrees = 0,
air_price = 0,

flood_largetrees = 0,
flood_mixedtrees = 0,
flood_price = 0,

largetrees_mixedtrees = 0,
largetrees_price = 0,

mixedtree_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( "asc_I") #fix the scale of the control treatment


# ################################################################# #
#### DEFINE RANDOM COMPONENTS ####
# ################################################################# #

### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "mlhs",
interNDraws = 500,
interUnifDraws = c(),
interNormDraws = c("draws_PTair",
"draws_PTflood",
"draws_largetrees",
"draws_mixedtrees",
"draws_cost"
),

intraDrawsType = "halton",
intraNDraws = 0,
intraUnifDraws = c(),
intraNormDraws = c()
)

### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()

randcoeff[["PT_air"]] = PT_air_mu + PT_air_sig*draws_PTair +
air_flood*draws_PTflood +
air_largetrees*draws_largetrees+
air_mixedtrees*draws_mixedtrees+
air_price*draws_cost

randcoeff[["PT_flood"]] = PT_flood_mu + PT_flood_sig*draws_PTflood +
flood_largetrees*draws_largetrees+
flood_mixedtrees*draws_mixedtrees+
flood_price*draws_cost

randcoeff[["largetrees"]] = largetrees_mu + largetrees_sig*draws_largetrees +
largetrees_mixedtrees*draws_mixedtrees+
largetrees_price*draws_cost

randcoeff[["mixedtrees"]] = mixedtrees_mu + mixedtrees_sig*draws_mixedtrees +
mixedtree_price*draws_cost

randcoeff[["cost"]] = -exp(logcost_mu + logcost_sig*draws_cost)


return(randcoeff)
}


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

### Compute utilities
V=list()
V[['alt1']] = asc_I + PT_air*(Health1*(exp(-((-log(ObjCert1))^gamma_air)))) +
PT_flood*Flood1*ObjCert1 +
largetrees*AppLarge1 +
mixedtrees*AppMixed1 + cost*Price1


V[['alt2']] = asc_I + PT_air*(Health2*(exp(-((-log(ObjCert2))^gamma_air)))) +
PT_flood*Flood2*ObjCert2+
largetrees*AppLarge2 +
mixedtrees*AppMixed2 + cost*Price2

V[['alt3']] = asc_III



### Define settings for MNL model component that are generic across classes
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)

# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #

# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #

apollo_modelOutput(model)
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Error "Some utilities for model component "MNL" contain values that are not finite numbers!"

Post by stephanehess »

Hi

apologies for the slow reply.

This is almost certainly caused by the fact that you take the log of R, this becomes negative, and then you take this to the power of 0.5. What is the range of R?

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Post Reply