Page 1 of 1

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

Posted: 19 Nov 2025, 23:29
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

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

Posted: 29 Nov 2025, 13:27
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