我刚开始使用“brms”,并且在指定模型公式时遇到问题。错误发生在随机截距的规范中(三个变量/术语表示嵌套的分层组结构)。我遇到的错误信息如下所示:
Setting 'rescor' to FALSE by default for this model
Error in str2lang(x) : <text>:1:17: unexpected ')'
1: ~ var4/var3/var1)
^
有人可以帮忙解决这个问题吗?任何帮助将不胜感激。我的代码如下所示:
result <- brm(
bf(
mvbind(var9, var10, var15, var16) ~ var2 + var13 + var14 + var19 + var20 + var34 + var46 + var47 + var50 + var51 + var52 + var56 + var57 + var59 + var60 + var62 + var65 + var66 + var89 + var90 + var91 + var92 + var93 + var94 + cor_ar(var2 + 1 | var4/var3/var1),
zi ~ var2 + var5 + var114 + cor_ar(var2 + 1 | var4/var3/var1)
),
data = y,
family = zero_inflated_negbinomial(),
iter = 1000,
chains = 4,
future = TRUE)
我不确定的模型公式的其他方面是:
请告诉我这些是否正确指定。谢谢!
用于测试
brm
语法的模拟设置的开始。现在这不起作用,因为对于ar()
来说,组内的时间值必须是唯一的。构建嵌套因子结构并确保时间值在组内是唯一的......或者至少不明显......
尽管如此,我还是想暂时把它留在这里,以防它有用。
library(brms)
library(glmmTMB)
library(dplyr)
nn <- 1000
ng <- 50
set.seed(101)
s <- function() factor(sample(1:ng, size = nn, replace = TRUE))
dd <- data.frame(x1 = rnorm(nn), x2 = rnorm(nn),
x3 = rnorm(nn), f1 = s(), f2 = s(), f3 = s())
dd <- (dd
|> group_by(f1, f2, f3)
|> mutate(time = factor(seq(n())))
)
form <- y ~ x1 + x2 + x3 +
ar1(0 + time|f1) + ar1(0 + time|f1:f2) + ar1(0 + time|f1:f2:f3)
dd$y <- simulate_new(
form[-2], ## formula without LHS
ziformula = ~1,
newdata = dd,
family = gaussian,
newparams = list(beta = 1:4,
theta = rep(1, 6),
betad = 1,
betazi = 1))[[1]]
brm( y ~ x1 + x2 + x3 +
ar(time = time, gr = f1),
family = gaussian,
data = dd)