INPUT ISSUE - values for "choiceVar" not included in "alternative
Posted: 17 Sep 2023, 04:13
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
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