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.

NaNs

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
TAJKUE
Posts: 7
Joined: 17 Sep 2020, 13:24

NaNs

Post by TAJKUE »

Hi forum,
I am trying to estimate an NLM and MNL Model, which seems to be working well. However, there is still the issue of the NaNs.

Here the complete output:
Model run using Apollo for R, version 0.1.0
www.ApolloChoiceModelling.com

Model name : MNL
Model description : MNL Model with Data
Model run at : 2020-09-17 17:41:22
Estimation method : bfgs
Model diagnosis : successful convergence
Number of individuals : 500
Number of observations : 2500

Number of cores used : 1
Model without mixing

LL(start) : -6309.866
LL(0) : -6309.866
LL(final) : -3451.108
Rho-square (0) : 0.4531
Adj.Rho-square (0) : 0.4513
AIC : 6924.22
BIC : 6988.28
Estimated parameters : 11
Time taken (hh:mm:ss) : 00:00:21.27
Iterations : 25
Min abs eigenvalue of hessian : 0
Some eigenvalues of hessian are positive, indicating potential problems!

Estimates:
Estimate Std.err. t.ratio(0) Rob.std.err. Rob.t.ratio(0)
b_tt_Price1 0.9851 NaN NaN 84.7746 0.01
b_tt_Price2 0.3528 NaN NaN 85.0660 0.00
b_tt_Price3 1.4685 NaN NaN 84.0435 0.02
b_tt_Price4 -0.5446 NaN NaN 84.2205 -0.01
b_tt_Brand 2.6037 NaN NaN 175.5951 0.01
b_tt_No_Name_Brand_1 1.5808 NaN NaN 192.7041 0.01
b_tt_No_Name_Brand_2 -1.9227 NaN NaN 175.4344 -0.01
b_tt_No_Bio -1.6127 NaN NaN 92.7732 -0.02
b_tt_Yes_Bio 3.8745 NaN NaN NaN NaN
b_tt_Outside_Option1 -1.0949 3576.351 0 63.4085 -0.02
b_tt_Outside_Option2 -1.1669 3576.351 0 60.9444 -0.02

Overview of choices for model component "MNL"
B11 B12 B13 B14 B21 B22 B23 B24 NB111 NB112 NB113 NB114 NB121 NB122 NB123 NB124 NB211 NB212
Times available 1319.00 1261.00 1279.00 1282.00 1283.00 1263.00 1275.00 1268.00 1343.00 1292.00 1296.00 1304.00 1328.00 1301 1309.00 1312.00 1329.00 1289
Times chosen 604.00 354.00 265.00 35.00 110.00 69.00 41.00 11.00 14.00 1.00 535.00 103.00 1.00 0 112.00 16.00 2.00 0
Percentage chosen overall 24.16 14.16 10.60 1.40 4.40 2.76 1.64 0.44 0.56 0.04 21.40 4.12 0.04 0 4.48 0.64 0.08 0
Percentage chosen when available 45.79 28.07 20.72 2.73 8.57 5.46 3.22 0.87 1.04 0.08 41.28 7.90 0.08 0 8.56 1.22 0.15 0
NB213 NB214 NB221 NB222 NB223 NB224 OO1 OO2
Times available 1269.00 1288.00 1299 1278 1264.00 1285.00 2500.00 2500.00
Times chosen 62.00 16.00 0 0 8.00 2.00 72.00 67.00
Percentage chosen overall 2.48 0.64 0 0 0.32 0.08 2.88 2.68
Percentage chosen when available 4.89 1.24 0 0 0.63 0.16 2.88 2.68

WARNING: some alternatives are never chosen in your data!


