From: Uwe L. <li...@st...> - 2007-10-03 17:36:45
|
I think this was proposed by Andrew Gelman in the original code and I already had the discussion but forgot the outcome (people would like to have it randomized?, Andrew?). Anyway, a fix would be to add drop = FALSE as in sims <- sims [sample(n.sims), , drop = FALSE] # scramble (for convenience in analysis) Best wishes, Uwe Dawn Woodard wrote: > 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. > > 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=rnorm(J, 0, 100), mu.theta=rnorm(1, 0, 100), > sigma.theta=runif(1, 0, 100)) > } > ## or alternatively something like: > # inits <- list( > # list(theta=rnorm(J, 0, 90), mu.theta=rnorm(1, 0, 90), > # sigma.theta=runif(1, 0, 90)), > # list(theta=rnorm(J, 0, 100), mu.theta=rnorm(1, 0, 100), > # sigma.theta=runif(1, 0, 100)) > # list(theta=rnorm(J, 0, 110), mu.theta=rnorm(1, 0, 110), > # sigma.theta=runif(1, 0, 110))) > > parameters <- c("mu.theta") > > ## Not run: > ## 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=1, n.iter=5000, > bugs.directory="c:/Program Files/WinBUGS14/", > working.directory=NULL, clearWD=TRUE, DIC = F) > print(schools.sim) > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Bugs-r-devel mailing list > Bug...@li... > https://lists.sourceforge.net/lists/listinfo/bugs-r-devel |