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.

Error in ICLV estimation: "Estimation Failed. No covariance matrix to compute."

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
Post Reply
janak12_jp
Posts: 16
Joined: 08 Sep 2021, 16:52

Error in ICLV estimation: "Estimation Failed. No covariance matrix to compute."

Post by janak12_jp »

I am trying to develop an ICLV model with binary logit. I get the results for parameter estimates but could not compute the covariance matrix and subsequently SE.
Please note that I have tried several specifications with trail & error looking to the large coefficients, changing priors (started with values from simple logit model). For the sake of clarification, I changed the fixed alternative setting as well. But the issue remains the same.

Attaching a simple specified code for reference.

Code: Select all

## Initialization

rm(list=ls())
library(apollo)
apollo_initialise()

## Set Core Controls

apollo_control= list(
  modelName= "ICLV",
  modelDescr= "Mode choice with latent variable",
  indivID= "ID"
 )

## Load database

database= read.csv("#####/iclvdata-2.csv", header=T)

## Parameter operations

database$orgbus= database$orgbus / 100
database$desbus= database$desbus / 100
database$tc_mpv= database$tc_mpv / 1000
database$tc_mpt= database$tc_mpt / 1000
database$tt_pv= database$tt_pv / 10
database$tt_pt= database$tt_pt / 10

## Definition of Model Parameters
### Vector of Parameters to be estimated

apollo_beta= c(# Alternate Specific Constants
               asc_pv= 1.029,
               asc_pt= 0,
                              
               # Social-Economic parameters
               gamma_female_comfort= 0, gamma_female_ttr= 0, gamma_female_cleanliness= 0, gamma_female_staffbehaviour= 0, gamma_female_envisusitain= 0, 
               
               gamma_age_under18_comfort= 0, gamma_age_under18_ttr= 0, gamma_age_under18_cleanliness= 0, gamma_age_under18_staffbehaviour= 0, gamma_age_under18_envisusitain= 0, 
               
               gamma_age_1830_comfort= 0, gamma_age_1830_ttr= 0, gamma_age_1830_cleanliness= 0, gamma_age_1830_staffbehaviour= 0, gamma_age_1830_envisusitain= 0,
               
	       gamma_age_3040_comfort= 0, gamma_age_3040_ttr= 0, gamma_age_3040_cleanliness= 0, gamma_age_3040_staffbehaviour= 0, gamma_age_3040_envisusitain= 0,

	       gamma_age_4050_comfort= 0, gamma_age_4050_ttr= 0, gamma_age_4050_cleanliness= 0, gamma_age_4050_staffbehaviour= 0, gamma_age_4050_envisusitain= 0, 
       
               gamma_age_5060_comfort= 0, gamma_age_5060_ttr= 0, gamma_age_5060_cleanliness= 0, gamma_age_5060_staffbehaviour= 0, gamma_age_5060_envisusitain= 0, 
	      
               gamma_age_above60= 0, #fixed
               gamma_fincome_30k_comfort= 0, gamma_fincome_30k_ttr= 0, gamma_fincome_30k_cleanliness= 0, gamma_fincome_30k_staffbehaviour= 0, gamma_fincome_30k_envisusitain= 0, 
	       
               gamma_fincome_30k60k_comfort= 0, gamma_fincome_30k60k_ttr= 0, gamma_fincome_30k60k_cleanliness= 0, gamma_fincome_30k60k_staffbehaviour= 0, gamma_fincome_30k60k_envisusitain= 0, 

 	       gamma_fincome_60k90k_comfort= 0, gamma_fincome_60k90k_ttr= 0, gamma_fincome_60k90k_cleanliness= 0, gamma_fincome_60k90k_staffbehaviour= 0, gamma_fincome_60k90k_envisusitain= 0, 
               
               gamma_fincome_90k120k_comfort= 0, gamma_fincome_90k120k_ttr= 0, gamma_fincome_90k120k_cleanliness= 0, gamma_fincome_90k120k_staffbehaviour= 0, gamma_fincome_90k120k_envisusitain= 0,
               
               gamma_fincome_120k150k_comfort= 0, gamma_fincome_120k150k_ttr= 0, gamma_fincome_120k150k_cleanliness= 0, gamma_fincome_120k150k_staffbehaviour= 0, gamma_fincome_120k150k_envisusitain= 0,
                                                        
	       gamma_fincome_150k= 0, #fixed
             
               # Trip attributes
               b_tt_pv= -0.403, b_tt_pt= 0, 
               b_tc_pv= 0.008, b_tc_pt= 0, 
               
               # Latent variables and thresholds in SEM component
               zeta_comfort1= 1, zeta_comfort2= 1, zeta_comfort3= 1, zeta_comfort4= 1,
               zeta_ttr1= 1, zeta_ttr2= 1, zeta_ttr3= 1,
               zeta_cleanliness1= 1, zeta_cleanliness2= 1,
	       zeta_staffbehaviour1= 1, zeta_staffbehaviour2= 1,
               zeta_envisusitain1= 1, zeta_envisusitain2= 1,
              
               tau_comfort1_1= -2, tau_comfort1_2= -1, tau_comfort1_3= 1, 
               tau_comfort2_1= -2, tau_comfort2_2= -1, tau_comfort2_3= 1, tau_comfort2_4= 2,
               tau_comfort3_1= -2, tau_comfort3_2= -1, tau_comfort3_3= 1,
               tau_comfort4_1= -2, tau_comfort4_2= -1, tau_comfort4_3= 1,
               tau_ttr1_1= -2, tau_ttr1_2= -1, tau_ttr1_3= 1, 
               tau_ttr2_1= -2, tau_ttr2_2= -1, tau_ttr2_3= 1,
               tau_ttr3_1= -1, tau_ttr3_2= 1,
               tau_cleanliness1_1= -1, tau_cleanliness1_2= 1,
               tau_cleanliness2_1= -2, tau_cleanliness2_2= -1, tau_cleanliness2_3= 1,
               tau_staffbehaviour1_1= -2, tau_staffbehaviour1_2= -1, tau_staffbehaviour1_3= 1, tau_staffbehaviour1_4= 2,
               tau_staffbehaviour2_1= -2, tau_staffbehaviour2_2= -1, tau_staffbehaviour2_3= 1, tau_staffbehaviour2_4= 2,
               tau_envisusitain1_1= -1, tau_envisusitain1_2= 1,
               tau_envisusitain2_1= -2, tau_envisusitain2_2= -1, tau_envisusitain2_3= 1,                            
             
               # Latent variables in choice model component
               lambda_comfort=0, 
               lambda_ttr=0, 
               lambda_cleanliness=0, 
               lambda_staffbehaviour=0, 
               lambda_envisusitain=0, 


               # ETA
               eta1= 0, eta2= 0, eta3= 0, eta4= 0, eta6= 0
               )

