multinomial mixed logit model mlogit r-package

那年仲夏 提交于 2019-12-03 15:31:03
Nate Pope

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!