[R] winbugs - R question

From: allan clark <allan_at_stats.uct.ac.za>
Date: Mon 09 Oct 2006 - 06:23:20 GMT

hi all

i would like to use r and winbugs in order to undertake seemingly unrelated regression. i am using the R2WINBUGS library. i just simulated a simple example (sample size is 25) in order to get the correct code.

i suspect that the problem is in my definition of the prior. it wants a multivariate node.

the example could be extended by including more than 1 X variable in the system of equations. how can one specify the following prior: the sum of the estimated betas (including the constant) is normal "a" and variance "b" say?

my code is given below:

library(R2WinBUGS)

set.seed(1)
x1=rnorm(25)
x2=rnorm(25)

n=25

#i know that the systems are not related but this will be extended later. y1=2+5*x1+rnorm(25)*2
y2=25-7*x2+rnorm(25)*2

X1=cbind(1,x1)
X2=cbind(1,x2)
Y=cbind(y1,y2)
I=diag(2)

J=diag(2)*0.001
m=matrix(0,nrow=2,ncol=0)

init<-list(b=matrix(0,nrow=2,ncol=2),tau=1) inits<-list(init,init,init)
data<-c("n","Y","X1","X2","I","J","m")
parameters<-c("b","tau")

a<-bugs(data=data, inits=inits, parameters, model.file="c:/try/sur.txt", n.chains = 3, n.iter = 1000, bugs.directory = "c:/Program Files/WinBUGS14/", working.directory = "c:/try", clearWD = FALSE,codaPkg = FALSE,debug=T)

model
{

    for (i in 1:n)
{

        Y[i,1:2] ~ dmnorm(mu[i,],P[1:2,1:2])

          # means in separate time series
          mu[i,1] <- inprod(X1[i,],b[,1])
          mu[i,2] <- inprod(X2[i,],b[,2])
          P[1:2,1:2]<-tau*I[1:2,1:2]
     }

     # priors on regression coefficients
     for (i in 1:2)

{
for (j in 1:2) { b[i,j]<-dnorm(0,0.001) }

    }

    tau~dgamma(0.001,0.001)
}

thanking you in advance
/
allan



R-help@stat.math.ethz.ch 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 Mon Oct 09 16:27:47 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 09 Oct 2006 - 09:30:09 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.