简体   繁体   中英

How do I run a multinomial logistic regression with mixed effects in R?

I'm trying to run a multinomial logistic regression with mixed effects. Let's say I have the following variables:

Participant (ten participants, each with 10 observations) Word (ten different words, each participant sees each once) IV (some two level grouping variable) DV (can be 1, 2 or 3)

How would I run a multinomial logistic regression with ppt and word as random variables?

Here is some sample data:

ppt <- rep(1:10, each = 10)
word <- rep(1:10, times = 10)
IV <- rep(1:2, times = 50)
DV <- sample(x = c(1,2,3), size = 100, replace = TRUE)

d <- as.data.frame(cbind(ppt, word, IV, DV))

I think the best package for this type of model is brms , but this package fits Bayesian models so you'll have to specify priors. I've fit an example model without specifying them, so it goes with the defaults that you shouldn't use.

library(brms)

d$DV <- as.factor(d$DV)
d$IV <- as.factor(d$IV)

model_fit <- brm(DV ~ IV + (1|ppt) + (1|word),
                 data = d,
                 family = categorical())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM