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.

"No covariance matrix to compute." Warning in Apollo eMDC model

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
Post Reply
sykim
Posts: 2
Joined: 26 Oct 2023, 03:19

"No covariance matrix to compute." Warning in Apollo eMDC model

Post by sykim »

Dear Stephane,

I am trying to run an apollo eMDC model with complementarity, substitution, and an implicit budget
to analyze quarterly energy(e.g. coal, naturagl gas, nuclear, oil, renewables) use by country.

Unfortunately, after 205 iterations, I got below results with warning messages.
"WARNING: Estimation failed. No covariance matrix to compute."
The code used for this analysis is attached below the results.

Can you give me an advise to solve this problem.
I would appreciate it if you would have a look and give any comment.

Thank you so much, always!

Best regards,
Suyeon

========================= Results ========================================
Preparing user-defined functions.

Testing likelihood function...

Pre-processing likelihood function...
Analytical gradients could not be calculated for all components, numerical
gradients will be used.

Testing influence of parameters......................................
Starting main estimation

BGW is using FD derivatives for model Jacobian. (Caller did not provide derivatives.)


Iterates will be written to:
output/eMDC_EnergyUse_without_budget_iterations.csv it nf F RELDF PRELDF RELDX MODEL stppar
0 1 1.024541940e+04
1 3 1.009529526e+04 1.465e-02 2.707e-02 9.89e-03 G 4.45e+01
2 4 9.802210539e+03 2.903e-02 5.256e-02 9.67e-03 G 3.72e+01
3 6 8.017661645e+03 1.821e-01 1.180e-01 1.28e-01 S -1.27e-03
4 8 6.715103603e+03 1.625e-01 1.552e-01 6.61e-02 S 1.69e+00
5 10 4.662228780e+03 3.057e-01 2.639e-01 1.74e-01 S 3.33e-01
6 12 1.209538666e+03 7.406e-01 5.140e-01 4.00e-02 S 7.99e-02
7 14 -4.440669897e+02 1.367e+00 1.239e+00 1.36e-02 S 7.44e-01
8 15 -1.912434629e+03 7.678e-01 1.408e+00 4.61e-02 S -9.33e-02
9 17 -3.351144040e+03 4.293e-01 3.458e-01 1.25e-02 S 1.57e+00
10 20 -6.172385178e+03 4.571e-01 5.216e-01 6.54e-02 S 3.77e-01
.............(omitted)...........
195 272 -7.101005915e+04 9.477e-12 1.287e-10 4.39e-08 G 1.02e+04
196 273 -7.101005915e+04 4.742e-12 6.441e-11 2.20e-08 G 3.04e-01
197 274 -7.101005915e+04 2.372e-12 3.222e-11 1.10e-08 G 3.04e-01
198 275 -7.101005915e+04 1.183e-12 1.611e-11 5.50e-09 G 3.04e-01
199 276 -7.101005915e+04 5.967e-13 8.057e-12 2.75e-09 G 3.04e-01
200 277 -7.101005915e+04 2.965e-13 4.029e-12 1.37e-09 G 3.04e-01
201 278 -7.101005915e+04 1.482e-13 2.015e-12 6.87e-10 G 3.04e-01
202 279 -7.101005915e+04 7.357e-14 1.007e-12 3.44e-10 G 3.04e-01
203 280 -7.101005915e+04 3.709e-14 5.051e-13 1.73e-10 G 3.04e-01
204 281 -7.101005915e+04 2.213e-14 2.526e-13 8.62e-11 G 3.04e-01
205 288 -7.101005915e+04 2.049e-16 1.477e-16 3.26e-14 G 6.76e+09

***** False convergence *****

Estimated parameters:
Estimate
aDeved -0.32789
aGDP -52.55518
aUnemploy 0.00000
aCovid19 0.00000
bCoal 0.96900
bNatugas 1.55980
bNucl 1.74184
bOil 1.45342
bRenew 6.17045
bC_ctax -0.15211
bNG_ctax -0.29889
bN_ctax 0.20153
bO_ctax -0.06268
bR_ctax 0.56837
bC_cneu -0.45422
bNG_cneu -0.38337
bN_cneu 0.07870
bO_cneu -0.16500
bR_cneu 0.56644
bC_noNucl -0.26137
bNG_noNucl -0.14251
bN_noNucl -50.71815
bO_noNucl 0.07556
bR_noNucl 0.31331
bC_accdnt 0.76492
bNG_accdnt 1.29318
bN_accdnt -1.73254
bO_accdnt 2.01275
bR_accdnt -0.32846
gCoal 7.816e-05
gNutugas 3.087e-05
gNucl 2.817e-05
gOil 3.342e-06
gRenew 3.569e-07
dCoalNatu -10.01749
dCoalNucl 0.00000
dCoalOil -113.86717
dCoalRe -190.18062
dNatuNucl 0.00000
dNatuOil -129.07635
dNatuRe -130.06708
dNuclOil 0.00000
dNuclRe 0.00000
dOilRe -408.20810
sigma 1.00000

Final LL: 71010.0591

WARNING: Estimation failed. No covariance matrix to compute.

Current process will resume in 3 seconds unless interrupted by the user...

coal natugas nucl oil
Times available 2.312000e+03 2.312000e+03 2.312000e+03 2.312000e+03
Times chosen 1.979000e+03 2.192000e+03 1.169000e+03 2.216000e+03
% chosen when avail. 8.559689e+01 9.480969e+01 5.056228e+01 9.584775e+01
Avg. consump. when avail. 3.376278e-04 2.807804e-04 2.636386e-04 3.968756e-05
Avg. consump. when chosen 3.944394e-04 2.961516e-04 5.214135e-04 4.140687e-05
renew
Times available 2.312000e+03
Times chosen 2.312000e+03
% chosen when avail. 1.000000e+02
Avg. consump. when avail. 1.037153e-03
Avg. consump. when chosen 1.037153e-03

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...
INFORMATION: Your model took more than 10 minutes to estimate, so it was saved to file
output/eMDC_EnergyUse_without_budget_model.rds before calculating its
covariance matrix. If calculation of the covariance matrix fails or is stopped
before finishing, you can load the model up to this point using
apollo_loadModel.

