1

我对 JAGS 中的这个模型有疑问,我想用 ay[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]
 )

我收到此错误:节点错误(形状/(exp(linear_predictor [1331])))这怎么可能?我不明白如果我再次运行它会改变导致问题的值

4

1 回答 1

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]))
  }
 }
于 2018-11-12T13:16:42.430 回答