Thanks, for suggestions (To define p before). I thought it and I put this line of code inside the loop: p[i] <- y[i] / n[i] but I received a RUNTIME ERROR and: (Attempt to redefine node p[1]). Thanks
Massimiliano Il giorno mar 1 giu 2021 alle ore 17:22 Bert Gunter <bgunter.4...@gmail.com> ha scritto: > Where is p defined before it is used? (Is this part of what jags provides > somehow?) > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along and > sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Tue, Jun 1, 2021 at 7:57 AM Massimiliano Tripoli < > massimiliano.trip...@gmail.com> wrote: > >> Dear R users, >> I'm trying to reproduce the example 6.5.1 (Dobson (1983)) in BUGS book in >> linux using JAGS. >> Below the code as >> >> >> >> https://www.mrc-bsu.cam.ac.uk/software/bugs/the-bugs-project-the-bugs-book/bugs-book-examples/the-bugs-book-examples-chapter-6-6-5-1/ >> >> # By R code: >> library('rjags') >> >> jags <- jags.model( >> file = "651.bug", >> list (x = c(1.6907, 1.7242, 1.7552, 1.7842, 1.8113, 1.8369, 1.8610, >> 1.8839), >> n = c(59, 60, 62, 56, 63, 59, 62, 60), >> y = c(6, 13, 18, 28, 52, 53, 61, 60)) , >> inits = list(beta = 0, alpha = 50), >> n.chains = 3 >> ) >> >> # By JAGS code: (651.bug) >> >> model { >> for (i in 1:8) { >> y[i] ~ dbin(p[i], n[i]) >> logit(p[i]) <- alpha + beta*(x[i] - mean(x[])) >> phat[i] <- y[i]/n[i] >> yhat[i] <- n[i]*p[i] >> } >> alpha ~ dnorm(0, 0.0001) >> beta ~ dnorm(0, 0.0001) >> } >> # I received this error in R: >> >> # Resolving undeclared variables >> >> # Allocating nodes >> >> #Graph information: >> >> # Observed stochastic nodes: 8 >> >> # Unobserved stochastic nodes: 2 >> >> # Total graph size: 78 >> >> >> >> #Initializing model >> >> #Deleting model >> >> >> >> #Error in jags.model(file = "651.bug", list(x = c(1.6907, 1.7242, 1.7552, >> : >> # Error in node y[1] >> >> #Node inconsistent with parents >> >> Thanks in advance >> M. Tripoli >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.