I am trying to learn Bayesian analysis based on the book "Performing Bayesian Data Analysis: A Tutorial with R, JAGS, and Stan (2015)."
There are examples in this book. So, I am trying to reproduce this example in R. However, in this example I have an error message.
To be specific, these are sample data.
data
y s
1 1 Reginald
2 0 Reginald
3 1 Reginald
4 1 Reginald
5 1 Reginald
6 1 Reginald
7 1 Reginald
8 0 Reginald
9 0 Tony
10 0 Tony
11 1 Tony
12 0 Tony
13 0 Tony
14 1 Tony
15 0 Tony
y<-data$y
s<-as.numeric(data$s)
Ntotal=length(y)
Nsubj=length(unique(s))
dataList=list(y=y, s=s, Ntotal=Ntotal, Nsubj=Nsubj)
Also, this is my model.
modelString="
model{
for(i in 1:Ntotal){
y[i] ~ dbern(theta[s[i]])
}
for(s in 1:Nsubj){
theta[s] ~ dbeta(2,2)
}
}
"
writeLines(modelString, con="TEMPmodel.txt")
library(rjags)
library(runjags)
jagsModel=jags.model(file="TEMPmodel.txt",data=dataList)
In this case, I got an error message.
Error in jags.model(file = "TEMPmodel.txt", data = dataList) :
RUNTIME ERROR:
Cannot insert node into theta[1...2]. Dimension mismatch
I do not know that I made a mistake in this code. Please give me some advice.
Thanks in advance.
source
share