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. 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.

hybrid model error "Some values inside xNormal are not finite"

Ask questions about the results reported after estimation. If the output includes errors, please include your model code if possible.
Post Reply
manes
Posts: 25
Joined: 15 Jun 2023, 13:13
Location: Israel
Contact:

hybrid model error "Some values inside xNormal are not finite"

Post by manes »

Hi all,
I have a repeating error (I use the most recent Apollo version).
I ran a hybrid MMNL with one latent variable, normally distributed which affects two indicators for pro-environmental behavior (peb).
The scale has 6 items, I have started with the two items with the highest loading.
(I have tried the ordered logit before but given the error message switched to normal distribution for now)
The model stops at apollo_validate and returns
Error in apollo_validate(normalDensity_settings, modelType, functionality, : INPUT ISSUE - Some values inside xNormal are not finite for model component "indic_paper"
I'm not sure what the problem is. Both indicators are 1-5 categorical variables.
This is the link to the data file https://www.dropbox.com/scl/fi/nkhi7al6 ... pnhss&dl=0
the code is below.

Code: Select all

rm(list = ls())
library ("apollo")
apollo_initialise()
### Set core controls
apollo_control = list(
  modelName       = "MMNL_hybrid_1",
  modelDescr      = "MMNL hybrid 1",
  indivID         = "id",
  nCores     = 3,
  outputDirectory = "output"
)

# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS                     ####
# ################################################################# #

database=read.csv("experiment_1_R.csv",header=TRUE)

# ################################################################# #
#### DEFINE MODEL PARAMETERS                                     ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=  c(asc_nano = 0, 
                asc_disposable_mu =-1.23 ,
                asc_disposable_sig =3.87,
                
                asc_cloth_mu= -1.95,
                asc_cloth_sig= 2.96,
                
                b_price_month  = -0.07,
                b_eco_friendly= 0.535,
                
                b_virus_effective=0,
                b_comfort_level=0.55,
                
                gamma_education_peb=0,
                lambda_peb=0,
                
                zeta_pb_recyc_paper=0, 
                zeta_pb_recyc_glass=0, 
                
                mu_pb_recyc_paper=0,
                mu_pb_recyc_glass=0,
                
                sigma_pb_recyc_paper=1,
                sigma_pb_recyc_glass=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("asc_nano" )

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

### Set parameters for generating draws
apollo_draws = list(
 interDrawsType = "halton", 
  interNDraws    = 800,    
 interUnifDraws=c(),      
  interNormDraws = c("draws_cloth","draws_disposable" ,"eta_peb")
)

### Create random parameters

apollo_randCoeff = function(apollo_beta, apollo_inputs){
  randcoeff = list()
  randcoeff[["asc_cloth"]] = asc_cloth_mu + asc_cloth_sig * draws_cloth 
  randcoeff[["asc_disposable"]] = asc_disposable_mu +  asc_disposable_sig * draws_disposable
  randcoeff[["peb"]]= gamma_education_peb*education+eta_peb
  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()
 
  
normalDensity_settings1 = list(outcomeNormal= pb_recyc_paper, 
                              xNormal=zeta_pb_recyc_paper*peb, 
                              mu=mu_pb_recyc_paper, 
                              sigma=sigma_pb_recyc_paper,
                              rows=(task==1))  

normalDensity_settings2 = list(outcomeNormal= pb_recyc_glass, 
                               xNormal=zeta_pb_recyc_glass*peb, 
                               mu=mu_pb_recyc_glass, 
                               sigma=sigma_pb_recyc_glass,
                               rows=(task==1))

P[["indic_paper"]] = apollo_normalDensity(normalDensity_settings1, functionality)
P[["indic_glass"]] = apollo_normalDensity(normalDensity_settings2, functionality)


  V=list()
  V[["disposable"]]= asc_disposable + b_eco_friendly *eco_friendly_disposable + b_virus_effective* virus_effective_disposable   
                           +b_comfort_level*comfort_level_disposable + b_price_month*price_month_disposable +lambda_peb*peb
  V[["cloth"]] =     asc_cloth      + b_eco_friendly *eco_freindly_cloth   + b_virus_effective* virus_effective_cloth          
                          +b_comfort_level*comfort_level_cloth      + b_price_month*price_month_cloth   +lambda_peb*peb                                                                                                                                 
  V[["nano"]] =      asc_nano       + b_eco_friendly *eco_freindly_nano      + b_virus_effective* virus_effective_nano         
                              +b_comfort_level*comfort_level_nano       + b_price_month*price_month_nano                                       
  
  ### Define settings for MNL model component
  mnl_settings = list(
    alternatives  = c(disposable=1, cloth=2, nano=3),
    choiceVar     = choice,
    V     = V
    #componentName = "choice"
  )
  #   
  #   ### Compute probabilities using MNL model
 P[['choice']] = apollo_mnl(mnl_settings, functionality)
  ### Likelihood of the whole model
  P = apollo_combineModels(P, apollo_inputs, 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)
}
################################################################## #
#### CHECK FOR COMPUTATIONAL REQUIREMENTS                         ####
# ################################################################# #

speedTest_settings=list(
nDrawsTry = c(250, 500, 1000),
nCoresTry = 1:8,
nRep      = 10
)

#apollo_speedTest(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs, speedTest_settings)
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
apollo_saveOutput(model)
Anat Tchetchik
stephanehess
Site Admin
Posts: 1355
Joined: 24 Apr 2020, 16:29

Re: hybrid model error "Some values inside xNormal are not finite"

Post by stephanehess »

Hi

I don't get that error message, but you had a different issue. Your utlities were:

Code: Select all

 V[["disposable"]]= asc_disposable + b_eco_friendly *eco_friendly_disposable + b_virus_effective* virus_effective_disposable   
                           +b_comfort_level*comfort_level_disposable + b_price_month*price_month_disposable +lambda_peb*peb
  V[["cloth"]] =     asc_cloth      + b_eco_friendly *eco_freindly_cloth   + b_virus_effective* virus_effective_cloth          
                          +b_comfort_level*comfort_level_cloth      + b_price_month*price_month_cloth   +lambda_peb*peb                                                                                                                                 
  V[["nano"]] =      asc_nano       + b_eco_friendly *eco_freindly_nano      + b_virus_effective* virus_effective_nano         
                              +b_comfort_level*comfort_level_nano       + b_price_month*price_month_nano                                       
 


the line breaks mean that the second part is ignored each time. You need to either have each utility on a line without line breaks, or end the first line with +, or put a bracket around it.

Then your model runs fine

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
manes
Posts: 25
Joined: 15 Jun 2023, 13:13
Location: Israel
Contact:

Re: hybrid model error "Some values inside xNormal are not finite"

Post by manes »

Thank you so much Stephane!
It runs and converges smoothly
(guess I was confusing with Ngene syntax that allows for such breaks)
Anat Tchetchik
Post Reply