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.

ordinal logit using second-order measurement component

Ask questions about model specifications. Ideally include a mathematical explanation of your proposed model.
Post Reply
idserrano
Posts: 7
Joined: 13 May 2020, 21:32

ordinal logit using second-order measurement component

Post by idserrano »

Dear developers of Apollo, I’m trying to estimate an ordinal logit using a second-order measurement component for the latent variables (LVs).
I attached de path diagram of the model to explain me better. However, when I run apollo_estimate I got the following error:

Error in apollo_validate(normalDensity_settings, modelType, functionality, :
Dependent variable for model component "indic_nat_gov" needs to be one-dimensional!

The normal_settings of indic_nat_gov (latent) is:

normalDensity_settings_nat_gov = list(outcomeNormal = nat_gov,
xNormal = zeta_nat_gov*gov,
mu = 0,
sigma = sigma_nat_gov,
rows = (task==1),
componentName = "indic_nat_gov")

And the first order measurement component is:

ol_settings_know_natgov = list(outcomeOrdered=know_natgov,
V=zeta_know_natgov*nat_gov,
tau=c(tau_1_know_natgov, tau_2_know_natgov, tau_3_know_natgov),
rows=(task==1),coding = c(1,2,3,4))

Thank you for any suggestion and guidance to solve this.

Bests,

IS
path v2.PNG
path v2.PNG (76.81 KiB) Viewed 7954 times
(complete code)

library(apollo)
database<-read_csv("data.csv",col_names=TRUE)
database<-as.data.frame(database)
#inicializar apollo
apollo_initialise()
#definir apolo control
apollo_control = list(
modelName ="Ordinal hybrid model Change v0",
modelDescr ="Ordinal hybrid model Change v0",
indivID ="id",
mixing = TRUE,
nCores = 8,
analyticGrad=FALSE
# panelData=FALSE
)
#definir los parametros del modelo a estimar
apollo_beta=c(asc =0,
gamma_nat_gov =0,
gamma_loc_gov =0,
gamma_health_off =0,
gamma_loc_emer_rpnd =0,
gamma_loc_rlf_org =0,
gamma_int_rlf_org =0,
gamma_red_crs =0,
gamma_trad_news =0,
gamma_elec_news =0,
gamma_poli =0,
gamma_fire =0,
zeta_know_natgov =0,
tau_1_know_natgov =-1,
tau_2_know_natgov =0,
tau_3_know_natgov =1,
zeta_trust_natgov =0,
tau_1_trust_natgov =-1,
tau_2_trust_natgov =0,
tau_3_trust_natgov =1,
zeta_know_logov =0,
tau_1_know_logov =-1,
tau_2_know_logov =0,
tau_3_know_logov =1,
zeta_trust_logov =0,
tau_1_trust_logov =-1,
tau_2_trust_logov =0,
tau_3_trust_logov =1,
zeta_know_health =0,
tau_1_know_health =-1,
tau_2_know_health =0,
tau_3_know_health =1,
zeta_trust_health =0,
tau_1_trust_health =-1,
tau_2_trust_health =0,
tau_3_trust_health =1,
zeta_know_localem =0,
tau_1_know_localem =-1,
tau_2_know_localem =0,
tau_3_know_localem =1,
zeta_trust_localem =0,
tau_1_trust_localem =-1,
tau_2_trust_localem =0,
tau_3_trust_localem =1,
zeta_know_localrelief =0,
tau_1_know_localrelief =-1,
tau_2_know_localrelief =0,
tau_3_know_localrelief =1,
zeta_trust_localrelief =0,
tau_1_trust_localrelief =-1,
tau_2_trust_localrelief =0,
tau_3_trust_localrelief =1,
zeta_know_ingo =0,
tau_1_know_ingo =-1,
tau_2_know_ingo =0,
tau_3_know_ingo =1,
zeta_trust_ingo =0,
tau_1_trust_ingo =-1,
tau_2_trust_ingo =0,
tau_3_trust_ingo =1,
zeta_know_redcross =0,
tau_1_know_redcross =-1,
tau_2_know_redcross =0,
tau_3_know_redcross =1,
zeta_trust_redcross =0,
tau_1_trust_redcross =-1,
tau_2_trust_redcross =0,
tau_3_trust_redcross =1,
zeta_know_news =0,
tau_1_know_news =-1,
tau_2_know_news =0,
tau_3_know_news =1,
zeta_trust_news =0,
tau_1_trust_news =-1,
tau_2_trust_news =0,
tau_3_trust_news =1,
zeta_know_social =0,
tau_1_know_social =-1,
tau_2_know_social =0,
tau_3_know_social =1,
zeta_trust_social =0,
tau_1_trust_social =-1,
tau_2_trust_social =0,
tau_3_trust_social =1,
zeta_know_police =0,
tau_1_know_police =-1,
tau_2_know_police =0,
tau_3_know_police =1,
zeta_trust_police =0,
tau_1_trust_police =-1,
tau_2_trust_police =0,
tau_3_trust_police =1,
zeta_know_fire =0,
tau_1_know_fire =-1,
tau_2_know_fire =0,
tau_3_know_fire =1,
zeta_trust_fire =0,
tau_1_trust_fire =-1,
tau_2_trust_fire =0,
tau_3_trust_fire =1,
zeta_nat_gov=1,
sigma_nat_gov=1,
zeta_loc_gov=1,
sigma_loc_gov=1,
zeta_health_off=1,
sigma_health_off=1,
zeta_loc_emer_rpnd=1,
sigma_loc_emer_rpnd=1,
zeta_loc_rlf_org=1,
sigma_loc_rlf_org=1,
zeta_int_rlf_org=1,
sigma_int_rlf_org=1,
zeta_red_crs=1,
sigma_red_crs=1,
zeta_trad_news=1,
sigma_trad_news=1,
zeta_elec_news=1,
sigma_elec_news=1,
zeta_poli=1,
sigma_poli=1,
zeta_fire=1,
sigma_fire=1,
beta_gov =0,
beta_loc_rpnd_org =0,
beta_int_rpnd_org =0,
beta_news =0,
beta_pol_fire=0,
tau_1_change=-1,
tau_2_change=0)
#definir parametros fijos para garantizar identificabilidad
apollo_fixed = c("asc")
# DEFINE RANDOM COMPONENTS
### Set parameters for generating draws
apollo_draws = list(
interDrawsType="mlhs",
interNDraws=500,
interUnifDraws=c(),
interNormDraws=c("eta_gov","eta_loc_rpnd_org","eta_int_rpnd_org","eta_news","eta_pol_fire","eta_nat_gov","eta_loc_gov","eta_health_off","eta_loc_emer_rpnd","eta_loc_rlf_org","eta_int_rlf_org","eta_red_crs","eta_trad_news","eta_elec_news","eta_poli","eta_fire"),
intraDrawsType='',
intraNDraws=0,
intraUnifDraws=c(),
intraNormDraws=c()
)
### Create random parameters
apollo_randCoeff=function(apollo_beta, apollo_inputs){
randcoeff = list()
randcoeff[["nat_gov"]] = eta_nat_gov
randcoeff[["loc_gov"]] = eta_loc_gov
randcoeff[["health_off"]] = eta_health_off
randcoeff[["loc_emer_rpnd"]] = eta_loc_emer_rpnd
randcoeff[["loc_rlf_org"]] = eta_loc_rlf_org
randcoeff[["int_rlf_org"]] = eta_int_rlf_org
randcoeff[["red_crs"]] = eta_red_crs
randcoeff[["trad_news"]] = eta_trad_news
randcoeff[["elec_news"]] = eta_elec_news
randcoeff[["poli"]] = eta_poli
randcoeff[["fire"]] = eta_fire
randcoeff[["gov"]] = eta_gov
randcoeff[["loc_rpnd_org"]] = eta_loc_rpnd_org
randcoeff[["int_rpnd_org"]] = eta_int_rpnd_org
randcoeff[["news"]] = eta_news
randcoeff[["pol_fire"]] = eta_pol_fire
return(randcoeff)
}
apollo_inputs = apollo_validateInputs()
#definir apollo probabilities function
apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))
P = list()
### Likelihood of indicators
#####gov
ol_settings_know_natgov = list(outcomeOrdered=know_natgov,
V=zeta_know_natgov*nat_gov,
tau=c(tau_1_know_natgov, tau_2_know_natgov, tau_3_know_natgov),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_trust_natgov = list(outcomeOrdered=trust_natgov,
V=zeta_trust_natgov*nat_gov,
tau=c(tau_1_trust_natgov, tau_2_trust_natgov, tau_3_trust_natgov),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_know_logov = list(outcomeOrdered=know_logov,
V=zeta_know_logov*loc_gov,
tau=c(tau_1_know_logov, tau_2_know_logov, tau_3_know_logov),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_trust_logov = list(outcomeOrdered=trust_logov,
V=zeta_trust_logov*loc_gov,
tau=c(tau_1_trust_logov, tau_2_trust_logov, tau_3_trust_logov),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_know_health = list(outcomeOrdered=know_health,
V=zeta_know_health*health_off,
tau=c(tau_1_know_health, tau_2_know_health, tau_3_know_health),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_trust_health = list(outcomeOrdered=trust_health,
V=zeta_trust_health*health_off,
tau=c(tau_1_trust_health, tau_2_trust_health, tau_3_trust_health),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_know_localem = list(outcomeOrdered=know_localem,
V=zeta_know_localem*loc_emer_rpnd,
tau=c(tau_1_know_localem, tau_2_know_localem, tau_3_know_localem),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_trust_localem = list(outcomeOrdered=trust_localem,
V=zeta_trust_localem*loc_emer_rpnd,
tau=c(tau_1_trust_localem, tau_2_trust_localem, tau_3_trust_localem),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_know_localrelief = list(outcomeOrdered=know_localrelief,
V=zeta_know_localrelief*loc_rlf_org,
tau=c(tau_1_know_localrelief, tau_2_know_localrelief, tau_3_know_localrelief),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_trust_localrelief = list(outcomeOrdered=trust_localrelief,
V=zeta_trust_localrelief*loc_rlf_org,
tau=c(tau_1_trust_localrelief, tau_2_trust_localrelief, tau_3_trust_localrelief),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_know_ingo = list(outcomeOrdered=know_ingo,
V=zeta_know_ingo*int_rlf_org,
tau=c(tau_1_know_ingo, tau_2_know_ingo, tau_3_know_ingo),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_trust_ingo = list(outcomeOrdered=trust_ingo,
V=zeta_trust_ingo*int_rlf_org,
tau=c(tau_1_trust_ingo, tau_2_trust_ingo, tau_3_trust_ingo),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_know_redcross = list(outcomeOrdered=know_redcross,
V=zeta_know_redcross*red_crs,
tau=c(tau_1_know_redcross, tau_2_know_redcross, tau_3_know_redcross),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_trust_redcross = list(outcomeOrdered=trust_redcross,
V=zeta_trust_redcross*red_crs,
tau=c(tau_1_trust_redcross, tau_2_trust_redcross, tau_3_trust_redcross),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_know_news = list(outcomeOrdered=know_news,
V=zeta_know_news*trad_news,
tau=c(tau_1_know_news, tau_2_know_news, tau_3_know_news),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_trust_news = list(outcomeOrdered=trust_news,
V=zeta_trust_news*trad_news,
tau=c(tau_1_trust_news, tau_2_trust_news, tau_3_trust_news),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_know_social = list(outcomeOrdered=know_social,
V=zeta_know_social*elec_news,
tau=c(tau_1_know_social, tau_2_know_social, tau_3_know_social),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_trust_social = list(outcomeOrdered=trust_social,
V=zeta_trust_social*elec_news,
tau=c(tau_1_trust_social, tau_2_trust_social, tau_3_trust_social),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_know_police = list(outcomeOrdered=know_police,
V=zeta_know_police*poli,
tau=c(tau_1_know_police, tau_2_know_police, tau_3_know_police),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_trust_police = list(outcomeOrdered=trust_police,
V=zeta_trust_police*poli,
tau=c(tau_1_trust_police, tau_2_trust_police, tau_3_trust_police),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_know_fire = list(outcomeOrdered=know_fire,
V=zeta_know_fire*fire,
tau=c(tau_1_know_fire, tau_2_know_fire, tau_3_know_fire),
rows=(task==1),coding = c(1,2,3,4))
ol_settings_trust_fire = list(outcomeOrdered=trust_fire,
V=zeta_trust_fire*fire,
tau=c(tau_1_trust_fire, tau_2_trust_fire, tau_3_trust_fire),
rows=(task==1),coding = c(1,2,3,4))
###second order measurement
normalDensity_settings_nat_gov = list(outcomeNormal = nat_gov,
xNormal = zeta_nat_gov*gov,
mu = 0,
sigma = sigma_nat_gov,
rows = (task==1),
componentName = "indic_nat_gov")
normalDensity_settings_loc_gov = list(outcomeNormal = loc_gov,
xNormal = zeta_loc_gov*gov,
mu = 0,
sigma = sigma_loc_gov,
rows = (task==1),
componentName = "indic_loc_gov")
normalDensity_settings_health_off = list(outcomeNormal = health_off,
xNormal = zeta_health_off*loc_rpnd_org,
mu = 0,
sigma = sigma_health_off,
rows = (task==1),
componentName = "indic_health_off")
normalDensity_settings_loc_emer_rpnd = list(outcomeNormal = loc_emer_rpnd,
xNormal = zeta_loc_emer_rpnd*loc_rpnd_org,
mu = 0,
sigma = sigma_loc_emer_rpnd,
rows = (task==1),
componentName = "indic_loc_emer_rpnd")
normalDensity_settings_loc_rlf_org = list(outcomeNormal = loc_rlf_org,
xNormal = zeta_loc_rlf_org*loc_rpnd_org,
mu = 0,
sigma = sigma_loc_rlf_org,
rows = (task==1),
componentName = "indic_loc_rlf_org")
normalDensity_settings_int_rlf_org = list(outcomeNormal = int_rlf_org,
xNormal = zeta_int_rlf_org*int_rpnd_org,
mu = 0,
sigma = sigma_int_rlf_org,
rows = (task==1),
componentName = "indic_int_rlf_org")
normalDensity_settings_red_crs = list(outcomeNormal = red_crs,
xNormal = zeta_red_crs*int_rpnd_org,
mu = 0,
sigma = sigma_red_crs,
rows = (task==1),
componentName = "indic_red_crs")
normalDensity_settings_trad_news = list(outcomeNormal = trad_news,
xNormal = zeta_trad_news*news,
mu = 0,
sigma = sigma_trad_news,
rows = (task==1),
componentName = "indic_trad_news")
normalDensity_settings_elec_news = list(outcomeNormal = elec_news,
xNormal = zeta_elec_news*news,
mu = 0,
sigma = sigma_elec_news,
rows = (task==1),
componentName = "indic_elec_news")
normalDensity_settings_poli = list(outcomeNormal = poli,
xNormal = zeta_poli*pol_fire,
mu = 0,
sigma = sigma_poli,
rows = (task==1),
componentName = "indic_poli")
normalDensity_settings_fire = list(outcomeNormal = fire,
xNormal = zeta_fire*pol_fire,
mu = 0,
sigma = sigma_fire,
rows = (task==1),
componentName = "indic_fire")
P[["indic_know_natgov"]] = apollo_ol(ol_settings_know_natgov, functionality)
P[["indic_trust_natgov"]] = apollo_ol(ol_settings_trust_natgov, functionality)
P[["indic_know_logov"]] = apollo_ol(ol_settings_know_logov, functionality)
P[["indic_trust_logov"]] = apollo_ol(ol_settings_trust_logov, functionality)
P[["indic_know_health"]] = apollo_ol(ol_settings_know_health, functionality)
P[["indic_trust_health"]] = apollo_ol(ol_settings_trust_health, functionality)
P[["indic_know_localem"]] = apollo_ol(ol_settings_know_localem, functionality)
P[["indic_trust_localem"]] = apollo_ol(ol_settings_trust_localem, functionality)
P[["indic_know_localrelief"]] = apollo_ol(ol_settings_know_localrelief, functionality)
P[["indic_trust_localrelief"]] = apollo_ol(ol_settings_trust_localrelief, functionality)
P[["indic_know_ingo"]] = apollo_ol(ol_settings_know_ingo, functionality)
P[["indic_trust_ingo"]] = apollo_ol(ol_settings_trust_ingo, functionality)
P[["indic_know_redcross"]] = apollo_ol(ol_settings_know_redcross, functionality)
P[["indic_trust_redcross"]] = apollo_ol(ol_settings_trust_redcross, functionality)
P[["indic_know_news"]] = apollo_ol(ol_settings_know_news, functionality)
P[["indic_trust_news"]] = apollo_ol(ol_settings_trust_news, functionality)
P[["indic_know_social"]] = apollo_ol(ol_settings_know_social, functionality)
P[["indic_trust_social"]] = apollo_ol(ol_settings_trust_social, functionality)
P[["indic_know_police"]] = apollo_ol(ol_settings_know_police, functionality)
P[["indic_trust_police"]] = apollo_ol(ol_settings_trust_police, functionality)
P[["indic_know_fire"]] = apollo_ol(ol_settings_know_fire, functionality)
P[["indic_trust_fire"]] = apollo_ol(ol_settings_trust_fire, functionality)
##second order measures
P[["indic_nat_gov"]] = apollo_normalDensity(normalDensity_settings_nat_gov, functionality)
P[["indic_loc_gov"]] = apollo_normalDensity(normalDensity_settings_loc_gov, functionality)
P[["indic_health_off"]] = apollo_normalDensity(normalDensity_settings_health_off, functionality)
P[["indic_loc_emer_rpnd"]] = apollo_normalDensity(normalDensity_settings_loc_emer_rpnd, functionality)
P[["indic_loc_rlf_org"]] = apollo_normalDensity(normalDensity_settings_loc_rlf_org, functionality)
P[["indic_int_rlf_org"]] = apollo_normalDensity(normalDensity_settings_int_rlf_org, functionality)
P[["indic_red_crs"]] = apollo_normalDensity(normalDensity_settings_red_crs, functionality)
P[["indic_trad_news"]] = apollo_normalDensity(normalDensity_settings_trad_news, functionality)
P[["indic_elec_news"]] = apollo_normalDensity(normalDensity_settings_elec_news, functionality)
P[["indic_poli"]] = apollo_normalDensity(normalDensity_settings_poli, functionality)
P[["indic_fire"]] = apollo_normalDensity(normalDensity_settings_fire, functionality)
ol_settings_change = list(outcomeOrdered=change,
V= asc + beta_gov * gov + beta_loc_rpnd_org * loc_rpnd_org + beta_int_rpnd_org * int_rpnd_org + beta_news * news +
beta_pol_fire * pol_fire,
tau=c(tau_1_change, tau_2_change),
rows=(task==1),coding = c(1,2,3))
P[["change"]] = apollo_ol(ol_settings_change, 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)
}
#estimar el modelo
# ################################################################# #
#### MODEL ESTIMATION ####
# ################################################################# #

### Optional: calculate LL before model estimation
apollo_llCalc(apollo_beta, apollo_probabilities, apollo_inputs)

### Estimate model
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)

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

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

apollo_modelOutput(model)

# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO FILE, using model name) ----
# ----------------------------------------------------------------- #

apollo_saveOutput(model)
stephanehess
Site Admin
Posts: 977
Joined: 24 Apr 2020, 16:29

Re: ordinal logit using second-order measurement component

Post by stephanehess »

Hi

the reason this is going wrong is because you're treating natgov as a dependent variable in the model. But natgov is not something that you observe in the data, but rather is just a function of the other LV. So you should just define natgov in apollo_randCoeff as a function of gov (the other LV), and the dependent variables will simply be knowledge and trust

Hope this helps

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
caldeiraga
Posts: 11
Joined: 24 Aug 2020, 15:07
Location: Brazil
Contact:

Re: ordinal logit using second-order measurement component

Post by caldeiraga »

Hi prof Hess,

I think it's a silly question, but, if I want to specify an ordered model like in the polr function from the MASS package, where I specify the utility (in the Manual says V is a numeric vector) in the model? All the examples in the manual and the topics here discuss the specification of the latent variable (or the numeric vector V) in the the rand_coeff list. I think for simple ordered models the specification it's more simple than using random coefficients, right? Can you give an example? I tried specificing V inside apollo_probabilitites like V = beta*attribute but it didn't work. Thanks in advance.

Best,
Gabriel
stephanehess
Site Admin
Posts: 977
Joined: 24 Apr 2020, 16:29

Re: ordinal logit using second-order measurement component

Post by stephanehess »

Hi

we're happy to help, but please show us your code so we can tell you where it goes wrong

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
caldeiraga
Posts: 11
Joined: 24 Aug 2020, 15:07
Location: Brazil
Contact:

Re: ordinal logit using second-order measurement component

Post by caldeiraga »

My model has an ordered variable with 4 outcomes, I just put two variables to test with it works, but then I get the following message:
Error in apollo_validate(ol_settings, modelType, functionality, apollo_inputs) :
Some values inside V are not finite for model component "model"
Além disso: Warning message:
In Ops.factor(b_sexo * apollo_inputs$apollo_scaling["b_sexo"], SEXO) :

Error in apollo_validate(ol_settings, modelType, functionality, apollo_inputs) :
Some values inside V are not finite for model component "model"

Code: Select all

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
  modelName  ="OL_1",
  modelDescr ="",
  indivID    ="ID"
)

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

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(tau_1   = -1,
              tau_2   = 0,
              tau_3   = 1,
              b_sex  = 0,
              b_age = 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()

# ################################################################# #
#### 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 settings for MNL model component
  ol_settings = list(
    outcomeOrdered  = outcome, 
    tau = list(tau_1,tau_2,tau_3),
    V   = b_sex*SEX + b_age*AGE
    )
  
  ### Compute probabilities using MNL model
  P[["model"]]  = apollo_ol(ol_settings, functionality)

  ### Prepare and return outputs of function
  P = apollo_prepareProb(P, apollo_inputs, functionality)
  
  return(P)
}

Gabriel
stephanehess
Site Admin
Posts: 977
Joined: 24 Apr 2020, 16:29

Re: ordinal logit using second-order measurement component

Post by stephanehess »

do you maybe have some NA values in the data? Or missing values?
--------------------------------
Stephane Hess
www.stephanehess.me.uk
caldeiraga
Posts: 11
Joined: 24 Aug 2020, 15:07
Location: Brazil
Contact:

Re: ordinal logit using second-order measurement component

Post by caldeiraga »

I found the error prof Hess, I was specifying in a wrong way the SEX variable and now it works. Thanks!

Best,
Gabriel
Post Reply