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.

positive Hessian eigenvalues

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
Post Reply
piatulo
Posts: 3
Joined: 12 Nov 2022, 12:41

positive Hessian eigenvalues

Post by piatulo »

Hey,

I have some problems with the estimation, because I get positive eigenvalues, as soon as I use all of my betas.
The more betas I add, the bigger becomes the eigenvalue to a point, where its 0 or positive and my model fails.

I tried it with a subset of my data and checked on every beta, but as soon as a certain amount is activated, it fails and the s.e. get very high or I get NaNs.

This is my code:

### Initialise code
apollo_initialise()

### set core controls
apollo_control = list(
modelName ="Nutzen",
modelDescr ="Simple MNL model on mode choice RP data",
indivID ="FID",
outputDirectory = "output"
)


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

### Vector of parameters, including any that are kept fixed in estimation

apollo_beta=c(asc_fuss = 0,
asc_rad = 0,
asc_auto = 0,
asc_mitfahr = 0,
asc_oev = 0,

b_temp_fuss_u0_5= 0,
b_temp_fuss_5_15 = 0,
b_temp_fuss_15_25 = 0,

b_temp_rad_u0_5= 0,
b_temp_rad_5_15 = 0,
b_temp_rad_15_25 = 0,

b_temp_auto_u0_5 = 0,
b_temp_auto_5_15 = 0,
b_temp_auto_15_25= 0,

b_temp_mitfahr_u0_5 = 0,
b_temp_mitfahr_5_15 = 0,
b_temp_mitfahr_15_25 = 0,

b_temp_oev_u0_5= 0,
b_temp_oev_5_15 = 0,
b_temp_oev_15_25 = 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_fuss", "b_temp_fuss_u0_5", "b_temp_rad_u0_5", "b_temp_auto_u0_5", "b_temp_mitfahr_u0_5", "b_temp_oev_u0_5"
)


# ################################################################# #
#### 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[['fuss']] = asc_fuss + b_temp_fuss_u0_5 * (KAT_TEMP_NEU == 1) + b_temp_fuss_5_15 * (KAT_TEMP_NEU == 2) + b_temp_fuss_15_25
(KAT_TEMP_NEU == 3)


V[['rad']] = asc_rad + b_temp_rad_u0_5 * (KAT_TEMP_NEU == 1) + b_temp_rad_5_15 * (KAT_TEMP_NEU== 2) + b_temp_rad_15_25 * (KAT_TEMP_NEU== 3)

V[['auto']] = asc_auto+ b_temp_auto_u0_5 * (KAT_TEMP_NEU== 1) + b_temp_auto_5_15 * (KAT_TEMP_NEU == 2) + b_temp_auto_15_25 * (KAT_TEMP_NEU == 3)#


V[['mitfahr']] = asc_mitfahr + b_temp_mitfahr_u0_5 * (KAT_TEMP_NEU == 1) + b_temp_mitfahr_5_15 * (KAT_TEMP_NEU== 2)+ b_temp_mitfahr_15_25 * (KAT_TEMP_NEU == 3)

V[['oev']] = asc_oev + b_temp_oev_u0_5 * (KAT_TEMP_NEU == 1) + b_temp_oev_5_15 * (KAT_TEMP_NEU == 2) + b_temp_oev_15_25 * (KAT_TEMP_NEU == 3)

# ################################################################# #
#### ANALYSIS OF CHOICES ####
# ################################################################# #


choiceAnalysis_settings <- list(
alternatives = c(fuss=1, rad =2, auto=4, mitfahr=5, oev=6),
avail =list(fuss =av_fuss, rad= av_rad, auto=av_auto, mitfahr = av_mitfahr, oev = av_oev),
choiceVar = choice,
V = V
)


### Compute probabilities using MNL model
P[['model']] = apollo_mnl(choiceAnalysis_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 ####
# ################################################################# #


These are the results I get:
Model name : Nutzen
Model description : Simple MNL model on mode choice RP data
Model run at : 2022-11-12 13:47:26
Estimation method : bfgs
Model diagnosis : successful convergence
Number of individuals : 1984
Number of rows in database : 100000
Number of modelled outcomes : 1e+05

Number of cores used : 1
Model without mixing

LL(start) : -151142.4
LL at equal shares, LL(0) : -151142.4
LL at observed shares, LL(C) : -122710.1
LL(final) : -122568.6
Rho-squared vs equal shares : 0.1891
Adj.Rho-squared vs equal shares : 0.189
Rho-squared vs observed shares : 0.0012
Adj.Rho-squared vs observed shares : 0.001
AIC : 245165.2
BIC : 245298.4

Estimated parameters : 14
Time taken (hh:mm:ss) : 00:01:7.63
pre-estimation : 00:00:10.41
estimation : 00:00:18.42
post-estimation : 00:00:38.8
Iterations : 24
Min abs eigenvalue of Hessian : 4e-06
Some eigenvalues of Hessian are positive, indicating potential problems!

Unconstrained optimisation.

These outputs have had the scaling used in estimation applied to them.
Estimates:
Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0)
asc_fuss 0.000000 NA NA NA NA
asc_rad -0.936449 0.04768 -19.64 0.10387 -9.01521
asc_auto 1.331313 0.03150 42.26 0.07231 18.41020
asc_mitfahr -0.389863 0.03694 -10.55 0.07206 -5.41011
asc_oev -0.728414 0.04114 -17.71 0.08340 -8.73384
b_temp_fuss_u0_5 0.000000 NA NA NA NA
b_temp_fuss_5_15 0.065989 NaN NaN 0.35766 0.18450
b_temp_fuss_15_25 0.004563 NaN NaN 0.22437 0.02034
b_temp_rad_u0_5 0.000000 NA NA NA NA
b_temp_rad_5_15 0.333230 NaN NaN 0.41623 0.80059
b_temp_rad_15_25 0.585298 NaN NaN 0.14782 3.95951
b_temp_auto_u0_5 0.000000 NA NA NA NA
b_temp_auto_5_15 -0.104662 NaN NaN 0.28693 -0.36476
b_temp_auto_15_25 -0.153079 NaN NaN NaN NaN
b_temp_mitfahr_u0_5 0.000000 NA NA NA NA
b_temp_mitfahr_5_15 -0.048284 NaN NaN 0.42641 -0.11323
b_temp_mitfahr_15_25 -0.076378 NaN NaN 0.09833 -0.77679
b_temp_oev_u0_5 0.000000 NA NA NA NA
b_temp_oev_5_15 -0.246271 NaN NaN 0.25006 -0.98486
b_temp_oev_15_25 -0.360404 NaN NaN 0.13970 -2.57975


Thank you very much in advance!
Pia
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: positive Hessian eigenvalues

Post by stephanehess »

Pia

your model is overspecified. If you use a full set of alternative specific constants, then you need to normalise one to zero, as you do, but it also means that when you add interactions, they can only be added to J-1 of the alternatives as only differences in utility matter

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
piatulo
Posts: 3
Joined: 12 Nov 2022, 12:41

Re: positive Hessian eigenvalues

Post by piatulo »

Hey Stephane,

thank you very much for your reply!
It works when I set all interactions for one alternative to zero.

Is it then still necassary, as I did in the example, to set one interaction for each alternative to zero too?


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

Re: positive Hessian eigenvalues

Post by stephanehess »

Pia

if your covariates are categorical, then you need that normalisation too, if they are continuous, then you don't

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