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.

Unlabelled BNL can not estimate the s.e or t-ratio

Ask questions about model specifications. Ideally include a mathematical explanation of your proposed model.
Post Reply
tutsie12
Posts: 1
Joined: 19 Nov 2025, 22:54

Unlabelled BNL can not estimate the s.e or t-ratio

Post by tutsie12 »

Hi Sir,

Thank you for this platform.

I am estimating an unlabelled BNL with 4 generic attributes. Since Its unlabelled, i did not specify ASC parameters.

On estimation, i get a warning that, "... the BHHH matrix is singular. Apollo will not attempt to compute the
covariance matrix." and the standard errors are not calculated,

When I add the ASCs and fix for 1 attribute, i still get the same issue.

May you kindly point in the right direction.

Code: Select all

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

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

### Load libraries
library(apollo)

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
  modelName  ="bnl_base",
  modelDescr ="bnl base model on pedestrian choices",
  indivID    ="ID",
  calculateLLC = TRUE,
  outputDirectory = 'george_output'
)

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

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

### Use only SP data
#database = subset(database,database$SP==1)

### Create new variable with average income
#database$mean_monthly_income = mean(database$income_month)
database$cost_a = 0.001*database$cost_a
database$cost_b = 0.001*database$cost_b

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

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(

              b_walkingD = 0,
              b_waitingT = 0,
              b_travelT  = 0,
              b_cost     = 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()
  
  ### List of utilities: these must use the same names as in mnl_settings, order is irrelevant
  V = list()
  V[['a']]  = b_walkingD * walkingD_a + b_waitingT * waitingT_a + b_travelT * travelT_a + b_cost * cost_a
  V[['b']]  = b_walkingD * walkingD_b + b_waitingT * waitingT_b + b_travelT * travelT_b + b_cost * cost_b
  
  ### Define settings for MNL model component
  mnl_settings = list(
    alternatives  = c(a=0, b=1), 
    avail         = list(a=1, b=1), 
    choiceVar     = choice.Code,
    V             = V
  )
  
  ### Compute probabilities using MNL model
  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                                            ####
# ################################################################# #

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)
Here is the result:

Code: Select all

> model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
Preparing user-defined functions.

Testing likelihood function...

Overview of choices for MNL model component :
                                       a       b
Times available                  1784.00 1784.00
Times chosen                      907.00  877.00
Percentage chosen overall          50.84   49.16
Percentage chosen when available   50.84   49.16


Pre-processing likelihood function...

Testing influence of parameters
Starting main estimation

BGW using analytic model derivatives supplied by caller...


Iterates will be written to: 
 george_output/bnl_base_iterations.csv
    it    nf     F            RELDF    PRELDF    RELDX    MODEL stppar
     0     1 1.236574570e+03
     1     2 1.235724293e+03 6.876e-04 6.875e-04 1.00e+00   G   3.32e-01
     2     3 1.235646362e+03 6.307e-05 6.307e-05 4.70e-01   G   0.00e+00
     3     4 1.235646362e+03 1.296e-11 1.296e-11 1.37e-04   G   0.00e+00

***** Relative function convergence *****
G2;H2;WARNINGh: Estimation succeeded but the BHHH matrix is singular. Apollo will not attempt to compute the
  covariance matrix. 

Estimated parameters:
gG2;              Estimate
b_walkingD -2.2440e-04
b_waitingT    0.004742
b_travelT    -0.003591
b_cost       -0.425999

Final LL: -1235.6464

gG2;Calculating log-likelihood at equal shares (LL(0)) for applicable models...
gG2;Calculating log-likelihood at observed shares from estimation data (LL(c)) for applicable models...
gG2;Calculating LL of each model component...
gG2;Calculating other model fit measures
gG2;
Your model was estimated using the BGW algorithm. Please acknowledge this by citing Bunch et al. (1993)
  - doi.org/10.1145/151271.151279

Please acknowledge the use of Apollo by citing Hess & Palma (2019) - doi.org/10.1016/j.jocm.2019.100170
g
> apollo_modelOutput(model)
Model run by mapfuriramasimbatutsirai using Apollo 0.3.6 on R 4.5.1 for Darwin.
Please acknowledge the use of Apollo by citing Hess & Palma (2019)
  DOI 10.1016/j.jocm.2019.100170
  www.ApolloChoiceModelling.com

Model name                                  : bnl_base
Model description                           : bnl base model on pedestrian choices
Model run at                                : 2025-11-20 00:57:54.461338
Estimation method                           : bgw
Estimation diagnosis                        : Relative function convergence
Optimisation diagnosis                      : Unknown (no Hessian calculated)
Number of individuals                       : 198
Number of rows in database                  : 1784
Number of modelled outcomes                 : 1784

Number of cores used                        :  1 
Model without mixing

LL(start)                                   : -1236.57
LL at equal shares, LL(0)                   : -1236.57
LL at observed shares, LL(C)                : -1236.32
LL(final)                                   : -1235.65
Rho-squared vs equal shares                  :  8e-04 
Adj.Rho-squared vs equal shares              :  -0.0025 
Rho-squared vs observed shares               :  5e-04 
Adj.Rho-squared vs observed shares           :  -0.0019 
AIC                                         :  2479.29 
BIC                                         :  2501.24 

Estimated parameters                        : 4
Time taken (hh:mm:ss)                       :  00:00:3.98 
     pre-estimation                         :  00:00:2.61 
     estimation                             :  00:00:0.94 
     post-estimation                        :  00:00:0.43 
Iterations                                  :  3  

Unconstrained optimisation.

Estimates:
              Estimate        s.e.   t.rat.(0)    Rob.s.e. Rob.t.rat.(0)
b_walkingD -2.2440e-04          NA          NA          NA            NA
b_waitingT    0.004742          NA          NA          NA            NA
b_travelT    -0.003591          NA          NA          NA            NA
b_cost       -0.425999          NA          NA          NA            NA
stephanehess
Site Admin
Posts: 1355
Joined: 24 Apr 2020, 16:29

Re: Unlabelled BNL can not estimate the s.e or t-ratio

Post by stephanehess »

Hi

difficult to know without looking at the data. can you share the data and code with me outside the forum and I'll have a look

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