I would like to use the R
mlogit
package. The documentation (http://cran.r-project.org/web/packages/mlogit/vignettes/mlogit.pdf) is well written, but I still have a question.
Suppose I have a dataset composed of three categorical variables: mode
, age
, cost
. mode
has three levels (mode1
, mode2
, mode3
), and the other two variables have two levels (age1
, age2
and cost1
, cost2
).
Basically, it is in the following form:
R> head(df)
mode age cost
1 mode2 age1 cost2
2 mode1 age1 cost2
3 mode1 age2 cost1
4 mode3 age1 cost1
With the command mlogitSample <- mlogit.data(df, choice = "mode", shape = "wide")
I am able to "convert" this dataset to the mlogit
format: every row is expanded into three rows (corresponding to the three different response categories), with the mode
column converted to a sequence of TRUE
or FALSE
. This is perfect for using mlogit
; however, I think it is also why I obtain the error Lapack routine dgesv: system is exactly singular: U[8,8] = 0
, given that I have multiple rows which are no more independent.
Since I know that it is possible to apply the multinomial logit method to my case, I would like to know how I can do it with this package. To a similar aim, the function multinom
of package nnet
works fine, but it does not fit the same model I have in mind: I would like to fit the model $\log(\pi_j(x)) = \alpha_j + \beta\cdot x$, with an intercept $\alpha_j$ varying for each mode category $j$, and a vector of constant coefficients $\beta$).