From: Dawn W. <dwo...@in...> - 2007-10-03 17:29:15
|
I found a bug in R2WinBUGS, which can be reproduced using the code = below. As a fix, I propose removing a single line of code in bugs.sims: sims <- sims [sample(n.sims),] # scramble (for convenience in = analysis) This line of code scrambles the samples for each parameter. What is the reason for doing this? For some reason, when sims is a matrix with a = single column (when the user has requested that only one parameter be returned) = this line changes sims from a matrix object to a vector object. =20 Thank you, Dawn model.file <- function(){ for (j in 1:J){ y[j] ~ dnorm (theta[j], tau.y[j]) theta[j] ~ dnorm (mu.theta, tau.theta) tau.y[j] <- pow(sigma.y[j], -2) } mu.theta ~ dnorm (0.0, 1.0E-6) tau.theta <- pow(sigma.theta, -2) sigma.theta ~ dunif (0, 1000) } # Some example data (see ?schools for details): data(schools) J <- nrow(schools) y <- schools$estimate sigma.y <- schools$sd data <- list ("J", "y", "sigma.y") inits <- function(){ list(theta=3Drnorm(J, 0, 100), mu.theta=3Drnorm(1, 0, 100), sigma.theta=3Drunif(1, 0, 100)) } ## or alternatively something like: # inits <- list( # list(theta=3Drnorm(J, 0, 90), mu.theta=3Drnorm(1, 0, 90), # sigma.theta=3Drunif(1, 0, 90)), # list(theta=3Drnorm(J, 0, 100), mu.theta=3Drnorm(1, 0, 100), # sigma.theta=3Drunif(1, 0, 100)) # list(theta=3Drnorm(J, 0, 110), mu.theta=3Drnorm(1, 0, 110), # sigma.theta=3Drunif(1, 0, 110))) parameters <- c("mu.theta") ## Not run:=20 ## You may need to edit "bugs.directory", ## also you need write access in the working directory: schools.sim <- bugs(data, inits, parameters, model.file, n.chains=3D1, n.iter=3D5000, bugs.directory=3D"c:/Program Files/WinBUGS14/", working.directory=3DNULL, clearWD=3DTRUE, DIC =3D F) print(schools.sim) |