[英]Error in jags.model RUNTIME ERROR: Compilation error on line 5. Index out of range taking subset of a
我對 Jags 很陌生,我正在嘗試計算 model DIC,但返回了這樣的錯誤:jags.model 中的錯誤(model.file,data = data,inits = init.values,n.chains = n.chains , : RUNTIME ERROR: Compilation error on line 5. 索引超出范圍,我的代碼的子集附在下面。
prior <- c(0.1, 0.15, 0.20, 0.25)
target <- 0.2
y<-c(0,0,0,4)
n<-c(0,5,5,8)
ndose=length(n)
bugs<-function(){
for (j in 1: ndose){
y[j]~dbin(p[j],n[j])
p[j]<-exp(3+a[j]*log(prior[j]/(1-prior[j])))/(1+exp(3+a[j]*log(prior[j]/(1-prior[j]))))
}
a~dgamma(1,1)
}
inits<-function(){
list('a'=0.001)
}
parameter<-c('a')
bugs.data<-list(y=y,n=n,prior=prior,ndose=ndose)
fit<-jags(data=bugs.data,inits=inits,parameter,bugs)
給定您提供的先驗,您已將a
指定為標量,但在上面您已將其索引為1:ndose
。 如果a
確實是標量,則將代碼更改為:
prior <- c(0.1, 0.15, 0.20, 0.25)
target <- 0.2
y<-c(0,0,0,4)
n<-c(0,5,5,8)
ndose=length(n)
bugs<-function(){
for (j in 1: ndose){
y[j]~dbin(p[j],n[j])
p[j]<-exp(3+a*log(prior[j]/(1-prior[j])))/(1+exp(3+a*log(prior[j]/(1-prior[j]))))
}
a~dgamma(1,1)
}
inits<-function(){
list('a'=0.001)
}
如果它是一個向量,那么你需要a
具有ndose
值。 僅使用上面的代碼,可以這樣完成:
target <- 0.2
y<-c(0,0,0,4)
n<-c(0,5,5,8)
ndose=length(n)
bugs<-function(){
for (j in 1: ndose){
y[j]~dbin(p[j],n[j])
p[j]<-exp(3+a[j]*log(prior[j]/(1-prior[j])))/(1+exp(3+a[j]*log(prior[j]/(1-prior[j]))))
}
for(j in 1:ndose){
a[j]~dgamma(1,1)
}}
inits<-function(){
list('a'=c(0.001, 1, 0.5, 0.7))
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.