[R] R2WinBUGS problem
Uwe Ligges
ligges at statistik.tu-dortmund.de
Fri Jul 25 19:44:11 CEST 2008
Dear Troels,
it is possible to start without inits if the problem to solve is
appropriate, here is the changed "schools" example from the help page:
model.file <- system.file(package="R2WinBUGS", "model", "schools.txt")
data(schools)
J <- nrow(schools)
y <- schools$estimate
sigma.y <- schools$sd
data <- list ("J", "y", "sigma.y")
parameters <- c("theta", "mu.theta", "sigma.theta")
schools.sim <- bugs(data, inits = NULL, parameters, model.file,
n.chains=3, n.iter=5000,
bugs.directory="c:/Program Files/WinBUGS14/",
working.directory=NULL, clearWD=TRUE)
print(schools.sim)
plot(schools.sim)
which means you have to specify "inits=NULL" in the bugs() call.
If it still does not work for you, please send me the data, I cannot
reproduce anything otherwise.
Best wishes,
uwe
Troels Ring wrote:
> Dear friends - I'm on winXP, R 2.71 - I have with some help dveloped
> this multivariate normal model, which gives very plausible results in
> WinBUGS even without any
> initial values specified. However, when I then try to run the same model
> via the bugs function in R2WinBUGS with inits specified as inits=NULL
> the program stops in a dead end. So I have tried to make inits for the
> bugs function as shown below. But then WinBUGS come to a halt while
> these inits are being handled so they are seemingly wrong. This is a bit
> annoying and I would like to know how I managed to corrupt the inits.
> This is sent both to WinBUGS and R with hope and some anxiety.
> Best wishes
> Troels
>
>
> cat("
> model {
> for (i in 1:126) {
> dep[i] ~ dnorm(mu.dep[i],tau.dep)
> mu.dep[i] <- alpha[ID[i]]*NAK.cor[i]+beta[ID[i]]*TBW.cor[i]
> fit[i] <- mu.dep[i]+CONST[i]
> }
> tau.dep <- pow(sigma_dep,-2)
> sigma_dep ~ dunif(0,100)
> for (j in 1:16) {
> alpha[lev[j]] <- AB[lev[j],1]
> beta[lev[j]] <- AB[lev[j],2]
> AB[lev[j],1:2] ~ dmnorm(AB.hat[lev[j],],tau.AB[,])I(lower[],
> upper[])
> AB.hat[lev[j],1] <- mu.alpha
> AB.hat[lev[j],2] <- mu.beta
> }
> lower[1] <- 0
> lower[2] <- -100
> upper[1] <- 100
> upper[2] <- 0
>
> mu.alpha ~ dnorm(0,0.0001)
> mu.beta ~ dnorm(0,0.0001)
>
> tau.AB[1:2,1:2] <- inverse(sigma.AB[,])
> sigma.AB[1,1] <- pow(sigma.alpha,2)
> sigma.alpha ~ dunif(0,100)
> sigma.AB[2,2] <- pow(sigma.beta,2)
> sigma.beta ~ dunif(0,100)
> sigma.AB[1,2] <- rho*sigma.alpha*sigma.beta
> sigma.AB[2,1] <- sigma.AB[1,2]
> rho ~ dunif(-1,1)
> }",
> file="ml3_pig.bug")
> pigs3.inits <- function () {
> list (AB=array(c(runif(16,0,10),runif(16,-30,0)),c(16,2)),
> mu.alpha=runif(1,0,10), mu.beta=runif(1,-30,0),
> sigma.dep=runif(1), sigma.alpha=runif(1), sigma.beta=runif(1),
> rho=runif(1))
> }
>
>
> pigs.parameters <- c ("mu.alpha", "mu.beta", "sigma_dep","alpha","beta",
> "fit","deviance","rho")
>
> pigs3 <- bugs (ml_pig.data, debug=TRUE,inits=pigs3.inits,
> pigs.parameters, "ml3_pig.bug", n.iter=2000,n.chains=3,
> bugs.directory = bugs.directory)
>
More information about the R-help
mailing list