I discovered the mlogit
-package for multinomial logit models in search of estimating a multinomial mixed logit model. After reading the excellent vignette I discove
The rpar
argument accepts only alternative-specific variables. There is no need to specify the person-specific id in the model formula -- this is handled by including id.var = something
in the mlogit.data
command. For example, if you had an alternative specific covariate acov
, you could allow random slopes for acov
across a panel:
N = 200
dat <- data.frame(personID = as.factor(sample(1:4, N, replace=TRUE)),
decision = as.factor(sample(c("Q","U", "other"), N, replace=TRUE)),
syllable = as.factor(sample(1:4, N, replace=TRUE)),
acov.Q = rnorm(N), acov.U = rnorm(N), acov.other = rnorm(N))
dataMod <- mlogit.data(dat, shape="wide", choice="decision", id.var="personID", varying = 4:6)
mlogit(formula = decision ~ acov|syllable, rpar = c(acov = "n"), panel = T, data = dataMod)
It seems you are trying to fit a model with a random, person-specific intercept for each alternative (not random slopes). Unfortunately, I don't think you can do so in mlogit
(but see this post).
One option that would work to fit random intercepts in the absence of alternative-specific covariates is MCMCglmm
.
library(MCMCglmm)
priors = list(R = list(fix = 1, V = 0.5 * diag(2), n = 2),
G = list(G1 = list(V = diag(2), n = 2)))
m <- MCMCglmm(decision ~ -1 + trait + syllable,
random = ~ idh(trait):personID,
rcov = ~ us(trait):units,
prior = priors,
nitt = 30000, thin = 20, burnin = 10000,
family = "categorical",
data = dat)
Relevant issues are prior selection, convergence of Markov chains, etc. Florian Jaeger's lab's blog has a short tutorial on multinomial models via MCMCglmm that you might find helpful, in addition to the MCMCglmm
documentation.