[R] error message running R2WinBUGS
Uwe Ligges
ligges at statistik.uni-dortmund.de
Thu Jul 28 10:59:06 CEST 2005
This is a question related to WinBUGS, not to R nor to the R2WinBUGS
"interface". Please ask on the appropriate lists/forums related to
WinBUGS (with plain WinBUGS code, rather than R's interface code).
BTW: Let's answer your question before:
You have specified x[1,28] to be 127, but it is from a Binomial
distribution with n=100.... (hence impossible!).
And that's what the WinBUGS (NOT R!) error message tells you.
Uwe Ligges
qi zhang wrote:
> *Dear R-user,
> *
> I try to run Winbugs from R using bugs function in R2WinBUGS.My model works
> well in Winbugs except that I can't get DIC. Since I don't need DIC, when I
> try to run Winbugs from R , I set "DIC=FALSE". My model is as following:
> model {
> for (i in 1:N) {
> for(j in 1 : T ) {
> x[i, j] ~ dbin(p[i, j],n[i])
> #Hier.prior
> p[i, j] ~ dbeta(alpha[i, j], beta[i, j])
> alpha[i, j] < - pi[ j]*(1-theta[i])/theta[i]
> beta[i, j] < -(1-pi[ j])*(1-theta[i])/theta[i]
> }
> }
>
> for(j in 1 : T ) {
> pi[ j ] ~dbeta(0.1,0.1)I(0.1,0.9)
> }
>
> for (i in 1:N) {
> theta[i] ~dbeta(2,10)
> }
> }
>
> And my R code is as followings:
>
> initials1<-list(theta=c(0.2,0.01), pi=rbeta(50, 0.1, 0.1)*0.8+0.1
>
> , p=matrix(rbeta(100, 2, 10)*0.8+0.1,nr=2,nc=50,byrow=TRUE))
>
> inits<-list(initials1 initials1)
>
> data<-list(N=2,T=50 ,n=c(100,150),x = structure(.Data = c(
>
> 3, 47, 8, 19, 87, 69,
>
> 2, 4, 75, 24, 16, 81,
>
> 10, 78, 87, 44, 17, 56,
>
> 23, 75, 55, 85, 84, 69,
>
> 6, 36, 8, 90, 47, 6,
>
> 87, 61, 49, 57, 28, 56,
>
> 31, 54, 75, 79, 67, 38,
>
> 28, 13, 89, 63, 32, 68,
>
> 70, 7,
>
> 24, 95, 8, 14, 127, 134,
>
> 7, 8, 133, 40, 76, 126,
>
> 0, 132, 120, 137, 9, 91,
>
> 3, 130, 18, 80, 134, 95,
>
> 12, 34, 19, 111, 34, 25,
>
> 127, 79, 132, 84, 72, 134,
>
> 67, 44, 95, 69, 80, 51,
>
> 57, 12, 138, 137, 64, 80,
>
> 130, 58), .Dim = c(2, 50)))
>
> #run winbugs
>
> library(R2WinBUGS)
>
> structure<-bugs(data,inits,model.file="S:/Common/zhangqi/ebayes/for
> R/model.txt",
>
> parameters=c("p","pi","theta"),n.chains=2,n.iter=2000,n.burnin=500,
>
> debug=TRUE,DIC=FALSE,bugs.directory="c:/Program Files/WinBUGS14/",
>
> working.directory = NULL )
>
> Even if I changed initial values several times, I still keep geting the
> following error message in Winbugs:
>
> display(log)
>
> check(S:/Common/zhangqi/ebayes/for R/model.txt)
>
> model is syntactically correct
>
> data(C:/Program Files/R/rw2011/data.txt)
>
> data loaded
>
> compile(2)
>
> model compiled
>
> inits(1,C:/Program Files/R/rw2011/inits1.txt)
>
> value of binomial x[1,28] must be between zero and order of x[1,28]
>
> I really have no clue about what I can do to fix it.
>
> Could any of your please take a look at my problem, I truely appreciate any
> suggestions.
>
> Qi Zhang
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list