gpt4 book ai didi

jags - 错误 : "Slicer stuck at value with infinite density" running binomial-beta model in JAGS

转载 作者:行者123 更新时间:2023-12-02 20:36:04 26 4
gpt4 key购买 nike

我正在尝试在 JAGS 中运行一个二项式-beta 模型(参见下面的示例代码)。我不断收到错误:错误:尝试运行 JAGS 模型时遇到以下错误:

Error in node a0
Slicer stuck at value with infinite density

我正在努力理解。我想也许初始条件是将 beta 分布发送到参数空间的无限区域,但经过一些调查后情况似乎并非如此。关于此错误的含义或如何调整代码以适应它的任何想法?

我将我的代码和一些虚构的示例数据放在了下面。这是我希望在我的数据集中出现的数据类型。

#Generate some sample data
counts = c(80,37,10,43,55,23,53,100,7,11)
n = c(100,57,25,78,55,79,65,100,9,11)
consp = c(1.00, 0.57, 0.25, 0.78, 0.55, 0.79, 0.65, 1.00, 0.09, 0.11)
treat = c(0.5,0.5,0.2,0.9,0.5,0.2,0.5,0.9,0.5,0.2)

#Model spec
model1.string <-"model{
for (i in 1:length(counts)){
counts[i] ~ dbin(p[i],n[i])
p[i] ~ dbeta( ( mu[i] * theta[i]) , ((1-mu[i])*theta[i]))
mu[i] <- ilogit(m0 + m1*consp[i] + m2*treat[i])
theta[i] <- exp(n0 + n1*consp[i])
}
m0 ~ dnorm(0, 1)
m1 ~ dnorm(0, 1)
m2~ dnorm(-1, 1)
k0 ~ dnorm(1, 1)
k1 ~ dnorm(0, 1)
}"

#Specify number of chains
chains=5
#Generate initial conditions
inits=replicate(chains, list(m0 = runif(1, 0.05, 0.25),
m1 = runif(1, 0,0.2),
m2=runif(1,-1,0),
k0 = runif(1, 0.5, 1.5),
k1 = runif(1, 0, 0.3)),simsplify = F)

#Run
model1.spec<-textConnection(model1.string)
results <- autorun.jags(model1.string,startsample = 10000,
data = list('counts' = counts,
'n' = n,
'consp'=consp,
"treat"=treat),
startburnin=5000,
psrf.target=1.02,
n.chains=5,
monitor = c("m0", "m1", "m2","k0", "k1"), inits = inits),

最佳答案

当被采样变量的概率密度在一个点上无穷大时,切片采样器(由 JAGS 使用)不起作用。 Beta 分布为 0 或 1 时可能会发生这种情况。

解决方法是截断产生问题的节点,如:

p[i] ~ dbeta( ( mu[i] * theta[i]) , ((1-mu[i])*theta[i])) I(0.001,0.999)

(我不太记得语法,但 JAGS 明确允许截断的随机变量)

关于jags - 错误 : "Slicer stuck at value with infinite density" running binomial-beta model in JAGS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47135726/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com