I am currently studying a logit model in R, I am using the mblogit model from the mclogit library. I want to study the random effects using the function ranef from the library lme4.
However, I get the following error
Error in UseMethod("ranef") :
no applicable method for ‘ranef’ applied to an object of class "c(‘mmblogit’, ‘mblogit’, ‘mmclogit’, ‘mclogit’, ‘lm’)"
I was wondering if someone could point me to a function that does something similar to ranef that works on mblogit objects.
The following code is a toy example of the issue. The program ends with the same error.
library(mclogit)
library(tidyverse)
options(warn=-1)
mi_df <- data.frame(
"factor" = c("a", "b", "c", "c", "d", "a"),
"category" = c("1", "1","1", "2", "2", "2"),
"province" = c("aa", "bb", "aa", "bb", "aa", "bb"),
"number1" = c(1.2, 3.4, 4.5, 5.6, 4.5, 3.6),
"number2" = c(6, 4, 9, 4, 2, 6)
)
mi_df$category <- relevel(as.factor(mi_df$category), ref="1")
modelo_multinomial0 <- mblogit(category ~ factor + number1+number2 , random = ~ 1 | (province),
data=mi_df, maxit = 30, epsilon = 1e-04)
summary(modelo_multinomial0)
confint(modelo_multinomial0)
library(lme4)
ranef(modelo_multinomial0)
>Solution :
From digging through str(modelo_multinomial0), it looks like $random.effects might be what you want:
modelo_multinomial0$random.effects[1,1][[1]]
[,1]
[1,] 5.418201e-41
[2,] 6.020224e-42
I would experiment with some larger examples to see if the dimensions and values of this component match what you expect.