I am using the mlogit package to run a multinomial mixed effect model. The data are in the long format to begin with. I am trying to determine whether a variable is related to differences in a categorical outcome, sleep duration, that has 3 categories (0,1,2). Sample data are:
id sleep var1
1 0 1.5
1 2 1.5
2 1 2
2 1 2
3 0 1
I tried running the following code:
mldata <- mlogit.data(df, choice="sleep", shape ="long")
mlogit.model1 <- mlogit(sleep ~ 1 | var1, data = df, reflevel = "0")
Error in dfidx::dfidx(data = data, dfa$idx, drop.index = dfa$drop.index, :
The choice variable must have exactly two modalities
In a previous post, I read that this message was caused by including the "varying" function of the mlogit package. However, I didn't include that so I don't understand what is going on.
Can someone please help?