在不拟合模型的情况下验证混合模型公式

问题描述 投票:0回答:1

我正在寻找类似于 insight 的 R 包,它允许我在不拟合模型的情况下验证混合模型公式。具体来说,我想检查公式是否是仅具有随机截距的仅截距混合模型(例如,没有随机斜率或嵌套效应)。如果没有包,我怎样才能可靠地实现这一点?

关于如何实现这一目标有什么建议吗?

注意,公式旨在传递给

brms::brm()

r mixed-models
1个回答
0
投票

我认为

reformulas
函数具有您想要的组件(
glmmTMB
lme4
都使用此包进行公式处理)。

测试用例

f1 <- y ~ x + (1|f) + (x | g)
f2 <- y ~ 1 + (1|f) + (1 | g)

功能

library(reformulas)
fun <- function(f) {
   ## fixed-effect component is intercept only
   identical(nobars(f)[[3]], 1) &
   ## random-effects term in each RE component is intercept only
   all(sapply(findbars(f), function(f0) f0[[2]] == 1))
}
fun(f1)  ## FALSE
fun(f2)  ## TRUE
© www.soinside.com 2019 - 2024. All rights reserved.