Page 1 of 1

Singular Hessian and estimated parameters close to 0

Posted: 27 Apr 2021, 16:31
by lukasbarthelmes
Hello all,

I am facing a problem with estimating a simple MNL model. I have done this several times before without any problems, but with the current model I always geht the error message "Singular Hessian, cannot calculate s.e.". Furthermore, all my estimated paramters are very close to 0. I have already tried different starting values for my Betas, used different starting routines for the model and varied in the used paramters. Even the simplest MNL (only asc) brings up the same problem. Does anyone know, what the problem could be? For further details, please have a look at the apollo output below.

Thanks in advance and best regards
Lukas

************************************************************************************************************************************************************************************

Overview of choices for MNL model component :
user non_user
Times available 10131.00 10131.00
Times chosen 3808.00 6323.00
Percentage chosen overall 37.59 62.41
Percentage chosen when available 37.59 62.41

Pre-processing likelihood function...

Testing likelihood function........
Starting main estimation
Initial function value: -7022.274
Initial gradient value:
asc_ES b_male b_age_5 b_age_6 b_age_7 b_taet_berufv b_taet_beruft b_taet_bildung
1257.5 314.0 455.0 272.5 73.0 725.5 279.5 -35.0
initial value 7022.274086
iter 1 value 7022.274086
final value 7022.274086
converged
Estimated parameters:
Estimate
asc_noES 0.000
asc_ES 8.439e-16
b_male 2.107e-16
b_age_5 3.053e-16
b_age_6 1.829e-16
b_age_7 4.899e-17
b_taet_berufv 4.869e-16
b_taet_beruft 1.876e-16
b_taet_bildung -2.349e-17

Computing covariance matrix using analytical gradient.
0%....25%....50%....75%.100%
ERROR: Singular Hessian, cannot calculate s.e.

Hessian written to MNL_xxx.csv
Computing score matrix...
Calculating LL(0)...
Calculating LL of each model component...

> apollo_modelOutput(model)
Model run using Apollo for R, version 0.2.1 on Windows by xxx
www.ApolloChoiceModelling.com

Model name : MNL_xxx
Model description : MNL-Modell fuer xxx
Model run at : 2021-04-27 17:10:24
Estimation method : bfgs
Model diagnosis : successful convergence
Number of individuals : 10131
Number of observations : 10131

Number of cores used : 1
Model without mixing

LL(start) : -7022.274
LL(0) : -7022.274
LL(final) : -7022.274
Rho-square (0) : 0
Adj.Rho-square (0) : -0.0011
AIC : 14060.55
BIC : 14118.34


Estimated parameters : 8
Time taken (hh:mm:ss) : 00:00:1.55
pre-estimation : 00:00:0.68
estimation : 00:00:0.25
post-estimation : 00:00:0.63
Iterations : 1
Min abs eigenvalue of Hessian : 0

Estimates:
Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0)
asc_noES 0.000 NA NA NA NA
asc_ES 8.439e-16 NA NA NA NA
b_male 2.107e-16 NA NA NA NA
b_age_5 3.053e-16 NA NA NA NA
b_age_6 1.829e-16 NA NA NA NA
b_age_7 4.899e-17 NA NA NA NA
b_taet_berufv 4.869e-16 NA NA NA NA
b_taet_beruft 1.876e-16 NA NA NA NA
b_taet_bildung -2.349e-17 NA NA NA NA

Re: Singular Hessian and estimated parameters close to 0

Posted: 27 Apr 2021, 20:43
by stephanehess
Hi

can you please post the code, so we can see what you're doing, and then we will try to help find the issue

Stephane

Re: Singular Hessian and estimated parameters close to 0

Posted: 28 Apr 2021, 07:48
by lukasbarthelmes
Hey Stephane,

please find the R script attached. Thanks for your help. I just X`d file paths

Best regards
Lukas

************************************************************************************************************************************************************************************

### Load Apollo library
library(apollo)
library(data.table)
library(dplyr)


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

setwd("xxx")

database = read.csv("xxx.csv", header = TRUE, sep = ";", dec = ",")
database = filter(database, altersklasse != 1)



### Initialise code
apollo_initialise()

### Set core controls

number = 8

### Set core controls
apollo_control = list(
modelName = paste0("MNL_xxx", number),
modelDescr ="MNL-Modell xxx",
indivID ="HP_ID"
)

### Create File-Structure
setwd("xxx")

dir.name = paste0("MNL_", number)
dir.create(dir.name)

setwd(paste0("xxx", dir.name))


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

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

asc_ES = 0,

b_male = 0,

b_age_5 = 0,
b_age_6 = 0,
b_age_7 = 0,

b_taet_berufv = 0,
b_taet_beruft = 0,
b_taet_bildung = 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_noES")

# ################################################################# #
#### 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[['non_user']] = asc_noES

V[['user']] = asc_ES +

b_male * (gender == 1) +

b_age_5 * (altersklasse == 5) +
b_age_6 * (altersklasse == 6) +
b_age_7 * (altersklasse == 7) +

b_taet_berufv * (taetigkeit == 1) +
b_taet_beruft * (taetigkeit == 2) +
b_taet_bildung * (taetigkeit %in% c(5,6))


### Define settings for MNL model component
mnl_settings = list(
alternatives = c(user = 1, non_user = 0),
avail = list(user = 1, non_user = 1),
choiceVar = es_mitglied,
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)

Re: Singular Hessian and estimated parameters close to 0

Posted: 01 May 2021, 12:07
by lukasbarthelmes
Hi Stephane,

in the meantime I fixed the problem. It seems that the order in which I define the alternatives in mnl_settings has to be the same order of my utility functions, at least in the case I am using lists. So when the utility funtion for "users" in my case comes first and the the utility function for "non_users", I also have to keep this order in mnl_settings (alternatives = c(user = 1, non_user = 0)). I was not aware of this.

Best regards
Lukas

Re: Singular Hessian and estimated parameters close to 0

Posted: 10 May 2021, 15:30
by dpalma
Hi Lukas,

Sorry for the delayed response.

Glad to hear you solved the issue. In theory, Apollo should be able to sort alternatives to avoid this kind of issues, but we'll look into this in case there is any scenario we missed.

Cheers
David