My assumption is that it comes from my data. Here an example of my the first individual´s choice:
ID Brand No_Name_Brand_1 No_Name_Brand_2 No_Bio Yes_Bio Price1 Price2 Price3 Price4 female Outside_Option1 Outside_Option2 AV_Barilla11 AV_Barilla12 AV_Barilla13 AV_Barilla14 AV_Barilla21 AV_Barilla22 AV_Barilla23 AV_Barilla24 AV_NoNameBrand111 AV_NoNameBrand112 AV_NoNameBrand113 AV_NoNameBrand114 AV_NoNameBrand121 AV_NoNameBrand122 AV_NoNameBrand123 AV_NoNameBrand124 AV_NoNameBrand211 AV_NoNameBrand212 AV_NoNameBrand213 AV_NoNameBrand214 AV_NoNameBrand221 AV_NoNameBrand222 AV_NoNameBrand223 AV_NoNameBrand224 AV_Outside1 AV_Outside2 choice
1 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11

and here the code:
# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS ####
# ################################################################# #

### Clear memory
rm(list = ls())

### Load Apollo library
library(apollo)

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
modelName ="MNL",
modelDescr ="MNL Model with Data",
indivID ="ID"
)

# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #

database = read.csv("Data_Model.csv",
fileEncoding="UTF-8-BOM",
sep = ";",
header = TRUE)


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

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(b_tt_Price1 = 0,
b_tt_Price2 = 0,
b_tt_Price3 = 0,
b_tt_Price4 = 0,
b_tt_Brand = 0,
b_tt_No_Name_Brand_1 =0,
b_tt_No_Name_Brand_2 =0,
b_tt_No_Bio = 0,
b_tt_Yes_Bio =0,
b_tt_Outside_Option1 =0,
b_tt_Outside_Option2 =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_settings$bootstrapSE=TRUE"){

### 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[['B11']] = b_tt_Price1*AV_Barilla11 + b_tt_Yes_Bio*AV_Barilla11 + b_tt_Brand*AV_Barilla11
V[['B12']] = b_tt_Price2 *AV_Barilla12+ b_tt_Yes_Bio *AV_Barilla12+ b_tt_Brand*AV_Barilla12
V[['B13']] = b_tt_Price3 *AV_Barilla13 + b_tt_Yes_Bio*AV_Barilla13 + b_tt_Brand*AV_Barilla13
V[['B14']] = b_tt_Price4 *AV_Barilla14+ b_tt_Yes_Bio*AV_Barilla14 + b_tt_Brand*AV_Barilla14
V[['B21']] = b_tt_Price1*AV_Barilla21 + b_tt_No_Bio*AV_Barilla21 + b_tt_Brand*AV_Barilla21
V[['B22']] = b_tt_Price2*AV_Barilla22 + b_tt_No_Bio*AV_Barilla22 + b_tt_Brand*AV_Barilla22
V[['B23']] = b_tt_Price3 *AV_Barilla23+ b_tt_No_Bio*AV_Barilla23 + b_tt_Brand*AV_Barilla23
V[['B24']] = b_tt_Price4*AV_Barilla24 + b_tt_No_Bio*AV_Barilla24 + b_tt_Brand*AV_Barilla24
V[['NB111']] = b_tt_Price1*AV_NoNameBrand111 + b_tt_Yes_Bio*AV_NoNameBrand111 + b_tt_No_Name_Brand_1*AV_NoNameBrand111
V[['NB112']] = b_tt_Price2*AV_NoNameBrand112 + b_tt_Yes_Bio*AV_NoNameBrand112 + b_tt_No_Name_Brand_1*AV_NoNameBrand112
V[['NB113']] = b_tt_Price3*AV_NoNameBrand113 + b_tt_Yes_Bio*AV_NoNameBrand113 + b_tt_No_Name_Brand_1*AV_NoNameBrand113
V[['NB114']] = b_tt_Price4*AV_NoNameBrand114 + b_tt_Yes_Bio*AV_NoNameBrand114 + b_tt_No_Name_Brand_1*AV_NoNameBrand114
V[['NB121']] = b_tt_Price1 *AV_NoNameBrand121+ b_tt_No_Bio*AV_NoNameBrand121 + b_tt_No_Name_Brand_1*AV_NoNameBrand121
V[['NB122']] = b_tt_Price2 *AV_NoNameBrand122+ b_tt_No_Bio*AV_NoNameBrand122 + b_tt_No_Name_Brand_1*AV_NoNameBrand122
V[['NB123']] = b_tt_Price3*AV_NoNameBrand123 + b_tt_No_Bio*AV_NoNameBrand123 + b_tt_No_Name_Brand_1*AV_NoNameBrand123
V[['NB124']] = b_tt_Price4*AV_NoNameBrand124 + b_tt_No_Bio*AV_NoNameBrand124 + b_tt_No_Name_Brand_1*AV_NoNameBrand124
V[['NB211']] = b_tt_Price1 *AV_NoNameBrand211+ b_tt_Yes_Bio*AV_NoNameBrand211 + b_tt_No_Name_Brand_2*AV_NoNameBrand211
V[['NB212']] = b_tt_Price2 *AV_NoNameBrand212+ b_tt_Yes_Bio*AV_NoNameBrand212 + b_tt_No_Name_Brand_2*AV_NoNameBrand212
V[['NB213']] = b_tt_Price3 *AV_NoNameBrand213 + b_tt_Yes_Bio*AV_NoNameBrand213 + b_tt_No_Name_Brand_2*AV_NoNameBrand213
V[['NB214']] = b_tt_Price4*AV_NoNameBrand214 + b_tt_Yes_Bio*AV_NoNameBrand214 + b_tt_No_Name_Brand_2*AV_NoNameBrand214
V[['NB221']] = b_tt_Price1*AV_NoNameBrand221 + b_tt_No_Bio *AV_NoNameBrand221+ b_tt_No_Name_Brand_2*AV_NoNameBrand221
V[['NB222']] = b_tt_Price2*AV_NoNameBrand222 + b_tt_No_Bio *AV_NoNameBrand222+ b_tt_No_Name_Brand_2*AV_NoNameBrand222
V[['NB223']] = b_tt_Price3*AV_NoNameBrand223 + b_tt_No_Bio*AV_NoNameBrand223 + b_tt_No_Name_Brand_2*AV_NoNameBrand223
V[['NB224']] = b_tt_Price4*AV_NoNameBrand224 + b_tt_No_Bio*AV_NoNameBrand224 + b_tt_No_Name_Brand_2*AV_NoNameBrand224
V[['OO1']] = b_tt_Outside_Option1*AV_Outside1
V[['OO2']] = b_tt_Outside_Option2*AV_Outside2

### Define settings for MNL model component
mnl_settings = list(
alternatives = c(B11=1, B12=2, B13=3, B14=4, B21=5, B22=6,B23=7, B24=8,
NB111=9, NB112=10, NB113=11,NB114=12, NB121=13, NB122=14,NB123=15,NB124=16,
NB211=17, NB212=18, NB213=19,NB214=20, NB221=21, NB222=22,NB223=23,NB224=24,
OO1=25, OO2=26),
avail = list(B11=AV_Barilla11, B12=AV_Barilla12, B13=AV_Barilla13, B14=AV_Barilla14,
B21=AV_Barilla21, B22=AV_Barilla22, B23=AV_Barilla23, B24=AV_Barilla24,
NB111=AV_NoNameBrand111, NB112=AV_NoNameBrand112, NB113=AV_NoNameBrand113, NB114=AV_NoNameBrand114,
NB121=AV_NoNameBrand121, NB122=AV_NoNameBrand122, NB123=AV_NoNameBrand123, NB124=AV_NoNameBrand124,
NB211=AV_NoNameBrand211, NB212=AV_NoNameBrand212, NB213=AV_NoNameBrand213, NB214=AV_NoNameBrand214,
NB221=AV_NoNameBrand221, NB222=AV_NoNameBrand222, NB223=AV_NoNameBrand223, NB224=AV_NoNameBrand224,
OO1=AV_Outside1, OO2=AV_Outside2),
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)



It would be great, if you could help me.

Thanks upfront & regards,
Tibor
stephanehess
Site Admin
Posts: 1042
Joined: 24 Apr 2020, 16:29

Re: NaNs

Post by stephanehess »

Hi

your model is most overspecified. If I understand it correctly, which is not clear without the data, then I think you need to apply a normalisation for each of the sets of parameters, namely one each in the the price, the brand, the bio, and the outside groups of params

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
TAJKUE
Posts: 7
Joined: 17 Sep 2020, 13:24

Re: NaNs

Post by TAJKUE »

Hi Stephane,
the data is in a binary structure e.g. if Price 1 is offered it is 1 and if not it is 0. This then has an impact on the alternatives offered means if Price 1 is not offered all alternatives that have it as an characteristic are not available (for the example of Price 1 not being offered alternatives B11,B21, NB111, NB121, NB211, NB221 are not available also in the AV variable).
The same is true for the other characteristics: Price 2, Price 3, Price 4, Yes_Bio, No_Bio, Brand, NoBrand1, NoBrand2, Outside_Option1 and Outside_Option2.
I hope this makes things clearer.

How would a normalization work of this data? Is it even feasible since we´re talking about binary variables?
stephanehess
Site Admin
Posts: 1042
Joined: 24 Apr 2020, 16:29

Re: NaNs

Post by stephanehess »

Hi

if none of the binary variables are not perfectly collinear, then you should be able to estimate the model by using a normalisation in each group, so e.g. fixing the parameters for price1, Yes_Bio, Brand, Outside_Option1. the last one might be too restrictive but you get the idea

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
TAJKUE
Posts: 7
Joined: 17 Sep 2020, 13:24

Re: NaNs

Post by TAJKUE »

Hi Stephane,
Thanks a lot! I got rid of the NaNs now.

Do you have any recommendations around which value I should fix the parameters?
stephanehess
Site Admin
Posts: 1042
Joined: 24 Apr 2020, 16:29

Re: NaNs

Post by stephanehess »

Only differences in utility matter, so the normalisation is arbitrary
--------------------------------
Stephane Hess
www.stephanehess.me.uk
TAJKUE
Posts: 7
Joined: 17 Sep 2020, 13:24

Re: NaNs

Post by TAJKUE »

Thank you so much! The model is working now.

I tried the same with NLM. However, the solution isn´t the same at least it seems so.

Here the model outputs:
Model run using Apollo for R, version 0.1.0
www.ApolloChoiceModelling.com

Model name : NL Model
Model description : NL Model with data
Model run at : 2020-09-18 15:01:57
Estimation method : bfgs
Model diagnosis : successful convergence
Number of individuals : 500
Number of observations : 2500

Number of cores used : 1
Model without mixing

LL(start) : -5261.186
LL(0) : -6309.866
LL(final) : -3021.326
Rho-square (0) : 0.5212
Adj.Rho-square (0) : 0.5197
AIC : 6060.65
BIC : 6113.07
Estimated parameters : 9
Time taken (hh:mm:ss) : 00:00:30.13
Iterations : 28

Estimates:
Estimate Std.err. t.ratio(0) Rob.std.err. Rob.t.ratio(0)
b_tt_Price1 1.0000 NA NA NA NA
b_tt_Price2 0.8723 NA NA NA NA
b_tt_Price3 1.2341 NA NA NA NA
b_tt_Price4 1.0481 NA NA NA NA
b_tt_Brand 1.0000 NA NA NA NA
b_tt_No_Name_Brand_1 1.5531 NA NA NA NA
b_tt_No_Name_Brand_2 0.2500 NA NA NA NA
b_tt_No_Bio -3.4191 NA NA NA NA
b_tt_Yes_Bio 1.0000 NA NA NA NA
b_tt_Outside_Option1 1.0000 NA NA NA NA
b_tt_Outside_Option2 -1.1192 NA NA NA NA
lambda_Brand 1.3338 NA NA NA NA
lambda_NoBrand 0.0066 NA NA NA NA
lambda_outside -1.2196 NA NA NA NA

Overview of choices for model component "NL"
B11 B12 B13 B14 B21 B22 B23 B24 NB111 NB112 NB113 NB114 NB121 NB122 NB123 NB124 NB211 NB212
Times available 1319.00 1261.00 1279.00 1282.00 1283.00 1263.00 1275.00 1268.00 1343.00 1292.00 1296.00 1304.00 1328.00 1301 1309.00 1312.00 1329.00 1289
Times chosen 604.00 354.00 265.00 35.00 110.00 69.00 41.00 11.00 14.00 1.00 535.00 103.00 1.00 0 112.00 16.00 2.00 0
Percentage chosen overall 24.16 14.16 10.60 1.40 4.40 2.76 1.64 0.44 0.56 0.04 21.40 4.12 0.04 0 4.48 0.64 0.08 0
Percentage chosen when available 45.79 28.07 20.72 2.73 8.57 5.46 3.22 0.87 1.04 0.08 41.28 7.90 0.08 0 8.56 1.22 0.15 0
NB213 NB214 NB221 NB222 NB223 NB224 OO1 OO2
Times available 1269.00 1288.00 1299 1278 1264.00 1285.00 2500.00 2500.00
Times chosen 62.00 16.00 0 0 8.00 2.00 72.00 67.00
Percentage chosen overall 2.48 0.64 0 0 0.32 0.08 2.88 2.68
Percentage chosen when available 4.89 1.24 0 0 0.63 0.16 2.88 2.68

Warning: some alternatives are never chosen in your data!
Nesting structure:
Nest: root (1)
|-Nest: Brand (1.3338)
| |-Alternative: B11
| |-Alternative: B12
| |-Alternative: B13
| |-Alternative: B14
| |-Alternative: B21
| |-Alternative: B22
| |-Alternative: B23
| '-Alternative: B24
|-Nest: NoBrand (0.0066)
| |-Alternative: NB111
| |-Alternative: NB112
| |-Alternative: NB113
| |-Alternative: NB114
| |-Alternative: NB211
| |-Alternative: NB212
| |-Alternative: NB213
| |-Alternative: NB214
| |-Alternative: NB121
| |-Alternative: NB122
| |-Alternative: NB123
| |-Alternative: NB124
| |-Alternative: NB221
| |-Alternative: NB222
| |-Alternative: NB223
| '-Alternative: NB224
'-Nest: Outside (-1.2196)
|-Alternative: OO1
'-Alternative: OO2


and here the code:
# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS ####
# ################################################################# #

### Clear memory
rm(list = ls())

### Load Apollo library
library(apollo)

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
modelName ="NL Model",
modelDescr ="NL Model with data",
indivID ="ID"
)

# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #

database = read.csv("Data_Model.csv",
fileEncoding="UTF-8-BOM",
sep = ";",
header = TRUE)


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

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(b_tt_Price1 = 1,
b_tt_Price2 = 0,
b_tt_Price3 = 0,
b_tt_Price4 = 0,
b_tt_Brand = 1,
b_tt_No_Name_Brand_1 =0,
b_tt_No_Name_Brand_2 =0.25,
b_tt_No_Bio = 0,
b_tt_Yes_Bio =1,
b_tt_Outside_Option1 =1,
b_tt_Outside_Option2 =0,
lambda_Brand=0.95,
lambda_NoBrand=0.95,
lambda_outside=0.95
)


### 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_tt_Price1","b_tt_Yes_Bio","b_tt_No_Name_Brand_2","b_tt_Outside_Option1","b_tt_Brand")


# ################################################################# #
#### 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 nl_settings, order is irrelevant
V = list()
V[['B11']] = b_tt_Price1*AV_Barilla11 + b_tt_Yes_Bio*AV_Barilla11 + b_tt_Brand*AV_Barilla11
V[['B12']] = b_tt_Price2 *AV_Barilla12+ b_tt_Yes_Bio *AV_Barilla12+ b_tt_Brand*AV_Barilla12
V[['B13']] = b_tt_Price3 *AV_Barilla13 + b_tt_Yes_Bio*AV_Barilla13 + b_tt_Brand*AV_Barilla13
V[['B14']] = b_tt_Price4 *AV_Barilla14+ b_tt_Yes_Bio*AV_Barilla14 + b_tt_Brand*AV_Barilla14
V[['B21']] = b_tt_Price1*AV_Barilla21 + b_tt_No_Bio*AV_Barilla21 + b_tt_Brand*AV_Barilla21
V[['B22']] = b_tt_Price2*AV_Barilla22 + b_tt_No_Bio*AV_Barilla22 + b_tt_Brand*AV_Barilla22
V[['B23']] = b_tt_Price3 *AV_Barilla23+ b_tt_No_Bio*AV_Barilla23 + b_tt_Brand*AV_Barilla23
V[['B24']] = b_tt_Price4*AV_Barilla24 + b_tt_No_Bio*AV_Barilla24 + b_tt_Brand*AV_Barilla24
V[['NB111']] = b_tt_Price1*AV_NoNameBrand111 + b_tt_Yes_Bio*AV_NoNameBrand111 + b_tt_No_Name_Brand_1*AV_NoNameBrand111
V[['NB112']] = b_tt_Price2*AV_NoNameBrand112 + b_tt_Yes_Bio*AV_NoNameBrand112 + b_tt_No_Name_Brand_1*AV_NoNameBrand112
V[['NB113']] = b_tt_Price3*AV_NoNameBrand113 + b_tt_Yes_Bio*AV_NoNameBrand113 + b_tt_No_Name_Brand_1*AV_NoNameBrand113
V[['NB114']] = b_tt_Price4*AV_NoNameBrand114 + b_tt_Yes_Bio*AV_NoNameBrand114 + b_tt_No_Name_Brand_1*AV_NoNameBrand114
V[['NB121']] = b_tt_Price1 *AV_NoNameBrand121+ b_tt_No_Bio*AV_NoNameBrand121 + b_tt_No_Name_Brand_1*AV_NoNameBrand121
V[['NB122']] = b_tt_Price2 *AV_NoNameBrand122+ b_tt_No_Bio*AV_NoNameBrand122 + b_tt_No_Name_Brand_1*AV_NoNameBrand122
V[['NB123']] = b_tt_Price3*AV_NoNameBrand123 + b_tt_No_Bio*AV_NoNameBrand123 + b_tt_No_Name_Brand_1*AV_NoNameBrand123
V[['NB124']] = b_tt_Price4*AV_NoNameBrand124 + b_tt_No_Bio*AV_NoNameBrand124 + b_tt_No_Name_Brand_1*AV_NoNameBrand124
V[['NB211']] = b_tt_Price1 *AV_NoNameBrand211+ b_tt_Yes_Bio*AV_NoNameBrand211 + b_tt_No_Name_Brand_2*AV_NoNameBrand211
V[['NB212']] = b_tt_Price2 *AV_NoNameBrand212+ b_tt_Yes_Bio*AV_NoNameBrand212 + b_tt_No_Name_Brand_2*AV_NoNameBrand212
V[['NB213']] = b_tt_Price3 *AV_NoNameBrand213 + b_tt_Yes_Bio*AV_NoNameBrand213 + b_tt_No_Name_Brand_2*AV_NoNameBrand213
V[['NB214']] = b_tt_Price4*AV_NoNameBrand214 + b_tt_Yes_Bio*AV_NoNameBrand214 + b_tt_No_Name_Brand_2*AV_NoNameBrand214
V[['NB221']] = b_tt_Price1*AV_NoNameBrand221 + b_tt_No_Bio *AV_NoNameBrand221+ b_tt_No_Name_Brand_2*AV_NoNameBrand221
V[['NB222']] = b_tt_Price2*AV_NoNameBrand222 + b_tt_No_Bio *AV_NoNameBrand222+ b_tt_No_Name_Brand_2*AV_NoNameBrand222
V[['NB223']] = b_tt_Price3*AV_NoNameBrand223 + b_tt_No_Bio*AV_NoNameBrand223 + b_tt_No_Name_Brand_2*AV_NoNameBrand223
V[['NB224']] = b_tt_Price4*AV_NoNameBrand224 + b_tt_No_Bio*AV_NoNameBrand224 + b_tt_No_Name_Brand_2*AV_NoNameBrand224
V[['OO1']] = b_tt_Outside_Option1*AV_Outside1
V[['OO2']] = b_tt_Outside_Option2*AV_Outside2

