[R] Help R2WinBUGS
TTsai
t.tsai at wustl.edu
Thu Dec 3 05:38:32 CET 2009
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.
More information about the R-help
mailing list