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.

Error in MNL model

Ask questions about model specifications. Ideally include a mathematical explanation of your proposed model.
Post Reply
Waldo
Posts: 2
Joined: 04 Apr 2023, 08:33

Error in MNL model

Post by Waldo »

Dear Apollo team,

I'm estimating a MNL model, largely following example 1 (model MNL_RP) on the example and code page. The model is made-up of 2 choice sets, each of which contains 1 attribute with 4 levels, 2 attributes with 3 levels and 1 attribute with 2 levels, resulting in a total of 8 dummy variables per choice set. I have two specific questions about the model specification.

1) When estimating the model I run into the following warning message:

In sqrt(diag(robvarcov)) : NaNs produced

In the next step it turns out to be impossible to print the P-values (they are NaN or the R-software freezes altogether). Do you have any idea what is happening and is there any way to resolve this issue? I noticed that there is a high degree of collinearity (Cramer’s V of 0.79) among some of the dummy variables, could this be the problem? And if so, is there a model available in the Apollo package which would be better suited to estimating a model with multicollinearity issues? I have explored the Apollo manual and forum but so far I have not been able to tackle the problem.

2) Instead of a dummy coded model I would like to fit the model using effects coding. I found the example script on the example and code page (MNL_SP_effects) but I am not a very experienced R-user and it proves very difficult to incorporate the suggested scripts in the Apollo code that I am using to estimate my model. I found a previous forum thread about this topic (here) but without a conclusive solution. Would you have any suggestion as to what changes to the current code I would have to make to make the code suitable for effect-coded data?
I am using the following code to estimate the model:

apollo_initialise()
apollo_control <- list(
modelName = "CL_apollo",
modelDescr = "Patient preferences for treatment",
indivID = "ID")
database<-DCM
apollo_beta <- c(
b_infection_min100 = 0,
b_infection_plus100 = 0,
b_infection_plus500 = 0,
b_bleeding_high = 0,
b_transfusion_5jaar = 0,
b_transfusion_25jaar = 0,
b_fatigue_5 = 0,
b_fatigue_10 = 0
)
apollo_fixed <- c()
apollo_inputs <- apollo_validateInputs()

apollo_probabilities <- function(apollo_beta, apollo_inputs, functionality = "estimate"){
apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))

P <- list()

V <- list()
V[['alt1']] = b_infection_min100* infection_min100.1 + b_infection_plus100 * infection_plus100.1 + b_infection_plus500 * infection_plus500.1 + b_bleeding_high * bleeding_high.1 +
b_transfusion_5jaar * transfusion_5jaar.1 + b_transfusion_25jaar * transfusion_25jaar.1 + b_fatigue_5* fatigue_5.1 + b_fatigue_10 * fatigue_10.1
V[['alt2']] = b_infection_min100* infection_min100.2 + b_infection_plus100 * infection_plus100.2 + b_infection_plus500 * infection_plus500.2 + b_bleeding_high * bleeding_high.2 +
b_transfusion_5jaar * transfusion_5jaar.2 + b_transfusion_25jaar * transfusion_25jaar.2 + b_fatigue_5* fatigue_5.2 + b_fatigue_10 * fatigue_10.2

mnl_settings <- list(
alternatives = c(alt1 = 1, alt2 = 2),
avail = list(alt1 = 1, alt2 = 1),
choiceVar = choice,
V = V
)

P[['model']] <- apollo_mnl(mnl_settings, functionality)
P <- apollo_panelProd(P, apollo_inputs, functionality)
P <- apollo_prepareProb(P, apollo_inputs, functionality)

return(P)
}
model <- apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
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
Computing covariance matrix using analytical gradient.
0%....25%....50%....75%.100%
WARNING: Some eigenvalues of the Hessian are complex,
indicating that the Hessian is not symmetrical.
Computing score matrix...

Warning message:
In sqrt(diag(robvarcov)) : NaNs produced

Best regards, Waldo
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: Error in MNL model

Post by stephanehess »

Hi

apologies for the slow reply, the forum was offline

1) can you share your outputs so we can help understand? It looks like an overspecification - are you sure you are normalising appropriately
2) regarding effects coding, the example is how to do it in Apollo, but of course note that effects coding is not giving you any advantages over dummy coding, and you can just use the dummy coding results and rescale them afterwards if you want

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