### Specify nests for NL model
nlNests = list(root=1, Brand=lambda_Brand, NoBrand = lambda_NoBrand, Outside = lambda_outside)

### Specify tree structure for NL model
nlStructure= list()
nlStructure[["root"]] = c("Brand", "NoBrand","Outside")
nlStructure[["Brand"]] = c("B11","B12","B13","B14",
"B21","B22","B23","B24")
nlStructure[["NoBrand"]] = c("NB111","NB112","NB113","NB114",
"NB211","NB212","NB213","NB214",
"NB121","NB122","NB123","NB124",
"NB221","NB222","NB223","NB224")
nlStructure[["Outside"]] = c("OO1","OO2")

### Define settings for NL model
nl_settings <- list(
alternatives = c(B11=1, B12=2, B13=3, B14=4, B21=5, B22=6,B23=7, B24=8,
NB111=9, NB112=10, NB113=11,NB114=12, NB121=13, NB122=14,NB123=15,NB124=16,
NB211=17, NB212=18, NB213=19,NB214=20, NB221=21, NB222=22,NB223=23,NB224=24,
OO1=25, OO2=26),
avail = list(B11=AV_Barilla11, B12=AV_Barilla12, B13=AV_Barilla13, B14=AV_Barilla14,
B21=AV_Barilla21, B22=AV_Barilla22, B23=AV_Barilla23, B24=AV_Barilla24,
NB111=AV_NoNameBrand111, NB112=AV_NoNameBrand112, NB113=AV_NoNameBrand113, NB114=AV_NoNameBrand114,
NB121=AV_NoNameBrand121, NB122=AV_NoNameBrand122, NB123=AV_NoNameBrand123, NB124=AV_NoNameBrand124,
NB211=AV_NoNameBrand211, NB212=AV_NoNameBrand212, NB213=AV_NoNameBrand213, NB214=AV_NoNameBrand214,
NB221=AV_NoNameBrand221, NB222=AV_NoNameBrand222, NB223=AV_NoNameBrand223, NB224=AV_NoNameBrand224,
OO1=AV_Outside1, OO2=AV_Outside2),
choiceVar = choice,
V = V,
nlNests = nlNests,
nlStructure = nlStructure
)

### Compute probabilities using NL model
P[["model"]] = apollo_nl(nl_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)


The data is the same as for the MNL-Model.
stephanehess
Site Admin
Posts: 1042
Joined: 24 Apr 2020, 16:29

Re: NaNs

Post by stephanehess »

Again, without knowing your data, I can only hypothesise that this is because your last nest contains two alternatives that are never both available at the same time.
--------------------------------
Stephane Hess
www.stephanehess.me.uk
TAJKUE
Posts: 7
Joined: 17 Sep 2020, 13:24

Re: NaNs

Post by TAJKUE »

Regarding the nests: if one outside option is available so is the other. However, there are cases where no Brand and none of the two NoNameBrands is available.
stephanehess
Site Admin
Posts: 1042
Joined: 24 Apr 2020, 16:29

Re: NaNs

Post by stephanehess »

Sorry, difficult to follow without having the data, etc. I suggest you try a model first with one of the nesting parameters freely estimated, and the others set to 1, and then find out where the identification issue is.

btw, for the normalised parameters from earlier, a value of 0 makes more sense than a value of 1.
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Post Reply