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
問題は、a[i] と d[i] に事前手段のベクトルを与えようとしたときに始まります。これらの手段を「0」に設定すると、コードが機能します。