I have problems in estimating a simple MNL model. It seems to be a rather trivial issue. However, I spent a lot of time finding it and consulted several posts in this forum without success.
The error code reads:
WARNING: Your model did not converge properly, and some of your parameter values
are tending to +/- infinity. This could point to an identification
issue. If you want to retain these parameters in the model, you may
wish to set their value(s) in apollo_beta to the estimated value(s),
include the parameter name(s) in apollo_fixed, and re-estimate the
model.
WARNING: Estimation failed. No covariance matrix to compute.
I have four categorical attributes (2-4 levels) and a continous attribute (price). The attributes are coded with values from 0 (opt-out) to 2,3 or 4 (depending on the levels).
I have two unlabbled alternatives and an opt-out.
This is the code that I use:
Code: Select all
# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS ####
# ################################################################# #
### Clear memory
rm(list = ls())
### Load Apollo library
library(apollo)
### Initialise code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName = "model_1",
modelDescr = "basic MNL model",
indivID = "sys_SequentialRespNum",
nCores = 1,
outputDirectory = "output"
)
# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #
### Get data
database = read.csv("pilot_CE.csv")
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
apollo_beta = c(b_bio = 0,
b_ft = 0,
b_hum = 0,
b_farm = 0,
b_kmu = 0,
b_konz = 0,
b_coop = 0,
b_dt = 0,
b_water = 0,
b_forest = 0,
b_erosion = 0,
b_co2 = 0,
b_ch = 0,
b_gs = 0,
b_price = 0,
b_asc1 = 0,
b_asc2 = 0,
b_out = 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("b_bio", "b_kmu", "b_water", "b_ch", "b_out")
# ################################################################# #
#### GROUP AND VALIDATE INPUTS ####
# ################################################################# #
apollo_inputs = apollo_validateInputs()
# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION ####
# ################################################################# #
apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
### Function initialisation: do not change the following three commands
### 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[["alt1"]] = b_bio * (Label == 1) + b_ft * (Label == 2) + b_hum * (Label == 3) + b_farm * (Label == 4) +
b_kmu * (Dist == 1) + b_konz * (Dist == 2) + b_coop * (Dist == 3) + b_dt * (Dist == 4) +
b_water * (ECO == 1) + b_forest * (ECO == 2) + b_erosion * (ECO == 3) + b_co2 * (ECO == 4) +
b_ch * (COO == 1) + b_gs * (COO == 2) +
b_price * Price +
b_asc1
V[["alt2"]] = b_bio * (Label == 1) + b_ft * (Label == 2) + b_hum * (Label == 3) + b_farm * (Label == 4) +
b_kmu * (Dist == 1) + b_konz * (Dist == 2) + b_coop * (Dist == 3) + b_dt * (Dist == 4) +
b_water * (ECO == 1) + b_forest * (ECO == 2) + b_erosion * (ECO == 3) + b_co2 * (ECO == 4) +
b_ch * (COO == 1) + b_gs * (COO == 2) +
b_price * Price +
b_asc2
V[["optout"]] = b_out
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(alt1=1, alt2=2, optout=3),
choiceVar = Concept,
utilities = 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)
When I run the code, I get the following output:
Code: Select all
>
Apollo ignition sequence completed
Several observations per individual detected based on the value of
sys_SequentialRespNum. Setting panelData in apollo_control set to
TRUE.
All checks on apollo_control completed.
All checks on database completed.
Preparing user-defined functions.
Testing likelihood function...
Setting "avail" is missing, so full availability is assumed.
Overview of choices for MNL model component :
alt1 alt2 optout
Times available 850.00 850 850.00
Times chosen 282.00 340 228.00
Percentage chosen overall 33.18 40 26.82
Percentage chosen when available 33.18 40 26.82
Pre-processing likelihood function...
Testing influence of parameters
Starting main estimation
BGW using analytic model derivatives supplied by caller...
Iterates will be written to:
output/model_1_iterations.csv
it nf F RELDF PRELDF RELDX MODEL stppar
0 1 9.338204454e+02
1 3 8.080264895e+02 1.347e-01 1.545e-01 1.00e+00 G 8.98e+00
2 4 7.145230304e+02 1.157e-01 1.758e-01 4.81e-01 G 7.47e+00
3 6 5.921750706e+02 1.712e-01 1.440e-01 9.14e-01 S 1.57e-01
4 7 4.719827479e+02 2.030e-01 5.165e-01 4.13e-01 G 6.47e-02
5 8 4.357836453e+02 7.670e-02 1.523e-01 3.41e-01 G 2.73e-02
6 10 4.339183332e+02 4.280e-03 3.654e-03 3.33e-02 S 4.56e-02
7 11 4.317097155e+02 5.090e-03 5.634e-03 3.64e-02 G 3.74e-02
8 12 4.301468326e+02 3.620e-03 6.129e-03 5.14e-02 G 1.69e-02
9 13 4.293513382e+02 1.849e-03 2.475e-03 5.21e-02 G 8.75e-03
10 14 4.289230065e+02 9.976e-04 7.655e-04 4.73e-02 S 6.73e-04
11 15 4.286934830e+02 5.351e-04 4.086e-04 4.32e-02 S 3.45e-04
12 16 4.285705699e+02 2.867e-04 2.183e-04 3.98e-02 S 1.80e-04
13 17 4.285048406e+02 1.534e-04 1.166e-04 3.69e-02 S 9.47e-05
14 19 4.285000209e+02 1.125e-05 1.107e-05 3.72e-03 S 3.38e-03
15 21 4.284917382e+02 1.933e-05 1.921e-05 6.93e-03 S 2.24e-04
16 23 4.284688989e+02 5.330e-05 5.040e-05 2.48e-02 S 2.57e-05
17 27 4.284687418e+02 3.667e-07 3.251e-06 3.80e-04 S 1.15e-01
18 28 4.284685574e+02 4.304e-07 6.715e-07 2.39e-04 S 2.82e-02
19 29 4.284683607e+02 4.589e-07 6.152e-07 2.44e-04 S 2.75e-02
20 32 4.284675041e+02 1.999e-06 2.186e-06 1.18e-03 S 1.28e-03
21 34 4.284671495e+02 8.277e-07 9.357e-07 4.67e-04 S 1.39e-02
22 37 4.284645571e+02 6.050e-06 6.039e-06 3.72e-03 S 2.98e-04
23 39 4.284635404e+02 2.373e-06 2.373e-06 1.53e-03 S 3.79e-03
24 42 4.284567084e+02 1.595e-05 1.591e-05 1.16e-02 S 0.00e+00
25 45 4.284559896e+02 1.678e-06 2.838e-06 1.25e-03 S 3.85e-03
26 48 4.284403099e+02 3.660e-05 2.773e-05 4.34e-02 S 0.00e+00
27 51 4.284402486e+02 1.429e-07 4.683e-07 4.44e-04 S 7.32e-03
28 55 4.284352918e+02 1.157e-05 7.739e-06 2.77e-02 S 0.00e+00
29 56 4.284326067e+02 6.267e-06 4.835e-06 2.63e-02 S 4.75e-06
30 57 4.284311523e+02 3.395e-06 2.620e-06 2.50e-02 S 2.58e-06
31 58 4.284303646e+02 1.839e-06 1.419e-06 2.38e-02 S 1.40e-06
32 59 4.284299379e+02 9.959e-07 7.685e-07 2.27e-02 S 7.57e-07
33 60 4.284297068e+02 5.394e-07 4.163e-07 2.17e-02 S 4.10e-07
34 61 4.284295816e+02 2.922e-07 2.255e-07 2.08e-02 S 2.22e-07
35 62 4.284295138e+02 1.582e-07 1.221e-07 2.00e-02 S 1.20e-07
36 63 4.284294771e+02 8.573e-08 6.615e-08 1.92e-02 S 6.51e-08
37 64 4.284294572e+02 4.642e-08 3.583e-08 1.85e-02 S 3.53e-08
38 65 4.284294464e+02 2.515e-08 1.942e-08 1.78e-02 S 1.91e-08
39 66 4.284294406e+02 1.362e-08 1.051e-08 1.72e-02 S 1.04e-08
40 67 4.284294374e+02 7.378e-09 5.695e-09 1.67e-02 S 5.61e-09
41 68 4.284294357e+02 3.995e-09 3.087e-09 1.61e-02 S 3.05e-09
42 69 4.284294348e+02 2.165e-09 1.674e-09 1.56e-02 S 1.66e-09
43 70 4.284294343e+02 1.172e-09 9.048e-10 1.51e-02 S 8.94e-10
44 71 4.284294340e+02 6.348e-10 4.899e-10 1.47e-02 S 3.11e-08
***** Singular convergence *****
Estimated parameters:
Estimate
b_bio 0.000
b_ft -2.098
b_hum 52.444
b_farm -4.052
b_kmu 0.000
b_konz -18.740
b_coop 31.386
b_dt 11.079
b_water 0.000
b_forest 1.895
b_erosion 2.282
b_co2 4.939
b_ch 0.000
b_gs -6.024
b_price 73.865
b_asc1 -21.171
b_asc2 -20.984
b_out 0.000
Final LL: -428.4294
WARNING: Your model did not converge properly, and some of your parameter values
are tending to +/- infinity. This could point to an identification
issue. If you want to retain these parameters in the model, you may
wish to set their value(s) in apollo_beta to the estimated value(s),
include the parameter name(s) in apollo_fixed, and re-estimate the
model.
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
Model run by rudolf using Apollo 0.3.2 on R 4.4.0 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 : model_1
Model description : basic MNL model
Model run at : 2024-05-21 17:32:02.644595
Estimation method : bgw
Model diagnosis : Singular convergence
Number of individuals : 107
Number of rows in database : 850
Number of modelled outcomes : 850
Number of cores used : 1
Model without mixing
LL(start) : -933.82
LL at equal shares, LL(0) : -933.82
LL at observed shares, LL(C) : -922.7
LL(final) : -428.43
Rho-squared vs equal shares : 0.5412
Adj.Rho-squared vs equal shares : 0.5273
Rho-squared vs observed shares : 0.5357
Adj.Rho-squared vs observed shares : 0.5238
AIC : 882.86
BIC : 944.55
Estimated parameters : 13
Time taken (hh:mm:ss) : 00:00:6.34
pre-estimation : 00:00:1.68
estimation : 00:00:4.63
post-estimation : 00:00:0.03
Iterations : 44 (Singular convergence)
Unconstrained optimisation.
Estimates:
Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0)
b_bio 0.000 NA NA NA NA
b_ft -2.098 NA NA NA NA
b_hum 52.444 NA NA NA NA
b_farm -4.052 NA NA NA NA
b_kmu 0.000 NA NA NA NA
b_konz -18.740 NA NA NA NA
b_coop 31.386 NA NA NA NA
b_dt 11.079 NA NA NA NA
b_water 0.000 NA NA NA NA
b_forest 1.895 NA NA NA NA
b_erosion 2.282 NA NA NA NA
b_co2 4.939 NA NA NA NA
b_ch 0.000 NA NA NA NA
b_gs -6.024 NA NA NA NA
b_price 73.865 NA NA NA NA
b_asc1 -21.171 NA NA NA NA
b_asc2 -20.984 NA NA NA NA
b_out 0.000 NA NA NA NA
Max