Your model was estimated using the BGW algorithm. Please acknowledge this by
citing Bunch et al. (1993) - DOI 10.1145/151271.151279

========================= Codes ========================================
# ################################################################# #
#### DEFINE MODEL PARAMETERS (setting names and starting values) ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(
aDeved = 0, aGDP = 0,
aUnemploy = 0, aCovid19 = 0,
# Base utility of inside goods
bCoal = 0, bNatugas = 0,
bNucl = 0, bOil = 0,
bRenew = 0,
bC_ctax = 0, bNG_ctax = 0,
bN_ctax = 0, bO_ctax = 0,
bR_ctax = 0,
bC_cneu = 0, bNG_cneu = 0,
bN_cneu = 0, bO_cneu = 0,
bR_cneu = 0,
bC_noNucl = 0, bNG_noNucl = 0,
bN_noNucl = 0, bO_noNucl = 0,
bR_noNucl = 0,
bC_accdnt = 0, bNG_accdnt = 0,
bN_accdnt = 0, bO_accdnt = 0,
bR_accdnt = 0,
# Satiation
gCoal = 1, gNutugas = 1,
gNucl = 1, gOil = 1,
gRenew = 1,
# Complementarity and substitution
dCoalNatu = 0, dCoalNucl = 0,
dCoalOil = 0, dCoalRe = 0,
dNatuNucl = 0, dNatuOil = 0,
dNatuRe = 0, dNuclOil = 0,
dNuclRe = 0, dOilRe = 0,
# S.d. of error term
sigma = 1)

### Vector with names (in quotes) of parameters to be kept fixed at their starting value in apollo_beta, use apollo_fixed = c() if none

apollo_fixed = c('dCoalNucl','dNatuNucl','dNuclOil','dNuclRe',
'aUnemploy', 'aCovid19',
'sigma')


# ################################################################# #
#### GROUP AND VALIDATE INPUTS ####
# ################################################################# #
# run a number of validation tests on the apollo_control settings and the database
# in the case of panel data, it adds an extra column called apollo_sequence which is
a runnning index of observations for each individual

apollo_inputs = apollo_validateInputs()

# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION ####
# ################################################################# #
# check distinctions from other functions !!!
# specific format depends on 'functionality'

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()

### Prepare Inputs
alts = c("coal", "natugas", "nucl", "oil", "renew")

nAlt = length(alts)
ones = setNames(as.list(rep(1, nAlt)), alts)

continuousChoice = list(coal = coal_capita,
natugas = natu_capita,
nucl = nucl_capita,
oil = oil_capita,
renew = renew_capita)

utilities = list(
coal = bCoal + bC_ctax * carbontax_adpt + bC_cneu * carbonneu_act + bC_noNucl * nucl_notuse + bC_accdnt * nuclear_accident,
natugas = bNatugas + bNG_ctax * carbontax_adpt + bNG_cneu * carbonneu_act + bNG_noNucl * nucl_notuse + bNG_accdnt * nuclear_accident,
nucl = bNucl + bN_ctax * carbontax_adpt + bN_cneu * carbonneu_act + bN_noNucl * nucl_notuse + bN_accdnt * nuclear_accident,
oil = bOil + bO_ctax * carbontax_adpt + bO_cneu * carbonneu_act + bO_noNucl * nucl_notuse + bO_accdnt * nuclear_accident,
renew = bRenew + bR_ctax * carbontax_adpt + bR_cneu * carbonneu_act + bR_noNucl * nucl_notuse + bR_accdnt * nuclear_accident
)

gamma = list(coal = gCoal,
natugas = gNutugas,
nucl = gNucl,
oil = gOil,
renew = gRenew)

delta <- c(0, 0, 0, 0, 0,
dCoalNatu, 0, 0, 0, 0,
dCoalNucl, dNatuNucl, 0, 0, 0,
dCoalOil, dNatuOil, dNuclOil, 0, 0,
dCoalRe, dNatuRe, dNuclRe, dOilRe, 0)
delta <- matrix(delta, nrow=nAlt, ncol=nAlt, byrow=TRUE)

### Define settings for eMDC model
emdc_settings <- list(continuousChoice = continuousChoice,
avail = ones,
utilityOutside = aDeved*developed + aGDP*gdp_capita + aUnemploy*log_unemploy + aCovid19*covid19_crisis,
utilities = utilities,
gamma = gamma,
delta = delta,
cost = ones,
sigma = sigma)

### Compute probabilities using eMDC model
P[["model"]] = apollo_emdc(emdc_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 & OUTPUT ####
# ################################################################# #

estimate_settings <- list(maxIterations = 5000)

model = apollo_estimate(apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs, estimate_settings)
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: "No covariance matrix to compute." Warning in Apollo eMDC model

Post by stephanehess »

Hi

your model hasn't converged to a proper solution (see the message about false convergence), so as a result, no covariance matrix is computed. Some of your model parameters seem to become very large in absolute values, and this is likely an indication of the problems. I suggest you look into those values and determine whether your model is correctly specified

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
sykim
Posts: 2
Joined: 26 Oct 2023, 03:19

Re: "No covariance matrix to compute." Warning in Apollo eMDC model

Post by sykim »

Dear Stephane,

Thank you so much for all your feedback and suggestion.
I will try to look into those values and correct them.

Best regards,
Suyeon
Post Reply