1

我正在尝试使用 R2OpenBUGS 库从 R 评估分层模型。我已经看过类似问题的答案,但似乎没有任何效果。如果有人可以提供帮助,我将非常高兴。

模型如下。

model{
for (i in 1:n) {
    goals1[i] ~ dpois(lambda1[i])
    goals2[i] ~ dpois(lambda2[i])
    log(lambda1[i]) <- mu + home + a[ht[i]] + d[at[i]]
    log(lambda2[i]) <- mu + a[at[i]] + d[ht[i]]
}
for (i in 1:np) {
    pred[i, 1] ~ dpois(parh[i])
    pred[i, 2] ~ dpois(para[i])
    log(parh[i]) <- mu + home + a[pht[i]] + d[pat[i]]
    log(para[i]) <- mu + a[pat[i]] + d[pht[i]]
}
mu ~ dnorm(pmu, 0.01)
home ~ dnorm(phome, 0.01)
for (i in 2:k) {
    a[i] ~ dnorm(priora[i], 0.01)
    d[i] ~ dnorm(priord[i], 0.01)
}
mua <- -sum(a[2:k])
mud <- -sum(d[2:k])
a[1] ~ dnorm(mua, 100)
d[1] ~ dnorm(mud, 100)}

在日志中我得到:

model is syntactically correct
expected the collection operator c error pos 7515
variable n is not defined
model must have been compiled but not updated to be able to change RN generator
BugsCmds:NoCompileInits
model must be compiled before generating initial values
model must be initialized before updating
model must be initialized before monitors used
model must be initialized before monitors used
model must be initialized before monitors used
model must be initialized before monitors used
model must be initialized before monitors used
model must be initialized before monitors used
model must be initialized before DIC can be monitored
model must be initialized before updating
model must be initialized before monitors used
DIC monitor not set

当我尝试将先验均值向量priora[]和priord[]赋给a[i]和d[i]时,问题就开始了。如果我将这些手段设置为“0”,则代码有效。

4

0 回答 0