# [R] winbugs - R question

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

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)
}