我对JAGS中的这个模型有疑问,我想对y [i]进行贝叶斯线性回归,其不服从正态分布,而是服从伽马。
模型是这样的:
"model {
Priors:
a ~ dnorm(0, 0.0001) # mean, precision = N(0, 10^4)
b ~ dnorm(0, 0.0001)
shape ~ dunif(0, 100)
# Likelihood data model:
for (i in 1:N) {
linear_predictor[i] <- a + b * x[i]
# dgamma(shape, rate) in JAGS:
y[i] ~ dgamma(shape, shape / exp(linear_predictor[i]))
}
}
"
为了使该代码可用于此数据的多元线性回归,我应该进行哪些更改?
dataListGamma = list(
x = x,
y = y,
Nx = dim(x)[2],
Ntotal = dim(x)[1]
)
我收到此错误: 节点错误(shape /(exp(linear_predictor [1331]))) 这怎么可能?我不明白 如果我再次运行它,它将更改导致问题的值
答案 0 :(得分:1)
这样的事情(使b
为每个元素具有相同,独立先验的向量,并使用for
循环构造线性预测变量)应该起作用:
model {
# Priors:
a ~ dnorm(0, 0.0001) # mean, precision = N(0, 10^4)
for (j in 1:Nx)
b[i] ~ dnorm(0, 0.0001)
}
shape ~ dunif(0, 100)
# Likelihood data model:
linear_predictor[i] <- a
for (i in 1:Ntotal) {
for (j in 1:Nx) {
linear_predictor[i] <- linear_predictor[i] + b[j]*N[i][j]
}
y[i] ~ dgamma(shape, shape / exp(linear_predictor[i]))
}
}