我试图从 Liu 和 Abeyratne 的“贝叶斯可靠性的实际应用”中重现示例 8.2。原始示例(与分层模型相关)是在 JAGS 中完成的,我想在 BRMS 上重现它。
我能够创建并运行一个模型,其中 Weibull 形状对所有组都是通用的(在示例中,它是九代产品)。
现在我想制作一个模型,我还可以在其中模拟“平均”形状和每个组的效果,就像拦截一样
这是有效的模型,其中形状对所有组都是通用的:
priors <-
set_prior("gamma(a, b)", class = "Intercept") +
set_prior("gamma(c, d)", class = "shape") +
set_prior("target += gamma_lpdf(a | 6, 0.4) - 1 * gamma_lccdf(0 | 6, 0.4) +
gamma_lpdf(b | 2, 0.2) - 1 * gamma_lccdf(0 |2, 0.2) ",
check = FALSE) +
set_prior("target += gamma_lpdf(c | 1, 1) - 1 * gamma_lccdf(0 | 1, 1) +
gamma_lpdf(d | 1, 1) - 1 * gamma_lccdf(0 | 1, 1) ",
check = FALSE)
stanvars <- stanvar(scode = "real<lower=0> a;
real<lower=0> b;
real<lower=0> c;
real<lower=0> d;",
block = "parameters")
brmsHyperModel <- brm(ttf | cens(censor) ~ 1 + (1 | gen),
family = weibull,
data = brmsData,
prior = priors,
stanvars = stanvars,
iter = 41000,
warmup = 4000,
chains = 4,
cores = 4,
seed = 4,
control = list(adapt_delta = .99))
我想运行这样的东西:
brmsForm <- bf(ttf | cens(censor) ~ 1 + (1 | gen),
shape ~ 1 + (1 | gen))
如果我只添加第二个等式,则会收到以下错误:
错误:以下先验不对应任何模型参数:shape ~ gamma(c, d)
我试图改变“先验”,而不是添加第二个方程,而是在形状中添加一个组变量,如下所示:
priors <-
set_prior("gamma(a, b)", class = "Intercept") +
set_prior("gamma(c, d)", class = "shape", group = 'gen' ) +
set_prior("target += gamma_lpdf(a | 6, 0.4) - 1 * gamma_lccdf(0 | 6, 0.4) +
gamma_lpdf(b | 2, 0.2) - 1 * gamma_lccdf(0 |2, 0.2) ",
check = FALSE) +
set_prior("target += gamma_lpdf(c | 1, 1) - 1 * gamma_lccdf(0 | 1, 1) +
gamma_lpdf(d | 1, 1) - 1 * gamma_lccdf(0 | 1, 1) ",
check = FALSE)
但后来我得到的错误是:
错误:以下先验不对应任何模型参数:shape_gen ~ gamma(c, d)
两者都做也会导致我出错。我想象模型规范和我缺少的先前规范之间存在一些相互作用!
有人可以帮助我吗?