在R中使用ranef函数处理mblogit模型时出现问题。

huangapple go评论66阅读模式
英文:

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 &lt;- data.frame(
  &quot;factor&quot; = c(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;c&quot;, &quot;d&quot;, &quot;a&quot;),
  &quot;category&quot; = c(&quot;1&quot;, &quot;1&quot;,&quot;1&quot;, &quot;2&quot;, &quot;2&quot;, &quot;2&quot;),
  &quot;province&quot; = c(&quot;aa&quot;, &quot;bb&quot;, &quot;aa&quot;, &quot;bb&quot;, &quot;aa&quot;, &quot;bb&quot;),
  &quot;number1&quot; = c(1.2, 3.4, 4.5, 5.6, 4.5, 3.6),
  &quot;number2&quot; = c(6, 4, 9, 4, 2, 6)
  )

mi_df$category &lt;- relevel(as.factor(mi_df$category), ref=&quot;1&quot;)

modelo_multinomial0 &lt;- 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.

huangapple
  • 本文由 发表于 2023年3月31日 21:26:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75899069.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定