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.

MNL - estimation failed (singular covergence)

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
Post Reply
willyk
Posts: 1
Joined: 13 Mar 2024, 12:46

MNL - estimation failed (singular covergence)

Post by willyk »

Dear Prof. Hess,

Thank you for running this forum.

I am running an MNL to estimate the preferences for mobility packages. I have 4 unlabeled alternatives (A, B, C, D), where D is basically a status-quo option.

Right now I am facing a problem of "Estimation failed. No covariance matrix to compute"

Here is my code:

Code: Select all

# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS                       ####
# ################################################################# #

### Clear memory
rm(list = ls())

### Load Apollo library

#install.packages("apollo")
library(apollo)
### Initialise code
apollo_initialise()

#------- MNL ---------

### Set core controls
apollo_control = list(
  modelName  = "MNL MaaS Italy",
  modelDescr = "MNL MaaS Italy" ,
  indivID    = "id"
)

# ################################################################# #
# LOAD DATA AND APPLY ANY TRANSFORMATIONS                     
data<-read.csv(file.choose(),header=TRUE)
database = data

### Define settings for analysis of choice data to be conducted prior to model estimation

choiceAnalysis_settings <- list(
  alternatives = c(Va=1, Vb=2, Vc=3, Vd=4),
  avail        = list(Va=database$av_a, Vb=database$av_b, Vc=database$av_c, Vd=database$av_d),
  choiceVar    = (database$choice)
)

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

### Vector of parameters, including any that are kept fixed in estimation
### ASC bundles
apollo_beta=c(asc_a = 0,
              asc_b = 0,
              asc_c = 0,
              asc_d = 0,
              b_pt1 = 0,
              b_bs1 = 0,
              b_cs1 = 0,
              b_ss1 = 0,
              b_tx1 = 0,
              b_gym1 = 0,
              b_sv1 = 0,
              b_costm1 = 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_d")

# 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()
  
  ### Likelihood of choices
  ### List of utilities: these must use the same names as in mnl_settings, order is irrelevant
  
  V = list()
  V[["Va"]] = (asc_a + b_pt1*a_pt + b_bs1*a_bs + b_cs1*a_cs + b_ss1*a_ss + b_tx1*a_tx + b_gym1*a_gym + b_sv1*a_sv + b_costm1*a_costm)
  
  V[["Vb"]] = (asc_b + b_pt1*b_pt + b_bs1*b_bs + b_cs1*b_cs + b_ss1*b_ss + b_tx1*b_tx + b_gym1*b_gym + b_sv1*b_sv + b_costm1*b_costm)
  
  V[["Vc"]] = (asc_c + b_pt1*c_pt + b_bs1*c_bs + b_cs1*c_cs + b_ss1*c_ss + b_tx1*c_tx + b_gym1*c_gym + b_sv1*c_sv + b_costm1*c_costm)
  
  V[["Vd"]] = (asc_d)
  
  ### Define settings for MNL model component
  mnl_settings = list(
    alternatives = c(Va=1, Vb=2, Vc=3, Vd=4),
    avail        = list(Va=av_a, Vb=av_b, Vc=av_c, Vd=av_d),
    choiceVar    = choice,
    utilities    = V
  )
  
  ### Compute probabilities for MNL model component
  P[['model']] = apollo_mnl(mnl_settings, functionality)
  
  ### Take product across observation for same individual
  P = apollo_panelProd(P, apollo_inputs, functionality)
  
  ### Prepare and return outputs of function
  P = apollo_prepareProb(P, apollo_inputs, functionality)
  return(P)
}

# MODEL ESTIMATION

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

#  MODEL OUTPUTS

apollo_modelOutput(model)          

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

apollo_saveOutput(model)    
And here is the output:

Code: Select all

Preparing user-defined functions.

Testing likelihood function...

Overview of choices for MNL model component :
                                      Va      Vb      Vc      Vd
Times available                  1578.00 1578.00 1578.00 1578.00
Times chosen                      408.00  411.00  390.00  369.00
Percentage chosen overall          25.86   26.05   24.71   23.38
Percentage chosen when available   25.86   26.05   24.71   23.38


Pre-processing likelihood function...

Testing influence of parameters
Starting main estimation

BGW using analytic model derivatives supplied by caller...


