2

Hi I am trying to use the mlogit function to estimate a discrete choice model for work trip mode of transit choice.

here is what my data looks like after using the mlogit.data function

mledata <- mlogit.data(data, choice="choice",shape="long", chid.var="ID", alt.var="fmode")

> head(mledata[,c(86,90:96)])
        ID extrabusdistance extratraindistance freq fmode y.n choice extradistance
1.car    1           0.0000            0.00000    3   car yes   TRUE   0.00000
1.bus    1          19.8579            0.00000    3   bus  no  FALSE   19.85790
1.train  1           0.0000           27.32557    3 train  no  FALSE   27.32557
2.car    2           0.0000            0.00000    3   car yes   TRUE   0.00000
2.bus    2          28.1311            0.00000    3   bus  no  FALSE   28.13110
2.train  2           0.0000           39.32078    3 train  no  FALSE   39.32078

I have some individual specific characteristics I want to include later but I'm trying this simple model first, and getting this error.

> f<-mlogit(choice~extradistance,mledata)
Error in if (abs(x - oldx) < ftol) { : 
missing value where TRUE/FALSE needed

Also I'm not sure if this will be helpful, but ill include this:

> typeof(mledata$extradistance)
[1] "double"
> typeof(mledata$choice)
[1] "logical"

My professor pretty much used my exact data set shown here in STATA and it ran, so any help in R would be much appreciated. In the choice column only "TRUE" or "FALSE" is contained, and there is one TRUE and TWO false for each individual "ID".

dan1st
  • 12,568
  • 8
  • 34
  • 67
Sam Tucker
  • 21
  • 1

1 Answers1

0

I had the same problem! But then I saw that I was missing some 1s in the choice columns, due to some syntax error that I made in building the daraset! to check it out do:

aggregate(df$choice, by=list(choice.id=df$choice.id), FUN=sum)
helvete
  • 2,455
  • 13
  • 33
  • 37
Irene
  • 1