## Parameters to be kept FIXED

apollo_fixed= c("asc_pt", 'gamma_age_above60', 'gamma_fincome_150k')


## Group and Validate Inputs

apollo_inputs= apollo_validateInputs()

## Model Definition 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 Random LVs
  
	comfort= gamma_female_comfort*female + gamma_age_under18_comfort*(age==1) + gamma_age_1830_comfort*(age==2) + gamma_age_3040_comfort*(age==3) + gamma_age_4050_comfort*(age==4) + gamma_age_5060_comfort*(age==5) + gamma_fincome_30k_comfort*(fincome==1) + gamma_fincome_30k60k_comfort*(fincome==2) + gamma_fincome_60k90k_comfort*(fincome==3) + gamma_fincome_90k120k_comfort*(fincome==4) + gamma_fincome_120k150k_comfort*(fincome==5) + eta1 
       ttr= gamma_female_ttr*female + gamma_age_under18_ttr*(age==1) + gamma_age_1830_ttr*(age==2) + gamma_age_3040_ttr*(age==3) + gamma_age_4050_ttr*(age==4) + gamma_age_5060_ttr*(age==5) + gamma_fincome_30k_ttr*(fincome==1) + gamma_fincome_30k60k_ttr*(fincome==2) + gamma_fincome_60k90k_ttr*(fincome==3) + gamma_fincome_90k120k_ttr*(fincome==4) + gamma_fincome_120k150k_ttr*(fincome==5) + eta2
        cleanliness= gamma_female_cleanliness*female + gamma_age_under18_cleanliness*(age==1) + gamma_age_1830_cleanliness*(age==2) + gamma_age_3040_cleanliness*(age==3) + gamma_age_4050_cleanliness*(age==4) + gamma_age_5060_cleanliness*(age==5) + gamma_fincome_30k_cleanliness*(fincome==1) + gamma_fincome_30k60k_cleanliness*(fincome==2) + gamma_fincome_60k90k_cleanliness*(fincome==3) + gamma_fincome_90k120k_cleanliness*(fincome==4) + gamma_fincome_120k150k_cleanliness*(fincome==5) + eta3
        staffbehaviour= gamma_female_staffbehaviour*female + gamma_age_under18_staffbehaviour*(age==1) + gamma_age_1830_staffbehaviour*(age==2) + gamma_age_3040_staffbehaviour*(age==3) + gamma_age_4050_staffbehaviour*(age==4) + gamma_age_5060_staffbehaviour*(age==5) + gamma_fincome_30k_staffbehaviour*(fincome==1) + gamma_fincome_30k60k_staffbehaviour*(fincome==2) + gamma_fincome_60k90k_staffbehaviour*(fincome==3) + gamma_fincome_90k120k_staffbehaviour*(fincome==4) + gamma_fincome_120k150k_staffbehaviour*(fincome==5) + eta4
       envisusitain= gamma_female_envisusitain*female + gamma_age_under18_envisusitain*(age==1) + gamma_age_1830_envisusitain*(age==2) + gamma_age_3040_envisusitain*(age==3) + gamma_age_4050_envisusitain*(age==4) + gamma_age_5060_envisusitain*(age==5) + gamma_fincome_30k_envisusitain*(fincome==1) + gamma_fincome_30k60k_envisusitain*(fincome==2) + gamma_fincome_60k90k_envisusitain*(fincome==3) + gamma_fincome_90k120k_envisusitain*(fincome==4) + gamma_fincome_120k150k_envisusitain*(fincome==5) + eta6
       
  # Creating list of probabilities P
  
  P= list()
  
  ## Likelihood of Choices
  ## List of utilities 
  
  V= list()

  V[['pv']]= (asc_pv + b_tt_pv*tt_pv + b_tc_pv*tc_mpv +  
                    lambda_comfort*comfort + lambda_ttr*ttr + lambda_cleanliness*cleanliness + lambda_staffbehaviour*staffbehaviour + lambda_envisusitain*envisusitain)
                    
  V[['pt']]= (asc_pt + b_tt_pt*tt_pt + b_tc_pt*tc_mpt + 
                    lambda_comfort*comfort + lambda_ttr*ttr + lambda_cleanliness*cleanliness + lambda_staffbehaviour*staffbehaviour + lambda_envisusitain*envisusitain)
 
    ## Settings for MNL model component
  
  mnl_settings= list(
    alternatives= c(pv=1, pt=2),
    avail= list(pv=av_pv, pt=av_pt),
    choiceVar= mode,
    V= V
  )
  
  ## Computing probabilities for MNL model component
  
  P[["choice"]]= apollo_mnl(mnl_settings, functionality)
  
  # Likelihood of indicators to the LVs
  
  ol_settings1= list(outcomeOrdered= comfort1,
                     V= zeta_comfort1*comfort,
                     tau= list(tau_comfort1_1, tau_comfort1_2, tau_comfort1_3),
                     rows=comfort1!=0)
  ol_settings2= list(outcomeOrdered= comfort2,
                     V= zeta_comfort2*comfort,
                     tau= list(tau_comfort2_1, tau_comfort2_2, tau_comfort2_3, tau_comfort2_4),
                     rows=comfort2!=0)
  ol_settings3= list(outcomeOrdered= comfort3,
                     V= zeta_comfort3*comfort,
                     tau= list(tau_comfort3_1, tau_comfort3_2, tau_comfort3_3),
                     rows=comfort3!=0)
  ol_settings4= list(outcomeOrdered= comfort4,
                     V= zeta_comfort4*comfort,
                     tau= list(tau_comfort4_1, tau_comfort4_2, tau_comfort4_3),
                     rows=comfort4!=0)
  ol_settings5= list(outcomeOrdered= ttr1,
                     V= zeta_ttr1*ttr,
                     tau= list(tau_ttr1_1, tau_ttr1_2, tau_ttr1_3),
                     rows=ttr1!=0)
  ol_settings6= list(outcomeOrdered= ttr2,
                     V= zeta_ttr2*ttr,
                     tau= list(tau_ttr2_1, tau_ttr2_2, tau_ttr2_3),
                     rows=ttr2!=0)
  ol_settings7= list(outcomeOrdered= ttr3,
                     V= zeta_ttr3*ttr,
                     tau= list(tau_ttr3_1, tau_ttr3_2),
                     rows=ttr3!=0)
  ol_settings8= list(outcomeOrdered= cleanliness1,
                     V= zeta_cleanliness1*cleanliness,
                     tau= list(tau_cleanliness1_1, tau_cleanliness1_2),
                     rows=cleanliness1!=0)
  ol_settings9= list(outcomeOrdered= cleanliness2,
                     V= zeta_cleanliness2*cleanliness,
                     tau= list(tau_cleanliness2_1, tau_cleanliness2_2, tau_cleanliness2_3),
                     rows=cleanliness2!=0)
  ol_settings10= list(outcomeOrdered= staffbehaviour1,
                     V= zeta_staffbehaviour1*staffbehaviour,
                     tau= list(tau_staffbehaviour1_1, tau_staffbehaviour1_2, tau_staffbehaviour1_3, tau_staffbehaviour1_4),
                     rows=staffbehaviour1!=0)
  ol_settings11= list(outcomeOrdered= staffbehaviour2,
                     V= zeta_staffbehaviour2*staffbehaviour,
                     tau= list(tau_staffbehaviour2_1, tau_staffbehaviour2_2, tau_staffbehaviour2_3, tau_staffbehaviour2_4),
                     rows=staffbehaviour2!=0)
   ol_settings14= list(outcomeOrdered= envisusitain1,
                     V= zeta_envisusitain1*envisusitain,
                     tau= list(tau_envisusitain1_1, tau_envisusitain1_2),
                     rows=envisusitain1!=0)
  ol_settings15= list(outcomeOrdered= envisusitain2,
                     V= zeta_envisusitain2*envisusitain,
                     tau= list(tau_envisusitain2_1, tau_envisusitain2_2, tau_envisusitain2_3),
                     rows=envisusitain2!=0)
 
  
  P[["indic_comfort1"]]= apollo_ol(ol_settings1, functionality)
  P[["indic_comfort2"]]= apollo_ol(ol_settings2, functionality)
  P[["indic_comfort3"]]= apollo_ol(ol_settings3, functionality)
  P[["indic_comfort4"]]= apollo_ol(ol_settings4, functionality)
  P[["indic_ttr1"]]= apollo_ol(ol_settings5, functionality)
  P[["indic_ttr2"]]= apollo_ol(ol_settings6, functionality)
  P[["indic_ttr3"]]= apollo_ol(ol_settings7, functionality)
  P[["indic_cleanliness1"]]= apollo_ol(ol_settings8, functionality)
  P[["indic_cleanliness2"]]= apollo_ol(ol_settings9, functionality)
  P[["indic_staffbehaviour1"]]= apollo_ol(ol_settings10, functionality)
  P[["indic_staffbehaviour2"]]= apollo_ol(ol_settings11, functionality)
  P[["indic_envisusitain1"]]= apollo_ol(ol_settings14, functionality)
  P[["indic_envisusitain2"]]= apollo_ol(ol_settings15, functionality)
 
   
  ## Likelihood of the whole combined model
  
  P= apollo_combineModels(P, apollo_inputs, functionality)
    
  ## Prepare and return the outputs of the function
  
  P= apollo_prepareProb(P, apollo_inputs, functionality)
  
  return(P)
}

