[R] error in mlogit

Achim Zeileis Achim.Zeileis at uibk.ac.at
Fri Jun 22 09:30:19 CEST 2012


On Fri, 22 Jun 2012, Kazu Nada wrote:

> Thank you so much for the suggestion.
> I want to estimate interactions between "the attributes of the choice set"
> and "subject-specific data (e.g., gender or income)".
> However, y ~ x | z notation is to see the interaction between "the
> alternatives of choice set" and "subject-specific data (e.g., gender or
> income)".
> 
> Therefore, I need to put the interaction terms after terms suggesting
> attributes.

Either this is wrong or you did not explain your data properly. (But you 
did not follow the posting guide anyway.)

I suspect that the variables "train", "bus", etc. are 0/1 dummy variables 
indicating the alternative and that variables like "inc" are 
subject-specific covariates. Then you create alternative-specific 
interaction terms which could equivalently and much more conveniently be 
created as subject-specific variables.

Consider the following example with data from the mlogit package:

## load package and data
library("mlogit")
data("Fishing", package = "mlogit")
Fish <- mlogit.data(Fishing, varying = c(2:9),
   shape = "wide", choice = "mode")

## create alternative-specific indicators
Fish$beach   <- as.numeric(Fish$alt == "beach")
Fish$boat    <- as.numeric(Fish$alt == "boat")
Fish$charter <- as.numeric(Fish$alt == "charter")
Fish$pier    <- as.numeric(Fish$alt == "pier")

## model with only alternative-specific dummies
## your style
m1a <- mlogit(mode ~ boat + charter + pier | 0, data = Fish)
## mlogit style
m1b <- mlogit(mode ~ 0 | 1, data = Fish)
cbind(coef(m1a), coef(m1b))

## model with alternative specific slopes for subject-specific variable
## your style
m2a <- mlogit(mode ~ boat + charter + pier + I(boat*income) +
   I(charter*income) + I(pier*income) | 0, data = Fish)
## mlogit style
m2b <- mlogit(mode ~ 0 | 1 + income, data = Fish)
cbind(coef(m2a), coef(m2b))

So I presume that you could greatly simplify your model formula. It might 
be necessary to set up a few of the interactions by hand but I strongly 
suspect not all of them!

hth,
Z

> Any suggestions would be grateful.
> 
> Kaz 
> 
> 2012/6/8 Achim Zeileis <Achim.Zeileis at uibk.ac.at>
>       On Fri, 8 Jun 2012, Kazu Nada wrote:
>
>             Hi, I need help to do "mlogit" including "l( )
>             function.
>             When I put following command,
>             "Error in  parse(text = x) :  <text>:2:0:" is shown.
> 
> 
> (1) Your example is not reproducible for us, see the footer of this
> mail and follow the posting guide.
> 
> (2) You manually set up a lot of interaction terms which actually can
> be seen as alternative-specific variables. You can simplify your
> formula considerably if you use mlogit's y ~ x | z notation. See the
> two package vignettes for guidance: vignette(package = "mlogit")
>
>       --------
>       res1<-(mlogit(choice~train+bus+plane+taxi+year+cost
>       +I(gen*train)+I(gen*bus)+I(gen*plane)+I(gen*taxi)+I(gen*year)+I(gen*cost)
>       +I(age*train)+I(age*bus)+I(age*plane)+I(age*taxi)+I(age*year)+I(age*cost)
> +I(prep*train)+I(prep*bus)+I(prep*plane)+I(prep*taxi)+I(prep*year)+I(prep*c
>       ost)
>       +I(inc*train)+I(inc*bus)+I(inc*plane)+I(inc*taxi)+I(inc*year)+I(inc*cost)
> +I(tour*train)+I(tour*bus)+I(tour*plane)+I(tour*taxi)+I(tour*year)+I(tour*c
>       ost)
> +I(ecot*train)+I(ecot*bus)+I(ecot*plane)+I(ecot*taxi)+I(ecot*year)+I(ecot*c
>       ost)
> +I(kibo*train)+I(kibo*bus)+I(kibo*plane)+I(kibo*taxi)+I(kibo*year)+I(kibo*c
>       ost)
>       ,data=dat))
>       --------
>
>       I appreciate if you could provide me any suggestion.
>
>       Thank you.
>       Kaz
> 
>        [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible
> code.
> 
> 
> 
>


More information about the R-help mailing list