Thank you for running this forum.
I am running an MNL to estimate the preferences for mobility packages. I have 4 unlabeled alternatives (A, B, C, D), where D is basically a status-quo option.
Right now I am facing a problem of "Estimation failed. No covariance matrix to compute"
Here is my code:
Code: Select all
# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS ####
# ################################################################# #
### Clear memory
rm(list = ls())
### Load Apollo library
#install.packages("apollo")
library(apollo)
### Initialise code
apollo_initialise()
#------- MNL ---------
### Set core controls
apollo_control = list(
modelName = "MNL MaaS Italy",
modelDescr = "MNL MaaS Italy" ,
indivID = "id"
)
# ################################################################# #
# LOAD DATA AND APPLY ANY TRANSFORMATIONS
data<-read.csv(file.choose(),header=TRUE)
database = data
### Define settings for analysis of choice data to be conducted prior to model estimation
choiceAnalysis_settings <- list(
alternatives = c(Va=1, Vb=2, Vc=3, Vd=4),
avail = list(Va=database$av_a, Vb=database$av_b, Vc=database$av_c, Vd=database$av_d),
choiceVar = (database$choice)
)
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
### ASC bundles
apollo_beta=c(asc_a = 0,
asc_b = 0,
asc_c = 0,
asc_d = 0,
b_pt1 = 0,
b_bs1 = 0,
b_cs1 = 0,
b_ss1 = 0,
b_tx1 = 0,
b_gym1 = 0,
b_sv1 = 0,
b_costm1 = 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_d")
# 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()
### Likelihood of choices
### List of utilities: these must use the same names as in mnl_settings, order is irrelevant
V = list()
V[["Va"]] = (asc_a + b_pt1*a_pt + b_bs1*a_bs + b_cs1*a_cs + b_ss1*a_ss + b_tx1*a_tx + b_gym1*a_gym + b_sv1*a_sv + b_costm1*a_costm)
V[["Vb"]] = (asc_b + b_pt1*b_pt + b_bs1*b_bs + b_cs1*b_cs + b_ss1*b_ss + b_tx1*b_tx + b_gym1*b_gym + b_sv1*b_sv + b_costm1*b_costm)
V[["Vc"]] = (asc_c + b_pt1*c_pt + b_bs1*c_bs + b_cs1*c_cs + b_ss1*c_ss + b_tx1*c_tx + b_gym1*c_gym + b_sv1*c_sv + b_costm1*c_costm)
V[["Vd"]] = (asc_d)
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(Va=1, Vb=2, Vc=3, Vd=4),
avail = list(Va=av_a, Vb=av_b, Vc=av_c, Vd=av_d),
choiceVar = choice,
utilities = V
)
### Compute probabilities for MNL model component
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
### Estimate model
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
# MODEL OUTPUTS
apollo_modelOutput(model)
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO FILE, using model name) ----
# ----------------------------------------------------------------- #
apollo_saveOutput(model)
Code: Select all
Preparing user-defined functions.
Testing likelihood function...
Overview of choices for MNL model component :
Va Vb Vc Vd
Times available 1578.00 1578.00 1578.00 1578.00
Times chosen 408.00 411.00 390.00 369.00
Percentage chosen overall 25.86 26.05 24.71 23.38
Percentage chosen when available 25.86 26.05 24.71 23.38
Pre-processing likelihood function...
Testing influence of parameters
Starting main estimation
BGW using analytic model derivatives supplied by caller...
Iterates will be written to:
D:/MaaS packages/Statistical analysis/Apollo/HCM/MNL MaaS Italy_iterations.csv it nf F RELDF PRELDF RELDX MODEL stppar
0 1 2.187572502e+03
1 4 2.056988686e+03 5.969e-02 4.969e-02 1.00e+00 G 7.63e-15
2 5 2.049955324e+03 3.419e-03 3.287e-03 1.19e-01 G -7.63e-15
3 6 2.049932700e+03 1.104e-05 1.077e-05 7.95e-03 S -7.63e-15
4 7 2.049932648e+03 2.499e-08 2.408e-08 1.84e-02 S -7.63e-15
5 8 2.049932648e+03 6.867e-11 6.803e-11 1.02e-02 S 3.71e-15
***** Singular convergence *****
Estimated parameters:
Estimate
asc_a -0.029227
asc_b -0.006198
asc_c -0.054373
asc_d 0.000000
b_pt1 0.306176
b_bs1 0.032210
b_cs1 -0.206261
b_ss1 -0.415269
b_tx1 0.050399
b_gym1 0.634462
b_sv1 0.325864
b_costm1 -0.033278
Final LL: -2049.9326
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
> apollo_modelOutput(model)
Model run by ASUS using Apollo 0.3.1 on R 4.3.1 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 : MNL MaaS Italy
Model description : MNL MaaS Italy
Model run at : 2024-03-13 14:52:03.447899
Estimation method : bgw
Model diagnosis : Singular convergence
Number of individuals : 263
Number of rows in database : 1578
Number of modelled outcomes : 1578
Number of cores used : 1
Model without mixing
LL(start) : -2187.57
LL at equal shares, LL(0) : -2187.57
LL at observed shares, LL(C) : -2186.14
LL(final) : -2049.93
Rho-squared vs equal shares : 0.0629
Adj.Rho-squared vs equal shares : 0.0579
Rho-squared vs observed shares : 0.0623
Adj.Rho-squared vs observed shares : 0.0586
AIC : 4121.87
BIC : 4180.87
Estimated parameters : 11
Time taken (hh:mm:ss) : 00:00:4.57
pre-estimation : 00:00:1.25
estimation : 00:00:3.25
post-estimation : 00:00:0.07
Iterations : 5 (Singular convergence)
Unconstrained optimisation.
Estimates:
Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0)
asc_a -0.029227 NA NA NA NA
asc_b -0.006198 NA NA NA NA
asc_c -0.054373 NA NA NA NA
asc_d 0.000000 NA NA NA NA
b_pt1 0.306176 NA NA NA NA
b_bs1 0.032210 NA NA NA NA
b_cs1 -0.206261 NA NA NA NA
b_ss1 -0.415269 NA NA NA NA
b_tx1 0.050399 NA NA NA NA
b_gym1 0.634462 NA NA NA NA
b_sv1 0.325864 NA NA NA NA
b_costm1 -0.033278 NA NA NA NA