L <- apollo_probabilities(apollo_beta, apollo_inputs, 'estimate')									
## Model Estimation

# Likelihood 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 Output

## apollo_modelOutput(model)

apollo_saveOutput(model)

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

Re: Error in ICLV estimation: "Estimation Failed. No covariance matrix to compute."

Post by stephanehess »

Hi

we cannot really help without seeing results/outputs

But your model does not seem to be an ICLV model anyway as you're not using any random components. Did you look at the examples online?

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
janak12_jp
Posts: 16
Joined: 08 Sep 2021, 16:52

Re: Error in ICLV estimation: "Estimation Failed. No covariance matrix to compute."

Post by janak12_jp »

Hi Stephen,

Thank you for the reply. Sorry for posting different code. Please review this code.
I could handle previous one. But the error seems to be different now.

Error in apollo_checkArguments(apollo_probabilities, apollo_randCoeff, :
SYNTAX ISSUE - The arguments for apollo_randCoeff need to be apollo_beta and apollo_inputs
In addition: Warning message:
In names(arguments) == c("apollo_beta", "apollo_inputs") :
longer object length is not a multiple of shorter object length

Code: Select all

## Initialization

rm(list=ls())
library(apollo)
apollo_initialise()

## Set Core Controls

apollo_control= list(
  modelName= "ICLV",
  modelDescr= "Mode choice with latent variable",
  indivID= "ID"
)

## Load database

database= read.csv("~iclvdata-2.csv", header=T)

## Parameter operations

database$orgbus= database$orgbus / 100
database$desbus= database$desbus / 100
database$tc_mpv= database$tc_mpv / 1000
database$tc_mpt= database$tc_mpt / 1000
database$tt_pv= database$tt_pv / 10
database$tt_pt= database$tt_pt / 10

## Definition of Model Parameters
### Vector of Parameters to be estimated

apollo_beta= c(# Alternate Specific Constants
  asc_pv= -1.029,
  asc_pt= 0,
  
  
  # Social-Economic parameters
  gamma_female_comfort= 0, gamma_female_ttr= 0, gamma_female_cleanliness= 0, gamma_female_staffbehaviour= 0, gamma_female_envisusitain= 0, 
  
  gamma_age_under18_comfort= 0, gamma_age_under18_ttr= 0, gamma_age_under18_cleanliness= 0, gamma_age_under18_staffbehaviour= 0, gamma_age_under18_envisusitain= 0, 
  
  gamma_age_1830_comfort= 0, gamma_age_1830_ttr= 0, gamma_age_1830_cleanliness= 0, gamma_age_1830_staffbehaviour= 0, gamma_age_1830_envisusitain= 0,
  
  gamma_age_3040_comfort= 0, gamma_age_3040_ttr= 0, gamma_age_3040_cleanliness= 0, gamma_age_3040_staffbehaviour= 0, gamma_age_3040_envisusitain= 0,
  
  gamma_age_4050_comfort= 0, gamma_age_4050_ttr= 0, gamma_age_4050_cleanliness= 0, gamma_age_4050_staffbehaviour= 0, gamma_age_4050_envisusitain= 0, 
  
  gamma_age_5060_comfort= 0, gamma_age_5060_ttr= 0, gamma_age_5060_cleanliness= 0, gamma_age_5060_staffbehaviour= 0, gamma_age_5060_envisusitain= 0, 
  
  gamma_age_above60= 0, #fixed
  
  gamma_fincome_30k_comfort= 0, gamma_fincome_30k_ttr= 0, gamma_fincome_30k_cleanliness= 0, gamma_fincome_30k_staffbehaviour= 0, gamma_fincome_30k_envisusitain= 0, 
  
  gamma_fincome_30k60k_comfort= 0, gamma_fincome_30k60k_ttr= 0, gamma_fincome_30k60k_cleanliness= 0, gamma_fincome_30k60k_staffbehaviour= 0, gamma_fincome_30k60k_envisusitain= 0, 
  
  gamma_fincome_60k90k_comfort= 0, gamma_fincome_60k90k_ttr= 0, gamma_fincome_60k90k_cleanliness= 0, gamma_fincome_60k90k_staffbehaviour= 0, gamma_fincome_60k90k_envisusitain= 0, 
  
  gamma_fincome_90k120k_comfort= 0, gamma_fincome_90k120k_ttr= 0, gamma_fincome_90k120k_cleanliness= 0, gamma_fincome_90k120k_staffbehaviour= 0, gamma_fincome_90k120k_envisusitain= 0,
  
  gamma_fincome_120k150k_comfort= 0, gamma_fincome_120k150k_ttr= 0, gamma_fincome_120k150k_cleanliness= 0, gamma_fincome_120k150k_staffbehaviour= 0, gamma_fincome_120k150k_envisusitain= 0,
  
  gamma_fincome_150k= 0, #fixed
  
  # Trip attributes
  b_tt_pv= -0.403, b_tt_pt= 0, 
  b_tc_pv= 0.008, b_tc_pt= 0,
  
  # Latent variables and thresholds in SEM component
  zeta_comfort1= 1, zeta_comfort2= 1, zeta_comfort3= 1, zeta_comfort4= 1,
  zeta_ttr1= 1, zeta_ttr2= 1, zeta_ttr3= 1,
  zeta_cleanliness1= 1, zeta_cleanliness2= 1,
  zeta_staffbehaviour1= 1, zeta_staffbehaviour2= 1,
  zeta_envisusitain1= 1, zeta_envisusitain2= 1,
  
  tau_comfort1_1= -2, tau_comfort1_2= -1, tau_comfort1_3= 1, 
  tau_comfort2_1= -2, tau_comfort2_2= -1, tau_comfort2_3= 1, tau_comfort2_4= 2,
  tau_comfort3_1= -2, tau_comfort3_2= -1, tau_comfort3_3= 1,
  tau_comfort4_1= -2, tau_comfort4_2= -1, tau_comfort4_3= 1,
  tau_ttr1_1= -2, tau_ttr1_2= -1, tau_ttr1_3= 1, 
  tau_ttr2_1= -2, tau_ttr2_2= -1, tau_ttr2_3= 1,
  tau_ttr3_1= -1, tau_ttr3_2= 1,
  tau_cleanliness1_1= -1, tau_cleanliness1_2= 1,
  tau_cleanliness2_1= -2, tau_cleanliness2_2= -1, tau_cleanliness2_3= 1,
  tau_staffbehaviour1_1= -2, tau_staffbehaviour1_2= -1, tau_staffbehaviour1_3= 1, tau_staffbehaviour1_4= 2,
  tau_staffbehaviour2_1= -2, tau_staffbehaviour2_2= -1, tau_staffbehaviour2_3= 1, tau_staffbehaviour2_4= 2,
  tau_envisusitain1_1= -1, tau_envisusitain1_2= 1,
  tau_envisusitain2_1= -2, tau_envisusitain2_2= -1, tau_envisusitain2_3= 1,                            
  
  # Latent variables in choice model component
  lambda_comfort=1, 
  lambda_ttr=1, 
  lambda_cleanliness=1, 
  lambda_staffbehaviour=1, 
  lambda_envisusitain=1 
  
)

## Parameters to be kept FIXED

apollo_fixed= c("asc_pt", 'gamma_age_above60', 'gamma_fincome_150k')
apollo_draws = list(
  interDrawsType="halton", 
  interNDraws=500,          
  interUnifDraws=c(),      
  interNormDraws=c("eta1", "eta2", "eta3", "eta4", "eta5"), 
  
  intraDrawsType="",
  intraNDraws=0,          
  intraUnifDraws=c(),     
  intraNormDraws=c()      
)
# Create Random LVs

apollo_randCoeff=function(apollo_beta, apollo_inputs, functionality= "estimate"){
  randcoeff = list()  
  
  randcoeff[["comfort"]]= gamma_female_comfort*female + gamma_age_under18_comfort*(age==1) + gamma_age_1830_comfort*(age==2) + gamma_age_3040_comfort*(age==3) + gamma_age_4050_comfort*(age==4) + gamma_age_5060_comfort*(age==5) + gamma_fincome_30k_comfort*(fincome==1) + gamma_fincome_30k60k_comfort*(fincome==2) + gamma_fincome_60k90k_comfort*(fincome==3) + gamma_fincome_90k120k_comfort*(fincome==4) + gamma_fincome_120k150k_comfort*(fincome==5) + eta1 
  randcoeff[["ttr"]]= gamma_female_ttr*female + gamma_age_under18_ttr*(age==1) + gamma_age_1830_ttr*(age==2) + gamma_age_3040_ttr*(age==3) + gamma_age_4050_ttr*(age==4) + gamma_age_5060_ttr*(age==5) + gamma_fincome_30k_ttr*(fincome==1) + gamma_fincome_30k60k_ttr*(fincome==2) + gamma_fincome_60k90k_ttr*(fincome==3) + gamma_fincome_90k120k_ttr*(fincome==4) + gamma_fincome_120k150k_ttr*(fincome==5) + eta2
  randcoeff[["cleanliness"]]= gamma_female_cleanliness*female + gamma_age_under18_cleanliness*(age==1) + gamma_age_1830_cleanliness*(age==2) + gamma_age_3040_cleanliness*(age==3) + gamma_age_4050_cleanliness*(age==4) + gamma_age_5060_cleanliness*(age==5) + gamma_fincome_30k_cleanliness*(fincome==1) + gamma_fincome_30k60k_cleanliness*(fincome==2) + gamma_fincome_60k90k_cleanliness*(fincome==3) + gamma_fincome_90k120k_cleanliness*(fincome==4) + gamma_fincome_120k150k_cleanliness*(fincome==5) + eta3
  randcoeff[["staffbehaviour"]]= gamma_female_staffbehaviour*female + gamma_age_under18_staffbehaviour*(age==1) + gamma_age_1830_staffbehaviour*(age==2) + gamma_age_3040_staffbehaviour*(age==3) + gamma_age_4050_staffbehaviour*(age==4) + gamma_age_5060_staffbehaviour*(age==5) + gamma_fincome_30k_staffbehaviour*(fincome==1) + gamma_fincome_30k60k_staffbehaviour*(fincome==2) + gamma_fincome_60k90k_staffbehaviour*(fincome==3) + gamma_fincome_90k120k_staffbehaviour*(fincome==4) + gamma_fincome_120k150k_staffbehaviour*(fincome==5) + eta4
  randcoeff[["envisusitain"]]= gamma_female_envisusitain*female + gamma_age_under18_envisusitain*(age==1) + gamma_age_1830_envisusitain*(age==2) + gamma_age_3040_envisusitain*(age==3) + gamma_age_4050_envisusitain*(age==4) + gamma_age_5060_envisusitain*(age==5) + gamma_fincome_30k_envisusitain*(fincome==1) + gamma_fincome_30k60k_envisusitain*(fincome==2) + gamma_fincome_60k90k_envisusitain*(fincome==3) + gamma_fincome_90k120k_envisusitain*(fincome==4) + gamma_fincome_120k150k_envisusitain*(fincome==5) + eta5
  
  
  return(randcoeff)
}

## Group and Validate Inputs

apollo_inputs= apollo_validateInputs()

## Model Definition 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))
  
  
  # Creating list of probabilities P
  
  P = list()
  
  # Likelihood of indicators to the LVs
  
  ol_settings1= list(outcomeOrdered= comfort1,
                     V= zeta_comfort1*comfort,
                     tau= list(tau_comfort1_1, tau_comfort1_2, tau_comfort1_3),
                     rows=comfort1!=0)
  ol_settings2= list(outcomeOrdered= comfort2,
                     V= zeta_comfort2*comfort,
                     tau= list(tau_comfort2_1, tau_comfort2_2, tau_comfort2_3, tau_comfort2_4),
                     rows=comfort2!=0)
  ol_settings3= list(outcomeOrdered= comfort3,
                     V= zeta_comfort3*comfort,
                     tau= list(tau_comfort3_1, tau_comfort3_2, tau_comfort3_3),
                     rows=comfort3!=0)
  ol_settings4= list(outcomeOrdered= comfort4,
                     V= zeta_comfort4*comfort,
                     tau= list(tau_comfort4_1, tau_comfort4_2, tau_comfort4_3),
                     rows=comfort4!=0)
  ol_settings5= list(outcomeOrdered= ttr1,
                     V= zeta_ttr1*ttr,
                     tau= list(tau_ttr1_1, tau_ttr1_2, tau_ttr1_3),
                     rows=ttr1!=0)
  ol_settings6= list(outcomeOrdered= ttr2,
                     V= zeta_ttr2*ttr,
                     tau= list(tau_ttr2_1, tau_ttr2_2, tau_ttr2_3),
                     rows=ttr2!=0)
  ol_settings7= list(outcomeOrdered= ttr3,
                     V= zeta_ttr3*ttr,
                     tau= list(tau_ttr3_1, tau_ttr3_2),
                     rows=ttr3!=0)
  ol_settings8= list(outcomeOrdered= cleanliness1,
                     V= zeta_cleanliness1*cleanliness,
                     tau= list(tau_cleanliness1_1, tau_cleanliness1_2),
                     rows=cleanliness1!=0)
  ol_settings9= list(outcomeOrdered= cleanliness2,
                     V= zeta_cleanliness2*cleanliness,
                     tau= list(tau_cleanliness2_1, tau_cleanliness2_2, tau_cleanliness2_3),
                     rows=cleanliness2!=0)
  ol_settings10= list(outcomeOrdered= staffbehaviour1,
                      V= zeta_staffbehaviour1*staffbehaviour,
                      tau= list(tau_staffbehaviour1_1, tau_staffbehaviour1_2, tau_staffbehaviour1_3, tau_staffbehaviour1_4),
                      rows=staffbehaviour1!=0)
  ol_settings11= list(outcomeOrdered= staffbehaviour2,
                      V= zeta_staffbehaviour2*staffbehaviour,
                      tau= list(tau_staffbehaviour2_1, tau_staffbehaviour2_2, tau_staffbehaviour2_3, tau_staffbehaviour2_4),
                      rows=staffbehaviour2!=0)
  ol_settings14= list(outcomeOrdered= envisusitain1,
                      V= zeta_envisusitain1*envisusitain,
                      tau= list(tau_envisusitain1_1, tau_envisusitain1_2),
                      rows=envisusitain1!=0)
  ol_settings15= list(outcomeOrdered= envisusitain2,
                      V= zeta_envisusitain2*envisusitain,
                      tau= list(tau_envisusitain2_1, tau_envisusitain2_2, tau_envisusitain2_3),
                      rows=envisusitain2!=0)
  
  
  P[["indic_comfort1"]]= apollo_ol(ol_settings1, functionality)
  P[["indic_comfort2"]]= apollo_ol(ol_settings2, functionality)
  P[["indic_comfort3"]]= apollo_ol(ol_settings3, functionality)
  P[["indic_comfort4"]]= apollo_ol(ol_settings4, functionality)
  P[["indic_ttr1"]]= apollo_ol(ol_settings5, functionality)
  P[["indic_ttr2"]]= apollo_ol(ol_settings6, functionality)
  P[["indic_ttr3"]]= apollo_ol(ol_settings7, functionality)
  P[["indic_cleanliness1"]]= apollo_ol(ol_settings8, functionality)
  P[["indic_cleanliness2"]]= apollo_ol(ol_settings9, functionality)
  P[["indic_staffbehaviour1"]]= apollo_ol(ol_settings10, functionality)
  P[["indic_staffbehaviour2"]]= apollo_ol(ol_settings11, functionality)
  P[["indic_envisusitain1"]]= apollo_ol(ol_settings14, functionality)
  P[["indic_envisusitain2"]]= apollo_ol(ol_settings15, functionality)
  
  ## List of utilities 
  
  V= list()
  
  V[['pv']]= (asc_pv + b_tt_pv*tt_pv + b_tc_pv*tc_mpv +  
                lambda_comfort*comfort + lambda_ttr*ttr + lambda_cleanliness*cleanliness + lambda_staffbehaviour*staffbehaviour + lambda_envisusitain*envisusitain)
  
  V[['pt']]= (asc_pt + b_tt_pt*tt_pt + b_tc_pt*tc_mpt + 
                lambda_comfort*comfort + lambda_ttr*ttr + lambda_cleanliness*cleanliness + lambda_staffbehaviour*staffbehaviour + lambda_envisusitain*envisusitain)
  
  ## Settings for MNL model component
  
  mnl_settings= list(
    alternatives= c(pv=1, pt=2),
    avail= list(pv=av_pv, pt=av_pt),
    choiceVar= mode,
    V= V
  )
  ### Compute probabilities for MNL model component
  
  P[["choice"]] = apollo_mnl(mnl_settings, functionality)
  
  ## Likelihood of the whole combined model
  
  P= apollo_combineModels(P, apollo_inputs, functionality)
  
  ### Average across inter-individual draws
  P = apollo_avgInterDraws(P, apollo_inputs, functionality)
  
  ## Prepare and return the outputs of the function
  
  P= apollo_prepareProb(P, apollo_inputs, functionality)
  
  return(P)
}

