expected left pointing arrow < - or twiddles ~ error
So this seemingly helpful OpenBUGS error was throwing me off. Code:
blog comments powered by Disqus
n <- 100
p <- 5
x <- matrix(rnorm(n*p),n,p)
b <- rnorm(p,0,.1)
rho <- exp(x%*%b)
N <- rpois(n,rho)
y <- rbinom(n,N,.5)
library(R2OpenBUGS)
model <- function() {
for (i in 1:n) {
y[i] ~ dbin(0.5,N[i])
N[i] ~ dpois(rho[i])
rho[i] <- exp(inprod(x[i,],b))
#rho[i] <- exp(x[i,1]*b[1]+x[i,2]*b[2]+x[i,3]*b[3]+x[i,4]*b[4]+x[i,5]*b[5])
}
for (i in 1:p) {
b[i] ~ dnorm(0,1)
}
}
fn <- file.path(tempdir(), "model.txt")
write.model(model,fn)
data <- list(n=n,p=p,y=y,x=x)
inits <- list(list(b=rep(0,p),N=y))
parameters <- c("b","N")
sim <- bugs(data,inits,parameters,fn,n.chains=1,n.burnin=1e3,n.thin=1,n.iter=1e4)
caused this error:
OpenBUGS version 3.2.1 rev 781
type 'modelQuit()' to quit
OpenBUGS> expected left pointing arrow < - or twiddles ~ error pos 197 (error on line 10)
OpenBUGS> model must be checked before data is loaded
OpenBUGS> model must be checked before compiling
OpenBUGS> model must have been compiled but not updated to be able to change RN generator
OpenBUGS> model must be compiled before initial values loaded
OpenBUGS> model must be compiled before generating initial values
OpenBUGS> model must be initialized before updating
OpenBUGS> model must be initialized before monitors used
OpenBUGS> model must be initialized before monitors used
OpenBUGS> model must be initialized before monitors used
OpenBUGS> model must be initialized before monitors used
OpenBUGS> model must be initialized before monitors used
OpenBUGS> model must be initialized before monitors used
OpenBUGS> model must be initialized before DIC can be monitored
OpenBUGS> model must be initialized before updating
OpenBUGS> model must be initialized before monitors used
OpenBUGS> model must be initialized before monitors used
OpenBUGS> DIC monitor not set
OpenBUGS>
which was caused by
rho[i] <- exp(inprod(x[i,],b))
and can be remedied by either
rho[i] <- exp(inprod(x[i,],b[]))
or
rho[i] <- exp(x[i,1]*b[1]+x[i,2]*b[2]+x[i,3]*b[3]+x[i,4]*b[4]+x[i,5]*b[5])
the former is what I was going for.
blog comments powered by Disqus