1

I'm estimating a mixed model on data from a discrete choice experiment with an opt-out alternative (alternative C). I define the individual, but I still get the error message "no individual index" and the model is not estimated.

A screenshot of my data:

enter image description here

Each respondent (individual) receives 6 choice tasks, in which he has to make a choice between three alternatives (A, B or C).

My code is the following:

library("mlogit")
private_car$choice <- as.logical(private_car$choice)
private_car$optout <- ifelse(private_car$card_number == "3", "1", "-1")
V2G_data <- mlogit.data(private_car, choice="choice", shape = "long", id.var = "individual", alt.var = "card_number", id = "individual")

V2G_mixed_model <- mlogit(formula = choice ~ price + autonomy + charge + g_autonomy + saving + premie + optout | -1 | 0 ,
                    data = V2G_data,
                    rpar = c(autonomy = 'n', charge = 'n', g_autonomy  = 'n'),
                    R = 100,
                    halton = NA,
                    print.level = 0,
                    panel = TRUE)

Can someone tell me where it goes wrong?

keepAlive
  • 6,369
  • 5
  • 24
  • 39
Rosanne
  • 11
  • 1
  • Hard to troubleshoot without a reprex, but it looks like there's multiple choice tasks completed by each individual, as denoted in the `card` column. Could be why the individual index used by dfidx is failing. Perhaps try adding `chid.var = "card"` to the `mlogit.data()` function? – awhug Jul 30 '21 at 04:50
  • Many thanks for your response. But when I add chid.var = "card" to the mlogit.data() function, I get a new error message stating: Error in dfidx::dfidx(data = data, dfa$idx, drop.index = dfa$drop.index, : the two indexes don't define unique observations – Rosanne Aug 02 '21 at 07:32

2 Answers2

0

I think I found the answer, thanks to your help. I had to create an identity index. The code for the mlogit.data formula should be:

V2G_mixed_model <- mlogit.data(private_car, choice = "choice", shape = "long", alt.var = "card_number", idx = c("individual", "card"))

Now it works! Many thanks again for your suggestion!

Rosanne
  • 11
  • 1
0

I came across the same problem, but when using your fix, I still get the error... I posted my question here: Error no individual index in mixed logit model using mlogit package in R

  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/34649185) – Marco Jul 06 '23 at 17:29