L <- apollo_probabilities(apollo_beta, apollo_inputs, 'estimate')									
## Model Estimation

# Likelihood 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 Output

## apollo_modelOutput(model)

apollo_saveOutput(model)

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

Re: Error in ICLV estimation: "Estimation Failed. No covariance matrix to compute."

Post by stephanehess »

Hi

please have a look at the example files and the manual. You have changed the syntax.

You have

Code: Select all

apollo_randCoeff=function(apollo_beta, apollo_inputs, functionality= "estimate")
instead of

Code: Select all

apollo_randCoeff = function(apollo_beta, apollo_inputs)
Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
janak12_jp
Posts: 16
Joined: 08 Sep 2021, 16:52

Re: Error in ICLV estimation: "Estimation Failed. No covariance matrix to compute."

Post by janak12_jp »

Hi, Stephane
Thank you for addressing the issue.
However, the error still persist:

Error in apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, :
SPECIFICATION ISSUE - Parameter lambda_comfort does not influence the log-likelihood of your model!

When I remove related specification, the error jumps to next latent variable.

Here is the code:

Code: Select all


## Initialization

rm(list=ls())
library(apollo)
apollo_initialise()

## Set Core Controls

apollo_control= list(
  modelName= "ICLV",
  modelDescr= "Mode choice with latent variable",
  indivID= "ID"
)

