Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Problem using function ranef in R on a mblogit model

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’)"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading