Page 1 of 1

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

Posted: 06 Jun 2022, 17:40
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)

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

Posted: 27 Jun 2022, 11:32
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