## Load database

database= read.csv("C:/Users/janak/Desktop/iclvdata-2.csv", header=T)

## Parameter operations

database$orgbus= database$orgbus / 100
database$desbus= database$desbus / 100
database$tc_mpv= database$tc_mpv / 1000
database$tc_mpt= database$tc_mpt / 1000
database$tt_pv= database$tt_pv / 10
database$tt_pt= database$tt_pt / 10

## Definition of Model Parameters
### Vector of Parameters to be estimated

apollo_beta= c(# Alternate Specific Constants
  asc_pv= 0,
  asc_pt= -1,
  
  
  # Social-Economic parameters
  gamma_female_comfort= 0, gamma_female_ttr= 0, gamma_female_cleanliness= 0, gamma_female_staffbehaviour= 0, gamma_female_envisusitain= 0, 
  
  gamma_age_under18_comfort= 0, gamma_age_under18_ttr= 0, gamma_age_under18_cleanliness= 0, gamma_age_under18_staffbehaviour= 0, gamma_age_under18_envisusitain= 0, 
  
  gamma_age_1830_comfort= 0, gamma_age_1830_ttr= 0, gamma_age_1830_cleanliness= 0, gamma_age_1830_staffbehaviour= 0, gamma_age_1830_envisusitain= 0,
  
  gamma_age_3040_comfort= 0, gamma_age_3040_ttr= 0, gamma_age_3040_cleanliness= 0, gamma_age_3040_staffbehaviour= 0, gamma_age_3040_envisusitain= 0,
  
  gamma_age_4050_comfort= 0, gamma_age_4050_ttr= 0, gamma_age_4050_cleanliness= 0, gamma_age_4050_staffbehaviour= 0, gamma_age_4050_envisusitain= 0, 
  
  gamma_age_5060_comfort= 0, gamma_age_5060_ttr= 0, gamma_age_5060_cleanliness= 0, gamma_age_5060_staffbehaviour= 0, gamma_age_5060_envisusitain= 0, 
  
  gamma_age_above60= 0, #fixed
  
  gamma_fincome_30k_comfort= 0, gamma_fincome_30k_ttr= 0, gamma_fincome_30k_cleanliness= 0, gamma_fincome_30k_staffbehaviour= 0, gamma_fincome_30k_envisusitain= 0, 
  
  gamma_fincome_30k60k_comfort= 0, gamma_fincome_30k60k_ttr= 0, gamma_fincome_30k60k_cleanliness= 0, gamma_fincome_30k60k_staffbehaviour= 0, gamma_fincome_30k60k_envisusitain= 0, 
  
  gamma_fincome_60k90k_comfort= 0, gamma_fincome_60k90k_ttr= 0, gamma_fincome_60k90k_cleanliness= 0, gamma_fincome_60k90k_staffbehaviour= 0, gamma_fincome_60k90k_envisusitain= 0, 
  
  gamma_fincome_90k120k_comfort= 0, gamma_fincome_90k120k_ttr= 0, gamma_fincome_90k120k_cleanliness= 0, gamma_fincome_90k120k_staffbehaviour= 0, gamma_fincome_90k120k_envisusitain= 0,
  
  gamma_fincome_120k150k_comfort= 0, gamma_fincome_120k150k_ttr= 0, gamma_fincome_120k150k_cleanliness= 0, gamma_fincome_120k150k_staffbehaviour= 0, gamma_fincome_120k150k_envisusitain= 0,
  
  gamma_fincome_150k= 0, #fixed
  
  # Trip attributes
  b_tt_pv= -0.403, b_tt_pt= 0, 
  b_tc_pv= 0.008, b_tc_pt= 0,
  
  # Latent variables and thresholds in SEM component
  zeta_comfort1= 1, zeta_comfort2= 1, zeta_comfort3= 1, zeta_comfort4= 1,
  zeta_ttr1= 1, zeta_ttr2= 1, zeta_ttr3= 1,
  zeta_cleanliness1= 1, zeta_cleanliness2= 1,
  zeta_staffbehaviour1= 1, zeta_staffbehaviour2= 1,
  zeta_envisusitain1= 1, zeta_envisusitain2= 1,
  
  tau_comfort1_1= -2, tau_comfort1_2= -1, tau_comfort1_3= 1, 
  tau_comfort2_1= -2, tau_comfort2_2= -1, tau_comfort2_3= 1, tau_comfort2_4= 2,
  tau_comfort3_1= -2, tau_comfort3_2= -1, tau_comfort3_3= 1,
  tau_comfort4_1= -2, tau_comfort4_2= -1, tau_comfort4_3= 1,
  tau_ttr1_1= -2, tau_ttr1_2= -1, tau_ttr1_3= 1, 
  tau_ttr2_1= -2, tau_ttr2_2= -1, tau_ttr2_3= 1,
  tau_ttr3_1= -1, tau_ttr3_2= 1,
  tau_cleanliness1_1= -1, tau_cleanliness1_2= 1,
  tau_cleanliness2_1= -2, tau_cleanliness2_2= -1, tau_cleanliness2_3= 1,
  tau_staffbehaviour1_1= -2, tau_staffbehaviour1_2= -1, tau_staffbehaviour1_3= 1, tau_staffbehaviour1_4= 2,
  tau_staffbehaviour2_1= -2, tau_staffbehaviour2_2= -1, tau_staffbehaviour2_3= 1, tau_staffbehaviour2_4= 2,
  tau_envisusitain1_1= -1, tau_envisusitain1_2= 1,
  tau_envisusitain2_1= -2, tau_envisusitain2_2= -1, tau_envisusitain2_3= 1,                            
  
  # Latent variables in choice model component
  lambda_comfort=0.1, 
  lambda_ttr=0.1, 
  lambda_cleanliness=0.1, 
  lambda_staffbehaviour=0.1, 
  lambda_envisusitain=0.1 
)

