2

I'm trying to do discrete choice modeling on the below data. Basically, 30 customers have 16 different choices of pizza. They can choose more than 1 type of pizza and the ones they choose is indicated by choice variable.

pizza   cust choice pan thin pineapple veggie sausage romano mozarella oz
1      1  Cust1      0   1    0         1      0       0      1         0  1
2      2  Cust1      1   0    1         1      0       0      0         0  0
3      3  Cust1      0   0    0         1      0       0      0         1  1
4      4  Cust1      1   0    1         1      0       0      0         0  0
5      5  Cust1      1   1    0         0      1       0      0         0  1
6      6  Cust1      0   0    1         0      1       0      1         0  0
7      7  Cust1      0   0    0         0      1       0      0         0  1
8      8  Cust1      1   0    1         0      1       0      0         1  0
9      9  Cust1      0   1    0         0      0       1      0         1  0
10    10  Cust1      1   0    1         0      0       1      0         0  1
11    11  Cust1      0   0    0         0      0       1      1         0  0
12    12  Cust1      0   0    1         0      0       1      0         0  1
13    13  Cust1      0   1    0         0      0       0      0         0  0
14    14  Cust1      1   0    1         0      0       0      0         1  1
15    15  Cust1      0   0    0         0      0       0      0         0  0
16    16  Cust1      0   0    1         0      0       0      1         0  1
17     1 Cust10      0   1    0         1      0       0      1         0  1
18     2 Cust10      0   0    1         1      0       0      0         0  0
19     3 Cust10      0   0    0         1      0       0      0         1  1
20     4 Cust10      0   0    1         1      0       0      0         0  0

When I use the below command to transform my data. I tried making few changes here like adding chid.var = "chid" and alt.levels=c(1:16). If I use both alt.levels and alt.var it gives me an error saying pizza already exists and will be replaced. However, I get no error if I use either of them.

pz <- mlogit.data(pizza,shape = "long",choice = "choice",
                  varying = 4:8, id = "cust", alt.var =  "pizza")

Finally, when I use the mlogit command, I get this error.

mlogit(choice ~ pan + thin + pineapple + veggie + sausage + romano + mozarella + oz, pz)

Error in solve.default(H, g[!fixed]) : 
  system is computationally singular: reciprocal condition number = 8.23306e-19

This is my first post on stackoverflow. I visit this site very often and so far never needed to post as I found solutions already. I went through almost all similar posts like this one but in vain. I'm new to discrete choice modeling so I don't know if I'm making any fundamental mistake here.

Also, I'm not really sure what chid.var does.

kamal tanwar
  • 197
  • 8

1 Answers1

0

Couldn't solve this problem. Though you can use multinom function from nnet package. It seems to work. Verified the answer.

The dataset remains the same as shown in the question so no need for any transformation

library("nnet")
pizza_model <- multinom(choice ~ Price + IsThin + IsPan ,data=pizza_all)
summary(pizza_model)

where choice is a dependent categorical variable which you want to predict. Price, IsThin, and IsPan are independent variables. Below is the output

Call:
multinom(formula = choice ~ Price + I_cPan + I_cThin, data = pizza_all)

Coefficients:
                  Values Std. Err.
(Intercept)  0.007192623 1.3298018
Price       -0.149665357 0.1464976
I_cPan       0.098438084 0.3138538
I_cThin      0.624447867 0.2637110

Residual Deviance: 553.8519 
AIC: 561.8519
kamal tanwar
  • 197
  • 8
  • thanks for following up with some info on how you dealt with it. Can you post more details of how you ending up getting your model to work in `nnet` for the benefit of future readers of your question? – DirtStats Oct 06 '17 at 19:58