[R] Help R2WinBUGS

From: TTsai <t.tsai_at_wustl.edu>
Date: Wed, 02 Dec 2009 20:38:32 -0800 (PST)

Hello,

I have problem running WinBUGS from R.
The following example works in WinBUGS but it does not work in R through package R2WinBUGS.
Does anyone know what the problem is?

x <- c(0.2, 1.1, 1, 2.2, 2.5, 2.9, 2.9, 3.6, 3.8, 0.6, 1, 2, 2.4, 2.6, 2.8, 3.2, 3.9, 3.5)

y <- c(0.5, 1.3, 0.1, 0.7, -0.4, 0.5, -0.9, -0.3, -0.3, 0.6, 0.4, 0.9, -0.1,
-0.4, -0.5, -0.2, 0.3, -1.5)
eco <- c(1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 1, 3, 2, 3, 2, 2, 2, 1)

N <- length(y)
J <- length(unique(eco))

f.data <- list("N", "y", "x", "eco", "J") f.inits <- function(){

               list(sigma.y=1, beta.0=1, beta.x=1, beta.eco=c(NA, 1, 1))} f.parameters <- c("beta.0", "beta.x", "sigma.y", "beta.eco")

f.ml <- bugs (data=f.data,

               inits=f.inits, 
               parameters.to.save=f.parameters, 
               model.file="oecd1.bug",              
               n.chains=3,                     
               n.iter=1000,                       
               debug=TRUE)


# This code works in WinBUGS.

model {
# dummy variable

  for (i in 1:N){
  D.eco2[i] <- equals(eco[i],2)
  D.eco3[i] <- equals(eco[i],3)
  }
# model's likelihood

  for (i in 1:N){                          
    y[i] ~ dnorm (mu[i], tau.y)      
    mu[i] <- beta.0 + beta.x*x[i] + beta.eco[2]*D.eco2[i] +
beta.eco[3]*D.eco3[i]      

  }
#

  beta.eco[1] <- 0   

# priors

   beta.0 ~ dnorm (0, 0.0001)
   beta.x ~ dnorm (0, 0.0001)    

   for (j in 2:J){
   beta.eco[j] ~ dnorm (0, 0.0001)
   }    

   tau.y <- pow(sigma.y, -2)         
   sigma.y ~ dunif (0, 100)           

}

DATA

list(N=18, J=3,
x = c(0.2, 1.1, 1, 2.2, 2.5, 2.9, 2.9, 3.6, 3.8, 0.6, 1, 2, 2.4, 2.6, 2.8,
3.2, 3.9, 3.5),
y = c(0.5, 1.3, 0.1, 0.7, -0.4, 0.5, -0.9, -0.3, -0.3, 0.6, 0.4, 0.9, -0.1,
-0.4, -0.5, -0.2, 0.3, -1.5),
eco = c(1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 1, 3, 2, 3, 2, 2, 2, 1) )

INITIAL VALUES
list(sigma.y=1, beta.0=1, beta.x=1, beta.eco=c(NA, 1, 1))

-- 
View this message in context: http://n4.nabble.com/Help-R2WinBUGS-tp947367p947367.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Thu 03 Dec 2009 - 06:51:49 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 05 Dec 2009 - 01:10:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive