1

I'm trying to fit a mixed logit model in R using the mlogit package.

This is a sample of my data:

Persona Proposito     MediosUsados    ModoPriPub    ModoMotor    TiempoViaje Sexo  AdultoMayor Estudios               
     <dbl> <chr>         <chr>           <chr>         <chr>              <dbl> <chr> <chr>       <chr>                  
1 17343102 Volver a Casa Bus Alimentador Publico       Motorizado            70 Mujer No          Media Cientifica-Human~
2 17345101 Volver a Casa A pie           No motorizado No motoriza~          20 Homb~ No          Basica/Primaria        
3 17345102 De compras    A pie           No motorizado No motoriza~          20 Mujer No          Universitaria          
4 17345102 Volver a Casa A pie           No motorizado No motoriza~          25 Homb~ No          Universitaria          
5 17346203 Al estudio    A pie           No motorizado No motoriza~          20 Mujer No          Media Cientifica-Human~
6 17346203 Volver a Casa A pie           No motorizado No motoriza~          20 Homb~ No          Media Cientifica-Human~

Where persona is the id of individual; MediosUsados is the mode (choice); ModoPriPub, ModoMotor and TiempoViaje are the conditional variables that depends on the mode; and Sexo, AdultoMayor & Estudios are the other variables depending on the individual.

This is how im trying to fit the model:

ibrary(readxl)
library(dfidx)
library(mlogit)


# Cargar dataset
TravelMode <- read_excel('Model_strings.xlsx')
model<-mlogit(MediosUsados~ModoMotor+ModoPriPub+TiempoViaje | Proposito+Sexo+AdultoMayor+Estudios, TravelMode, shape="long")
 

Nevertheless I get this error all the time:

Error in dfidx::dfidx(data = data, dfa$idx, drop.index = dfa$drop.index,  : 
  the two indexes don't define unique observations

I tried removing the duplicates but it keeps throwing the same error message. Any help would be much appreciated.

Phil
  • 7,287
  • 3
  • 36
  • 66
yieniggu
  • 384
  • 1
  • 7
  • 20
  • 1
    Apparently, it seems like you are missing the `idx` argument. Try to add `idx = "Persona"` to your `mlogit` options. Regarless, the code you posted is just a multinomial logit (MNL), not a mixed logit. For a reference on mixed logit I gently suggest you to see [this link](https://cran.r-project.org/web/packages/mlogit/vignettes/e3mxlogit.html) – Álvaro A. Gutiérrez-Vargas Nov 12 '20 at 08:27

0 Answers0