## Parameters to be kept FIXED

apollo_fixed= c("asc_pv", 'gamma_age_above60', 'gamma_fincome_150k')

### Set parameters for generating draws
apollo_draws = list(
  interDrawsType="halton", 
  interNDraws=500,          
  interUnifDraws=c(),      
  interNormDraws=c("eta1", "eta2", "eta3", "eta4", "eta5"), 
  
  intraDrawsType="",
  intraNDraws=0,          
  intraUnifDraws=c(),     
  intraNormDraws=c()      
)

# Create Random LVs

apollo_randCoeff=function(apollo_beta, apollo_inputs){
  randcoeff = list()  
  
  randcoeff[["comfort"]]= (gamma_female_comfort*female + gamma_age_under18_comfort*(age==1) + gamma_age_1830_comfort*(age==2) + gamma_age_3040_comfort*(age==3) + gamma_age_4050_comfort*(age==4) + gamma_age_5060_comfort*(age==5) + gamma_fincome_30k_comfort*(fincome==1) + gamma_fincome_30k60k_comfort*(fincome==2) + gamma_fincome_60k90k_comfort*(fincome==3) + gamma_fincome_90k120k_comfort*(fincome==4) + gamma_fincome_120k150k_comfort*(fincome==5) + eta1) 
  randcoeff[["ttr"]]= (gamma_female_ttr*female + gamma_age_under18_ttr*(age==1) + gamma_age_1830_ttr*(age==2) + gamma_age_3040_ttr*(age==3) + gamma_age_4050_ttr*(age==4) + gamma_age_5060_ttr*(age==5) + gamma_fincome_30k_ttr*(fincome==1) + gamma_fincome_30k60k_ttr*(fincome==2) + gamma_fincome_60k90k_ttr*(fincome==3) + gamma_fincome_90k120k_ttr*(fincome==4) + gamma_fincome_120k150k_ttr*(fincome==5) + eta2)
  randcoeff[["cleanliness"]]= (gamma_female_cleanliness*female + gamma_age_under18_cleanliness*(age==1) + gamma_age_1830_cleanliness*(age==2) + gamma_age_3040_cleanliness*(age==3) + gamma_age_4050_cleanliness*(age==4) + gamma_age_5060_cleanliness*(age==5) + gamma_fincome_30k_cleanliness*(fincome==1) + gamma_fincome_30k60k_cleanliness*(fincome==2) + gamma_fincome_60k90k_cleanliness*(fincome==3) + gamma_fincome_90k120k_cleanliness*(fincome==4) + gamma_fincome_120k150k_cleanliness*(fincome==5) + eta3)
  randcoeff[["staffbehaviour"]]= (gamma_female_staffbehaviour*female + gamma_age_under18_staffbehaviour*(age==1) + gamma_age_1830_staffbehaviour*(age==2) + gamma_age_3040_staffbehaviour*(age==3) + gamma_age_4050_staffbehaviour*(age==4) + gamma_age_5060_staffbehaviour*(age==5) + gamma_fincome_30k_staffbehaviour*(fincome==1) + gamma_fincome_30k60k_staffbehaviour*(fincome==2) + gamma_fincome_60k90k_staffbehaviour*(fincome==3) + gamma_fincome_90k120k_staffbehaviour*(fincome==4) + gamma_fincome_120k150k_staffbehaviour*(fincome==5) + eta4)
  randcoeff[["envisusitain"]]= (gamma_female_envisusitain*female + gamma_age_under18_envisusitain*(age==1) + gamma_age_1830_envisusitain*(age==2) + gamma_age_3040_envisusitain*(age==3) + gamma_age_4050_envisusitain*(age==4) + gamma_age_5060_envisusitain*(age==5) + gamma_fincome_30k_envisusitain*(fincome==1) + gamma_fincome_30k60k_envisusitain*(fincome==2) + gamma_fincome_60k90k_envisusitain*(fincome==3) + gamma_fincome_90k120k_envisusitain*(fincome==4) + gamma_fincome_120k150k_envisusitain*(fincome==5) + eta5)
  
  
  return(randcoeff)
}


