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.

'MNL' Best-worst estimation settings for Conjoint based dataset

Ask questions about how to estimate models and how to change your settings for estimation.
Post Reply
Yashin
Posts: 21
Joined: 23 Sep 2021, 01:43

'MNL' Best-worst estimation settings for Conjoint based dataset

Post by Yashin »

Dear Concern,

I have a conjoint based data set where I have recorded the responses of the respondents in a response column giving them best-worst choice experiment. Hence, the response column has been coded as effects coding as: best =1, worst =-1 and the rest/not chosen = 0.

Here is the code that I have used for MNL joint Best-worst estimation from the Apollo choice modeling forum (drug choice data):
N:B= Here, Concepts= alternatives, Response= Choice

rm(list = ls())
#install.packages("apollo")

### Load Apollo library
library(apollo)


### Initialise code
apollo_initialise()



### Set core controls
apollo_control = list(
modelName = "MNL",
modelDescr = "logit model for best-worst",
indivID = "sys_RespNum",
outputDirectory = "output"
)


database_A = read.csv("test_machen.csv",header=TRUE)
database_B = read.csv("CBC02.csv",header=TRUE)
total <- merge(database_A,database_B,by="sys_RespNum", all.database_B = TRUE)
#write.csv(total,"final.csv", row.names = FALSE)
database<-total


# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(b_Distance = 0,
b_Rev_Waiting_Time= 0,
b_Charging_Power= 0,
b_Charging_Time = 0,
b_Price = 0,
mu_worst= 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("b_Distance", "b_Rev_Waiting_Time", "b_Charging_Power", "b_Charging_Time", "b_Price")

# ################################################################# #
#### 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[["Concept1"]] = ( b_Distance*Distance==1 + b_Rev_Waiting_Time*(Rev_Waiting_Time==1)
+ b_Charging_Power*(Charging_Power==1) + b_Charging_Time*(Charging_Time==1)
+ b_Price*(Price==1))
V[["Concept2"]] = ( b_Distance*Distance==2 + b_Rev_Waiting_Time*(Rev_Waiting_Time==2)
+ b_Charging_Power*(Charging_Power==2) + b_Charging_Time*(Charging_Time==2)
+ b_Price*(Price==2))
V[["Concept3"]] = ( b_Distance*Distance==3 + b_Rev_Waiting_Time*(Rev_Waiting_Time==3)
+ b_Charging_Power*(Charging_Power==3) + b_Charging_Time*(Charging_Time==3)
+ b_Price*(Price==3))

### Compute probabilities for "best" choice using MNL model
mnl_settings_best = list(
alternatives = c(Concept1=1, Concept2=-1, Concept3=0),
avail = 1,
choiceVar = "Response"==1,
utilities = V,
componentName = "Response"
)
P[["choice_best"]] = apollo_mnl(mnl_settings_best, functionality)



### Compute probabilities for "worst" choice using MNL model
mnl_settings_worst = list(
alternatives = c(Concept1=1, Concept2=-1, Concept3=0),
avail = 1,
choiceVar = "Response"==1,
utilities = list(Concept1 = -mu_worst*V[["Concept1"]],
Concept2 = -mu_worst*V[["Concept2"]],
Concept3 = -mu_worst*V[["Concept3"]],
componentName = "Response"!=1 )
)

P[["choice_worst"]] = apollo_mnl(mnl_settings_worst, functionality)

### Combined model
P = apollo_combineModels(P, apollo_inputs, 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)

After this code, I am receiving the following information in my R console:


Testing likelihood function...
WARNING: some alternatives are never chosen in your data!
WARNING: Availability not provided (or some elements are NA). Full availability assumed.

Overview of choices for MNL model component Response:
Concept1 Concept2 Concept3
Times available 750 750 750.00
Times chosen 0 0 1.00
Percentage chosen overall 0 0 0.13
Percentage chosen when available 0 0 0.13
Apollo found a model component of type MNL without a componentName. The name was set to "choice_worst" by default.
WARNING: some alternatives are never chosen in your data!
WARNING: Availability not provided (or some elements are NA). Full availability assumed.

Overview of choices for MNL model component choice_worst:
Concept1 Concept2 Concept3
Times available 750 750 750.00
Times chosen 0 0 1.00
Percentage chosen overall 0 0 0.13
Percentage chosen when available 0 0 0.13

Pre-processing likelihood function...

Testing influence of parametersError in apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, :
Parameter mu_worst does not influence the log-likelihood of your model!


I am bit confused, which core setting do I have to change for using this Apollo package. Any suggestions will be highly appreciated.
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: 'MNL' Best-worst estimation settings for Conjoint based dataset

Post by stephanehess »

Hi

sorry, your description of the experiment/data is not very clear, and looking at the utilities doesn't really clarify it to me either. What did people see in the experiment?

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