计算 ordinal::clmm 的边际效应

发布于 2025-01-11 07:48:03 字数 2230 浏览 0 评论 0原文

我在从具有随机效应的序数模型 (ordinal::clmm()) 计算 AME(...平均边际效应...)时遇到一些问题(在我的例子中是四级年份因子)。函数 margins::margins() 和 mfx::probitmfx() 不起作用。

ggeffects::ggpredict() 函数可以工作,但在指定随机效应点时遇到问题,我不想在其中看到平均边际效应。就我而言,它针对年份 = 2006 进行了调整(范围为 2006、2008、2017、2018),这对我来说信息量不大。

这是 iris 数据集的示例。无论它的用法如何,我都会改变变量。这只是一个例子……

#datasets::iris %>% glimpse
#get ordered variable and a factor for random effects
iris %>% mutate(species_o = ordered(Species), petal_length_cut_f = cut(iris$Petal.Length,4) )->temp
#fit model
clmm(species_o~Sepal.Width+(1|petal_length_cut_f), data = temp, link = "probit")->clmm_fit
#predict
ggpredict(clmm_fit, terms = c("petal_length_cut_f [all]", "Sepal.Width [all]"), type = "re")-> gp

这会引发错误:

无法计算“clmm”模型的随机效应水平的预测值。请从“terms”中删除以下变量:petal_length_cut_f

移动到 lme4::lmer() 我可以做我想做的事:

#fit model
lmer(as.numeric(species_o) ~Sepal.Width+(1|petal_length_cut_f), data = temp)->lmer_fit
#predict
ggpredict(lmer_fit, terms = c("petal_length_cut_f [all]", "Sepal.Width [all]"), type = "re")-> gp
gp

# Predicted values of species_o

# Sepal.Width = 2

petal_length_cut_f | Predicted |        95% CI
----------------------------------------------
(0,994,2,48]       |      1.01 | [-0.03, 2.04]
(2,48,3,95]        |      2.00 | [ 0.97, 3.04]
(3,95,5,43]        |      2.36 | [ 1.33, 3.40]
(5,43,6,91]        |      3.00 | [ 1.96, 4.03]

# Sepal.Width = 2,2

petal_length_cut_f | Predicted |        95% CI
----------------------------------------------
(0,994,2,48]       |      1.01 | [-0.02, 2.04]
(2,48,3,95]        |      2.00 | [ 0.97, 3.03]
(3,95,5,43]        |      2.36 | [ 1.33, 3.39]
(5,43,6,91]        |      3.00 | [ 1.97, 4.03]

# Sepal.Width = 2,3

petal_length_cut_f | Predicted |        95% CI
----------------------------------------------
(0,994,2,48]       |      1.01 | [-0.02, 2.03]
(2,48,3,95]        |      2.00 | [ 0.97, 3.03]
(3,95,5,43]        |      2.36 | [ 1.33, 3.39]
(5,43,6,91]        |      3.00 | [ 1.97, 4.03]

… … … 
asoasf

我已经在包的 GitHub 中发布了一个问题,但很高兴听到任何替代方案 (其他回归函数/方法,具有 ggpredict 或其他函数,可以计算序数模型中特定随机效应水平的 AME)。

多谢, 路易丝

I have some problems with calculating the AME (…average marginal effects…) from an ordinal model (ordinal::clmm()) with random effects (in my case a four level year factor). The functions margins::margins() and mfx::probitmfx() don't work.

The ggeffects::ggpredict() function works but it has problems to specify the point(s) of random effects where I wan't to see my average marginal effects. In my case it adjusted for year = 2006 (from a range 2006,2008,2017,2018) what is not very informative for me.

Here is an example with the iris dataset. I mutated the variables no matter about it's usage. It's just an example……

#datasets::iris %>% glimpse
#get ordered variable and a factor for random effects
iris %>% mutate(species_o = ordered(Species), petal_length_cut_f = cut(iris$Petal.Length,4) )->temp
#fit model
clmm(species_o~Sepal.Width+(1|petal_length_cut_f), data = temp, link = "probit")->clmm_fit
#predict
ggpredict(clmm_fit, terms = c("petal_length_cut_f [all]", "Sepal.Width [all]"), type = "re")-> gp

This throws an error:

Predicted values can't be computed for levels of random effects from 'clmm' models. Please remove following variables from 'terms': petal_length_cut_f

Moving to lme4::lmer() I can do what I wanted:

#fit model
lmer(as.numeric(species_o) ~Sepal.Width+(1|petal_length_cut_f), data = temp)->lmer_fit
#predict
ggpredict(lmer_fit, terms = c("petal_length_cut_f [all]", "Sepal.Width [all]"), type = "re")-> gp
gp

# Predicted values of species_o

# Sepal.Width = 2

petal_length_cut_f | Predicted |        95% CI
----------------------------------------------
(0,994,2,48]       |      1.01 | [-0.03, 2.04]
(2,48,3,95]        |      2.00 | [ 0.97, 3.04]
(3,95,5,43]        |      2.36 | [ 1.33, 3.40]
(5,43,6,91]        |      3.00 | [ 1.96, 4.03]

# Sepal.Width = 2,2

petal_length_cut_f | Predicted |        95% CI
----------------------------------------------
(0,994,2,48]       |      1.01 | [-0.02, 2.04]
(2,48,3,95]        |      2.00 | [ 0.97, 3.03]
(3,95,5,43]        |      2.36 | [ 1.33, 3.39]
(5,43,6,91]        |      3.00 | [ 1.97, 4.03]

# Sepal.Width = 2,3

petal_length_cut_f | Predicted |        95% CI
----------------------------------------------
(0,994,2,48]       |      1.01 | [-0.02, 2.03]
(2,48,3,95]        |      2.00 | [ 0.97, 3.03]
(3,95,5,43]        |      2.36 | [ 1.33, 3.39]
(5,43,6,91]        |      3.00 | [ 1.97, 4.03]

… … … 
asoasf

I already posted an issue in the package's GitHub but would be glad to hear about any alternatives (other regression function/ method with ggpredict or other function that can compute AMEs at specific levels of the random effects in an ordinal model).

Thanks a lot,
Luise

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一梦等七年七年为一梦 2025-01-18 07:48:03

根据定义,随机效应的所有级别均来自相同的分布。因此,您无法获得特定年份的估计值。随机效应主要用于指示批次(例如受试者ID)。如果模型以前没有见过,那么使用新的主题 ID 进行预测是没有意义的。这就是为什么模型中没有特定主题 ID 的系数,因此没有对任何随机效应的边际效应估计。随机效应只是为了分组,组名没有内在含义。

By definition, all levels of a random effect were drawn from the same distribution. Thus, you can not get an estimate for a particular year. Random effects are mostly used to indicate batches (e.g. subject ID). Making predictions using a new subject ID does not make sense, if the model has not seen it before. This is why there aren't coefficients for a particular subject id in the model, and thus there is no marginal effect estimate on any random effects. Random effects are just for grouping, the group names do not have intrinsic meaning.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文