所以我正在尝试做这个贝叶斯数据建模项目,然后我回到了我在 rjags 上的贝叶斯统计课上的笔记,我的教授在那里学习了一个非常相似的模型。我能够毫无问题地运行那个,但是当我将它调整到我的模型时,我的输出出现错误。
这是我的代码:
library(rjags)
set.seed(12196)
# Number of bear reports
Y <- black_bears$Y # Number of surveys saying there was a reported bear sighting
N <- black_bears$N # Number of surveys submitted on whether a bear was seen or not
q <- Y/N # proportion of the non-bear sightings submitted
n <- length(Y)
X <- log(q)-log(1-q) # X = logit(q)
data <- list(Y=Y,N=N,X=X)
params <- c("beta")
model_string <- textConnection("model{
# Likelihood
for (i in 1:n){
Y[i] ~ dbinom(p[i], N[i])
logit(p[i] <- beta[1] + beta[2]*X[i])
}
# Priors
beta[1] ~ dnorm(0, 0.01)
beta[2] ~ dnorm(0, 0.01)
}")
model <- jags.model(model_string,data = data, n.chains=2,quiet=TRUE)
update(model, 10000, progress.bar="none")
samples1 <- coda.samples(model, variable.names=params, thin=5, n.iter=20000, progress.bar="none")
plot(samples1)
任何和所有的帮助表示赞赏。谢谢!