Iterates will be written to: 
 D:/MaaS packages/Statistical analysis/Apollo/HCM/MNL MaaS Italy_iterations.csv    it    nf     F            RELDF    PRELDF    RELDX    MODEL stppar
     0     1 2.187572502e+03
     1     4 2.056988686e+03 5.969e-02 4.969e-02 1.00e+00   G   7.63e-15
     2     5 2.049955324e+03 3.419e-03 3.287e-03 1.19e-01   G   -7.63e-15
     3     6 2.049932700e+03 1.104e-05 1.077e-05 7.95e-03   S   -7.63e-15
     4     7 2.049932648e+03 2.499e-08 2.408e-08 1.84e-02   S   -7.63e-15
     5     8 2.049932648e+03 6.867e-11 6.803e-11 1.02e-02   S   3.71e-15

***** Singular convergence *****

Estimated parameters:
            Estimate
asc_a      -0.029227
asc_b      -0.006198
asc_c      -0.054373
asc_d       0.000000
b_pt1       0.306176
b_bs1       0.032210
b_cs1      -0.206261
b_ss1      -0.415269
b_tx1       0.050399
b_gym1      0.634462
b_sv1       0.325864
b_costm1   -0.033278

Final LL: -2049.9326

WARNING: Estimation failed. No covariance matrix to compute. 

  Current process will resume in 3 seconds unless interrupted by the user...

Calculating log-likelihood at equal shares (LL(0)) for applicable models...
Calculating log-likelihood at observed shares from estimation data (LL(c)) for applicable
  models...
Calculating LL of each model component...
Calculating other model fit measures

Your model was estimated using the BGW algorithm. Please acknowledge this by citing Bunch
  et al. (1993) - DOI 10.1145/151271.151279
> apollo_modelOutput(model)          
Model run by ASUS using Apollo 0.3.1 on R 4.3.1 for Windows.
Please acknowledge the use of Apollo by citing Hess & Palma (2019)
  DOI 10.1016/j.jocm.2019.100170
  www.ApolloChoiceModelling.com

Model name                                  : MNL MaaS Italy
Model description                           : MNL MaaS Italy
Model run at                                : 2024-03-13 14:52:03.447899
Estimation method                           : bgw
Model diagnosis                             : Singular convergence
Number of individuals                       : 263
Number of rows in database                  : 1578
Number of modelled outcomes                 : 1578

Number of cores used                        :  1 
Model without mixing

LL(start)                                   : -2187.57
LL at equal shares, LL(0)                   : -2187.57
LL at observed shares, LL(C)                : -2186.14
LL(final)                                   : -2049.93
Rho-squared vs equal shares                  :  0.0629 
Adj.Rho-squared vs equal shares              :  0.0579 
Rho-squared vs observed shares               :  0.0623 
Adj.Rho-squared vs observed shares           :  0.0586 
AIC                                         :  4121.87 
BIC                                         :  4180.87 

Estimated parameters                        : 11
Time taken (hh:mm:ss)                       :  00:00:4.57 
     pre-estimation                         :  00:00:1.25 
     estimation                             :  00:00:3.25 
     post-estimation                        :  00:00:0.07 
Iterations                                  :  5 (Singular convergence) 

Unconstrained optimisation.

Estimates:
            Estimate        s.e.   t.rat.(0)    Rob.s.e. Rob.t.rat.(0)
asc_a      -0.029227          NA          NA          NA            NA
asc_b      -0.006198          NA          NA          NA            NA
asc_c      -0.054373          NA          NA          NA            NA
asc_d       0.000000          NA          NA          NA            NA
b_pt1       0.306176          NA          NA          NA            NA
b_bs1       0.032210          NA          NA          NA            NA
b_cs1      -0.206261          NA          NA          NA            NA
b_ss1      -0.415269          NA          NA          NA            NA
b_tx1       0.050399          NA          NA          NA            NA
b_gym1      0.634462          NA          NA          NA            NA
b_sv1       0.325864          NA          NA          NA            NA
b_costm1   -0.033278          NA          NA          NA            NA
I appreciate very much if you could help me on this one.
stephanehess
Site Admin
Posts: 1049
Joined: 24 Apr 2020, 16:29

Re: MNL - estimation failed (singular covergence)

Post by stephanehess »

Hi

apologies for the slow reply. There is nothing immediately apparent that would be causing an overspecification. Can you tell us more about the data? Maybe there are strange correlations in the data that lead to an empirical identification issue?

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