英文:
Problem using function ranef in R on a mblogit model
问题
抱歉,我只能翻译您提供的文字,不能执行代码。以下是您提供的内容的翻译:
我目前正在R中研究一个logit模型,我正在使用mclogit库中的mblogit模型。我想使用lme4库中的ranef函数来研究随机效应。
然而,我遇到了以下错误:
> 错误:在对象类型为"c('mmblogit', 'mblogit', 'mmclogit', 'mclogit', 'lm')"的对象上应用了"ranef"的方法。
我想知道是否有人能指导我找到一个类似于ranef
的函数,可以在mblogit
对象上使用。
以下代码是问题的一个玩具示例。程序以相同的错误结束。
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)
英文:
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)
答案1
得分: 1
从查看str(modelo_multinomial0)
的结果来看,$random.effects
可能 是你想要的内容:
modelo_multinomial0$random.effects[1,1][[1]]
[,1]
[1,] 5.418201e-41
[2,] 6.020224e-42
我建议尝试一些更大的示例,以查看这个组件的维度和值是否与你的预期相符。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论