I discovered the mlogit
-package for multinomial logit models in search of estimating a multinomial mixed logit model. After reading the excellent vignette I discovered that I could not apply my data on any of the described examples.
I now write in hope of help with my problem and created a minimal example to illustrate my situation.
The Problem is as follows: There are words with the consonant 'Q' somewhere. Now an experiment was conducted with people who were tasked to listen to these words and say if they heard a Q, an U or some OTHER consonant. This has to modeled in dependence of some factors like syllable position or real/non-real-word.
In the minimal example I created 4 people and their answers with the syllable position.
library(mlogit)
library(nnet)
set.seed(1234)
data <- data.frame(personID = as.factor(sample(1:4, 40, replace=TRUE)),
decision = as.factor(sample(c("Q","U", "other"), 40, replace=TRUE)),
syllable = as.factor(sample(1:4, 40, replace=TRUE)))
summary(data)
personID decision syllable
1:11 other:10 1:18
2:10 Q :18 2: 9
3:10 U :12 3: 5
4: 9 4: 8
As far as I know nnet
's multinom
function does not cover mixed models.
modNnet1 <- multinom(decision ~ syllable, data=data)
First I used the mlogit.data
-function to reshape the file. After discussion with a colleague we came to the conclusion that there is no alternative.specific.variable.
dataMod <- mlogit.data(data, shape="wide", choice="decision", id.var="personID")
mod1 <- mlogit(formula = decision ~ 0|syllable,
data = dataMod,
reflevel="Q", rpar=c(personID="n"), panel=TRUE)
Error in names(sup.coef) <- names.sup.coef :
'names' attribute [1] must be the same length as the vector [0]
mod2 <- mlogit(formula = decision ~ personID|syllable,
data = dataMod,
reflevel="Q", rpar=c(personID="n"), panel=TRUE)
Error in solve.default(H, g[!fixed]) :
Lapack routine dgesv: system is exactly singular: U[3,3] = 0
No I do not know what to do, so I ask for help in here. But I believe this kind of problem can be solved with mlogit
and I just don't see it yet ;)
syllable
variable? I trieddat$syllableEff <- C(dat$syllable, sum,3)
and used the formuladecision ~ -1 + trait + syllableEff
but it did not seem to work. If you don't know, I'll post a new topic – Oaken