hybrid model error "Some values inside xNormal are not finite"
Posted: 14 Aug 2024, 14:54
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
This is the link to the data file https://www.dropbox.com/scl/fi/nkhi7al6 ... pnhss&dl=0
the code is below.
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
I'm not sure what the problem is. Both indicators are 1-5 categorical variables.Error in apollo_validate(normalDensity_settings, modelType, functionality, : INPUT ISSUE - Some values inside xNormal are not finite for model component "indic_paper"
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)