## Group and Validate Inputs

apollo_inputs= apollo_validateInputs()

## Model Definition 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))
  
  # Creating list of probabilities P
  
  P= list()
  
  ## Likelihood of Choices
  ## List of utilities 
  
  V= list()
  
  V[['pv']]= (asc_pv + b_tt_pv*tt_pv + b_tc_pv*tc_mpv +  
                lambda_comfort*comfort + lambda_ttr*ttr + lambda_cleanliness*cleanliness + lambda_staffbehaviour*staffbehaviour + lambda_envisusitain*envisusitain)
  
  V[['pt']]= (asc_pt + b_tt_pt*tt_pt + b_tc_pt*tc_mpt + 
                lambda_comfort*comfort + lambda_ttr*ttr + lambda_cleanliness*cleanliness + lambda_staffbehaviour*staffbehaviour + lambda_envisusitain*envisusitain)
  
  ## Settings for MNL model component
  
  mnl_settings= list(
    alternatives= c(pv=1, pt=2),
    avail= list(pv=av_pv, pt=av_pt),
    choiceVar= mode,
    utilities = V,
    componentName = "choice"
  )
  
  
  # Likelihood of indicators to the LVs
  
  ol_settings1= list(outcomeOrdered= comfort1,
                     V= zeta_comfort1*comfort,
                     tau= list(tau_comfort1_1, tau_comfort1_2, tau_comfort1_3),
                     rows=comfort1!=0)
  ol_settings2= list(outcomeOrdered= comfort2,
                     V= zeta_comfort2*comfort,
                     tau= list(tau_comfort2_1, tau_comfort2_2, tau_comfort2_3, tau_comfort2_4),
                     rows=comfort2!=0)
  ol_settings3= list(outcomeOrdered= comfort3,
                     V= zeta_comfort3*comfort,
                     tau= list(tau_comfort3_1, tau_comfort3_2, tau_comfort3_3),
                     rows=comfort3!=0)
  ol_settings4= list(outcomeOrdered= comfort4,
                     V= zeta_comfort4*comfort,
                     tau= list(tau_comfort4_1, tau_comfort4_2, tau_comfort4_3),
                     rows=comfort4!=0)
  ol_settings5= list(outcomeOrdered= ttr1,
                     V= zeta_ttr1*ttr,
                     tau= list(tau_ttr1_1, tau_ttr1_2, tau_ttr1_3),
                     rows=ttr1!=0)
  ol_settings6= list(outcomeOrdered= ttr2,
                     V= zeta_ttr2*ttr,
                     tau= list(tau_ttr2_1, tau_ttr2_2, tau_ttr2_3),
                     rows=ttr2!=0)
  ol_settings7= list(outcomeOrdered= ttr3,
                     V= zeta_ttr3*ttr,
                     tau= list(tau_ttr3_1, tau_ttr3_2),
                     rows=ttr3!=0)
  ol_settings8= list(outcomeOrdered= cleanliness1,
                     V= zeta_cleanliness1*cleanliness,
                     tau= list(tau_cleanliness1_1, tau_cleanliness1_2),
                     rows=cleanliness1!=0)
  ol_settings9= list(outcomeOrdered= cleanliness2,
                     V= zeta_cleanliness2*cleanliness,
                     tau= list(tau_cleanliness2_1, tau_cleanliness2_2, tau_cleanliness2_3),
                     rows=cleanliness2!=0)
  ol_settings10= list(outcomeOrdered= staffbehaviour1,
                      V= zeta_staffbehaviour1*staffbehaviour,
                      tau= list(tau_staffbehaviour1_1, tau_staffbehaviour1_2, tau_staffbehaviour1_3, tau_staffbehaviour1_4),
                      rows=staffbehaviour1!=0)
  ol_settings11= list(outcomeOrdered= staffbehaviour2,
                      V= zeta_staffbehaviour2*staffbehaviour,
                      tau= list(tau_staffbehaviour2_1, tau_staffbehaviour2_2, tau_staffbehaviour2_3, tau_staffbehaviour2_4),
                      rows=staffbehaviour2!=0)
  ol_settings14= list(outcomeOrdered= envisusitain1,
                      V= zeta_envisusitain1*envisusitain,
                      tau= list(tau_envisusitain1_1, tau_envisusitain1_2),
                      rows=envisusitain1!=0)
  ol_settings15= list(outcomeOrdered= envisusitain2,
                      V= zeta_envisusitain2*envisusitain,
                      tau= list(tau_envisusitain2_1, tau_envisusitain2_2, tau_envisusitain2_3),
                      rows=envisusitain2!=0)
  
  
  P[["indic_comfort1"]]= apollo_ol(ol_settings1, functionality)
  P[["indic_comfort2"]]= apollo_ol(ol_settings2, functionality)
  P[["indic_comfort3"]]= apollo_ol(ol_settings3, functionality)
  P[["indic_comfort4"]]= apollo_ol(ol_settings4, functionality)
  P[["indic_ttr1"]]= apollo_ol(ol_settings5, functionality)
  P[["indic_ttr2"]]= apollo_ol(ol_settings6, functionality)
  P[["indic_ttr3"]]= apollo_ol(ol_settings7, functionality)
  P[["indic_cleanliness1"]]= apollo_ol(ol_settings8, functionality)
  P[["indic_cleanliness2"]]= apollo_ol(ol_settings9, functionality)
  P[["indic_staffbehaviour1"]]= apollo_ol(ol_settings10, functionality)
  P[["indic_staffbehaviour2"]]= apollo_ol(ol_settings11, functionality)
  P[["indic_envisusitain1"]]= apollo_ol(ol_settings14, functionality)
  P[["indic_envisusitain2"]]= apollo_ol(ol_settings15, functionality)
  
  
  ## Computing probabilities for MNL model component
  
  P[["choice"]]= apollo_mnl(mnl_settings, functionality)  
  
  ## Likelihood of the whole combined model
  
  P= apollo_combineModels(P, apollo_inputs, functionality)
  
  ### Average across inter-individual draws
  P = apollo_avgInterDraws(P, apollo_inputs, functionality)
  
  ## Prepare and return the outputs of the function
  
  P= apollo_prepareProb(P, apollo_inputs, functionality)
  
  return(P)
}

L <- apollo_probabilities(apollo_beta, apollo_inputs, 'estimate')									
## Model Estimation

# Likelihood 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 Output

## apollo_modelOutput(model)

apollo_saveOutput(model)

I hope this time no generic error in code!
I can send the data to your email, if require.
Thank you in advance.
stephanehess
Site Admin
Posts: 1355
Joined: 24 Apr 2020, 16:29

Re: Error in ICLV estimation: "Estimation Failed. No covariance matrix to compute."

Post by stephanehess »

Hi

well, this is quite clear. You have included

Code: Select all

lambda_comfort*comfort + lambda_ttr*ttr + lambda_cleanliness*cleanliness + lambda_staffbehaviour*staffbehaviour + lambda_envisusitain*envisusitain
in both utilities.

Remember that only differences in utility matter, so these terms will just cancel out. You need to either interact them with an attribute that is alternative-specific or with the label of the alternatives (subject to a normalisation, so in this case only include them in one alternative)

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