No covariance matrix
Posted: 01 Apr 2024, 15:59
I am trying to estimate a MNL model with 7 app attributes that have three levels. All the attributes are effect coded with two parameters (for example, cost --> costa & costb). I have also included a 'opt out' option, which was phrased as 'prefer to download no app at all' and is utility function 'app 0', which is 0.
For some reason I get the error 'Estimation failed. No covariance matrix to compute.' I think it has to do with the singular convergence. I check my dataset and tried estimating the model without the 'opt out' option, which lead to the error: 'Singular Hessian, cannot calculate s.e.'. I could not find out what was wrong with my model based on the other topics with similar errors. Below is my code and the output.
Thank you!
----------------------------------------------------------------------------------------------------------------------------------------------------------
rm(list = ls())
### Load Apollo library
library(apollo)
### Initialise code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName ="MNL_3",
modelDescr ="MNL model only attributes_noalt3",
indivID ="ID"
)
#### LOAD DATA
database = read.csv("/Users/evahogervorst/Desktop/Studie/Afstuderen/Data/Werkspace/MNLdata_onlyattributes_noalt3.csv", sep = ',', header=TRUE)
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(BETA_costa = 0,
BETA_costb = 0,
BETA_priva = 0,
BETA_privb = 0,
BETA_coma = 0,
BETA_comb = 0,
BETA_acca = 0,
BETA_accb = 0,
BETA_usea = 0,
BETA_useb = 0,
BETA_persa = 0,
BETA_persb = 0,
BETA_exta = 0,
BETA_extb = 0,
delta_alternative = 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()
#### 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[['app0']] = 0
V[['appA']] = delta_alternative + BETA_costa * cost1a + BETA_costb * cost1b + BETA_priva * priv1a + BETA_privb * priv1b + BETA_coma * com1a + BETA_comb + com1b + BETA_acca * acc1a + BETA_accb * acc1b + BETA_usea * use1a + BETA_useb * use1b + BETA_persa * pers1a + BETA_persb * pers1b + BETA_exta * ext1a + BETA_extb * ext1b
V[['appB']] = delta_alternative + BETA_costa * cost2a + BETA_costb * cost2b + BETA_priva * priv2a + BETA_privb * priv2b + BETA_coma * com2a + BETA_comb + com2b + BETA_acca * acc2a + BETA_accb * acc2b + BETA_usea * use2a + BETA_useb * use2b + BETA_persa * pers2a + BETA_persb * pers2b + BETA_exta * ext2a + BETA_extb * ext2b
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(app0=0, appA=1, appB=2),
avail = list(app0=1, appA=1, appB=1),
choiceVar = choice,
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 VALIDATION
###apollo_sink()
###apollo_outOfSample(apollo_beta,
### apollo_fixed,
### apollo_probabilities,
### apollo_inputs,
### outOfSample_settings = list (validationSize = 0.33))
###apollo_sink()
#### MODEL OUTPUTS
apollo_modelOutput(model,modelOutput_settings=list(printPVal=TRUE))
apollo_saveOutput(model)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
OUTPUT
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> #### MODEL ESTIMATION
> model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
Preparing user-defined functions.
Testing likelihood function...
Overview of choices for MNL model component :
app0 appA appB
Times available 1512.00 1512.0 1512.00
Times chosen 838.00 369.0 305.00
Percentage chosen overall 55.42 24.4 20.17
Percentage chosen when available 55.42 24.4 20.17
Pre-processing likelihood function...
Testing influence of parameters
Starting main estimation
BGW using analytic model derivatives supplied by caller...
Iterates will be written to:
/Users/evahogervorst/MNL_3_iterations.csv it nf F RELDF PRELDF RELDX MODEL stppar
0 1 1.786329956e+03
1 4 1.461998007e+03 1.816e-01 1.658e-01 1.00e+00 G 6.64e-01
2 5 1.339591379e+03 8.373e-02 8.482e-02 3.80e-01 G 1.40e-01
3 6 1.328959500e+03 7.937e-03 6.750e-03 3.32e-01 G 1.98e-15
4 7 1.328136826e+03 6.190e-04 6.480e-04 1.25e-01 S -1.88e-15
5 8 1.328087420e+03 3.720e-05 3.532e-05 3.82e-02 S -1.88e-15
6 9 1.328077082e+03 7.784e-06 6.242e-06 1.64e-01 S 3.63e-15
7 10 1.328075634e+03 1.090e-06 9.325e-07 8.49e-02 S -3.63e-15
8 11 1.328075408e+03 1.702e-07 1.228e-07 9.67e-02 S -3.63e-15
9 12 1.328075320e+03 6.573e-08 5.380e-08 3.65e-02 S -3.63e-15
10 13 1.328075304e+03 1.255e-08 9.449e-09 9.55e-02 S -3.63e-15
11 14 1.328075299e+03 3.270e-09 2.757e-09 5.89e-02 S -3.63e-15
12 15 1.328075299e+03 3.544e-10 2.929e-10 9.23e-02 S 0.00e+00
13 16 1.328075299e+03 3.417e-11 3.069e-11 7.18e-05 S 1.66e-14
***** Singular convergence *****
Estimated parameters:
Estimate
BETA_costa -0.821935
BETA_costb -0.113798
BETA_priva 0.532970
BETA_privb -0.082607
BETA_coma 0.073161
BETA_comb -2.428525
BETA_acca 1.009997
BETA_accb -0.129587
BETA_usea 0.316059
BETA_useb -0.177152
BETA_persa -0.008474
BETA_persb 0.221608
BETA_exta 0.152582
BETA_extb -0.035154
delta_alternative 1.034001
Final LL: -1328.0753
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 VALIDATION
>
> ###apollo_sink()
> ###apollo_outOfSample(apollo_beta,
> ### apollo_fixed,
> ### apollo_probabilities,
> ### apollo_inputs,
> ### outOfSample_settings = list (validationSize = 0.33))
> ###apollo_sink()
>
> #### MODEL OUTPUTS
> apollo_modelOutput(model,modelOutput_settings=list(printPVal=TRUE))
For some reason I get the error 'Estimation failed. No covariance matrix to compute.' I think it has to do with the singular convergence. I check my dataset and tried estimating the model without the 'opt out' option, which lead to the error: 'Singular Hessian, cannot calculate s.e.'. I could not find out what was wrong with my model based on the other topics with similar errors. Below is my code and the output.
Thank you!
----------------------------------------------------------------------------------------------------------------------------------------------------------
rm(list = ls())
### Load Apollo library
library(apollo)
### Initialise code
apollo_initialise()
### Set core controls
apollo_control = list(
modelName ="MNL_3",
modelDescr ="MNL model only attributes_noalt3",
indivID ="ID"
)
#### LOAD DATA
database = read.csv("/Users/evahogervorst/Desktop/Studie/Afstuderen/Data/Werkspace/MNLdata_onlyattributes_noalt3.csv", sep = ',', header=TRUE)
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(BETA_costa = 0,
BETA_costb = 0,
BETA_priva = 0,
BETA_privb = 0,
BETA_coma = 0,
BETA_comb = 0,
BETA_acca = 0,
BETA_accb = 0,
BETA_usea = 0,
BETA_useb = 0,
BETA_persa = 0,
BETA_persb = 0,
BETA_exta = 0,
BETA_extb = 0,
delta_alternative = 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()
#### 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[['app0']] = 0
V[['appA']] = delta_alternative + BETA_costa * cost1a + BETA_costb * cost1b + BETA_priva * priv1a + BETA_privb * priv1b + BETA_coma * com1a + BETA_comb + com1b + BETA_acca * acc1a + BETA_accb * acc1b + BETA_usea * use1a + BETA_useb * use1b + BETA_persa * pers1a + BETA_persb * pers1b + BETA_exta * ext1a + BETA_extb * ext1b
V[['appB']] = delta_alternative + BETA_costa * cost2a + BETA_costb * cost2b + BETA_priva * priv2a + BETA_privb * priv2b + BETA_coma * com2a + BETA_comb + com2b + BETA_acca * acc2a + BETA_accb * acc2b + BETA_usea * use2a + BETA_useb * use2b + BETA_persa * pers2a + BETA_persb * pers2b + BETA_exta * ext2a + BETA_extb * ext2b
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(app0=0, appA=1, appB=2),
avail = list(app0=1, appA=1, appB=1),
choiceVar = choice,
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 VALIDATION
###apollo_sink()
###apollo_outOfSample(apollo_beta,
### apollo_fixed,
### apollo_probabilities,
### apollo_inputs,
### outOfSample_settings = list (validationSize = 0.33))
###apollo_sink()
#### MODEL OUTPUTS
apollo_modelOutput(model,modelOutput_settings=list(printPVal=TRUE))
apollo_saveOutput(model)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
OUTPUT
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> #### MODEL ESTIMATION
> model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
Preparing user-defined functions.
Testing likelihood function...
Overview of choices for MNL model component :
app0 appA appB
Times available 1512.00 1512.0 1512.00
Times chosen 838.00 369.0 305.00
Percentage chosen overall 55.42 24.4 20.17
Percentage chosen when available 55.42 24.4 20.17
Pre-processing likelihood function...
Testing influence of parameters
Starting main estimation
BGW using analytic model derivatives supplied by caller...
Iterates will be written to:
/Users/evahogervorst/MNL_3_iterations.csv it nf F RELDF PRELDF RELDX MODEL stppar
0 1 1.786329956e+03
1 4 1.461998007e+03 1.816e-01 1.658e-01 1.00e+00 G 6.64e-01
2 5 1.339591379e+03 8.373e-02 8.482e-02 3.80e-01 G 1.40e-01
3 6 1.328959500e+03 7.937e-03 6.750e-03 3.32e-01 G 1.98e-15
4 7 1.328136826e+03 6.190e-04 6.480e-04 1.25e-01 S -1.88e-15
5 8 1.328087420e+03 3.720e-05 3.532e-05 3.82e-02 S -1.88e-15
6 9 1.328077082e+03 7.784e-06 6.242e-06 1.64e-01 S 3.63e-15
7 10 1.328075634e+03 1.090e-06 9.325e-07 8.49e-02 S -3.63e-15
8 11 1.328075408e+03 1.702e-07 1.228e-07 9.67e-02 S -3.63e-15
9 12 1.328075320e+03 6.573e-08 5.380e-08 3.65e-02 S -3.63e-15
10 13 1.328075304e+03 1.255e-08 9.449e-09 9.55e-02 S -3.63e-15
11 14 1.328075299e+03 3.270e-09 2.757e-09 5.89e-02 S -3.63e-15
12 15 1.328075299e+03 3.544e-10 2.929e-10 9.23e-02 S 0.00e+00
13 16 1.328075299e+03 3.417e-11 3.069e-11 7.18e-05 S 1.66e-14
***** Singular convergence *****
Estimated parameters:
Estimate
BETA_costa -0.821935
BETA_costb -0.113798
BETA_priva 0.532970
BETA_privb -0.082607
BETA_coma 0.073161
BETA_comb -2.428525
BETA_acca 1.009997
BETA_accb -0.129587
BETA_usea 0.316059
BETA_useb -0.177152
BETA_persa -0.008474
BETA_persb 0.221608
BETA_exta 0.152582
BETA_extb -0.035154
delta_alternative 1.034001
Final LL: -1328.0753
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 VALIDATION
>
> ###apollo_sink()
> ###apollo_outOfSample(apollo_beta,
> ### apollo_fixed,
> ### apollo_probabilities,
> ### apollo_inputs,
> ### outOfSample_settings = list (validationSize = 0.33))
> ###apollo_sink()
>
> #### MODEL OUTPUTS
> apollo_modelOutput(model,modelOutput_settings=list(printPVal=TRUE))