[R] Binary data on JAGS

Massimiliano Tripoli m@@@|m|||@no@tr|po|| @end|ng |rom gm@||@com
Tue Jun 1 09:46:42 CEST 2021


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]]



More information about the R-help mailing list