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.

INPUT ISSUE - values for "choiceVar" not included in "alternative

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
Post Reply
JamesNind
Posts: 3
Joined: 16 Sep 2023, 04:51

INPUT ISSUE - values for "choiceVar" not included in "alternative

Post by JamesNind »

Kia ora,

I am developing a choice model where participants are asked to choose between 3 unlabeled pharmacies. I have collected some pilot data and processed it using the apollo_LongtoWide function. but have been unable to analyse it so far. I have been stopped by the error message: INPUT ISSUE - The data contains values for "choiceVar" for model component "model" that are not included in "alternatives". I believe I have a syntax error as my "choice_new" column only includes values 1,2,3. I have attached my code and data set and would appreciate any advice.

rm(list = ls())
library(apollo)
library(readxl)
library(tidyverse)

apollo_initialise()
apollo_control = list(
modelName = "MNL-pilot",
modelDescr = "MNL analysis of pilot data",
indivID = "id",
outputDirectory = "output"
)

database = read_csv("/Users/jamesnind/Library/CloudStorage/OneDrive-UniversityofOtago/Working documents/DCE/Pilot/Apollo_LongtoWide.csv")
headers=TRUE

apollo_beta=c( "b_l_10_minutes_1" = 0,
"b_l_20_minutes_1" = 0,
"b_l_30_minutes_1" = 0,
"b_l_10_minutes_2" = 0,
"b_l_20_minutes_2" = 0,
"b_l_30_minutes_2" = 0,
"b_l_10_minutes_3" = 0,
"b_l_20_minutes_3" = 0,
"b_l_30_minutes_3" = 0,

"b_x1_star_1" = 0,
"b_x3_star_1" = 0,
"b_x5_star_1" = 0,
"b_x1_star_2" = 0,
"b_x3_star_2" = 0,
"b_x5_star_2" = 0,
"b_x1_star_3" = 0,
"b_x3_star_3" = 0,
"b_x5_star_3" = 0,

"b_wt_5_minutes_1" = 0,
"b_wt_15_minutes_1" =0,
"b_wt_30_minutes_1" = 0,
"b_wt_5_minutes_2" = 0,
"b_wt_15_minutes_2" =0,
"b_wt_30_minutes_2" = 0,
"b_wt_5_minutes_3" = 0,
"b_wt_15_minutes_3" =0,
"b_wt_30_minutes_3" = 0,

"b_supermarket_1" = 0,
"b_doctors_1" = 0,
"b_nothing_1" = 0,
"b_supermarket_2" = 0,
"b_doctors_2" = 0,
"b_nothing_2" = 0,
"b_supermarket_3" = 0,
"b_doctors_3" = 0,
"b_nothing_3" = 0,

"b_pc_0_1" = 0,
"b_pc_5_1" = 0,
"b_pc_15_1" = 0,
"b_pc_0_2" = 0,
"b_pc_5_2" = 0,
"b_pc_15_2" = 0,
"b_pc_0_3" = 0,
"b_pc_5_3" = 0,
"b_pc_15_3" = 0,

"b_limited_1" = 0,
"b_available_1" = 0,
"b_limited_2" = 0,
"b_available_2" = 0,
"b_limited_3" = 0,
"b_available_3" = 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[["A"]] = "l_10_minutes_1 + l_20_minutes_1 + l_30_minutes_1 + x1_star_1 + x3_star_1 + x5_star_1 + wt_5 minutes_1 + wt_15_minutes_1 + wt_30_minutes_1
+ supermarket_1 + doctors_1 + nothing_1 + pc_0_1 + pc_5_1 + pc_15_1 + limited_1 + available_1"
V[["B"]] = "l_10_minutes_2 + l_20_minutes_2 + l_30_minutes_2 + x1_star_2 + x3_star_2 + x5_star_2 + wt_5 minutes_2 + wt_15_minutes_2 + wt_30_minutes_2
+ b_supermarket_2 + b_doctors_2 + b_nothing_2 + b_pc_0_2 + b_pc_5_2 + b_pc_15_2 + b_limited_2 + b_available_2"
V[["C"]] = "l_10_minutes_3 + l_20_minutes_3 + l_30_minutes_3 + x1_star_3 + x3_star_3 + x5_star_3 + wt_5 minutes_3 + wt_15_minutes_3 + wt_30_minutes_3
+ supermarket_3 + doctors_3 + nothing_3 + pc_0_3 + pc_5_3 + pc_15_3 + limited_3 + available_3"

mnl_settings = list (
alternatives = c(A=1, B=2, C=3),
avail = 1,
choiceVar = "choice_new",
utilities = 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)

Column headers:
cs id resp age ethnicity gender income pharmacy_use med_burden dep_quin gid l_10_minutes_1 l_20_minutes_1 l_30_minutes_1 x1_star_1 x3_star_1 x5_star_1 wt_5_minutes_1 wt_15_minutes_1 wt_30_minutes_1 supermarket_1 doctors_1 nothing_1 pc_0_1 pc_5_1 pc_15_1 limited_1 available_1 avail_1 l_10_minutes_2 l_20_minutes_2 l_30_minutes_2 x1_star_2 x3_star_2 x5_star_2 wt_5_minutes_2 wt_15_minutes_2 wt_30_minutes_2 supermarket_2 doctors_2 nothing_2 pc_0_2 pc_5_2 pc_15_2 limited_2 available_2 avail_2 l_10_minutes_3 l_20_minutes_3 l_30_minutes_3 x1_star_3 x3_star_3 x5_star_3 wt_5_minutes_3 wt_15_minutes_3 wt_30_minutes_3 supermarket_3 doctors_3 nothing_3 pc_0_3 pc_5_3 pc_15_3 limited_3 available_3 avail_3 choice_new

Thank you for your help and apologies if this is a simple question
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: INPUT ISSUE - values for "choiceVar" not included in "alternative

Post by stephanehess »

Hi

this might not be the cause, but can you remove the quotation marks around choice_new?

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
JamesNind
Posts: 3
Joined: 16 Sep 2023, 04:51

Re: INPUT ISSUE - values for "choiceVar" not included in "alternative

Post by JamesNind »

Thank you Stephane, that has removed that error message.

I now have an error stating I have values that are not finite numbers, I read one of your previous replies which recommended checking for missing data however I have no blank or NA cells. Do you have any suggestions for this problem?

Cheers,
James
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: INPUT ISSUE - values for "choiceVar" not included in "alternative

Post by stephanehess »

Can you show me the full output?
--------------------------------
Stephane Hess
www.stephanehess.me.uk
JamesNind
Posts: 3
Joined: 16 Sep 2023, 04:51

Re: INPUT ISSUE - values for "choiceVar" not included in "alternative

Post by JamesNind »

Thank you Stephane

Testing likelihood function...
Error in apollo_mnl(c(mnl_settings, componentName2 = "model"), functionality) :
CALCULATION ISSUE - Some utilities for model component "model" contain values that are not finite numbers!
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: INPUT ISSUE - values for "choiceVar" not included in "alternative

Post by stephanehess »

You also have quotation marks in your utilities. They should not be there as they are otherwise seen as text
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Post Reply