# [R] BRugs

flipha23 neungsoo.ha at gmail.com
Mon Apr 19 06:04:40 CEST 2010

```Hi. I am new here, and I am writing this Winbugs code with BRugs.
n=length(bi.bmi)
Lagegp=13
Lgen=2
Lrace=5
Lstra=15
Lpsu=2
#model gen x race
bi.bmi.model=function(){
# likelihood
for (i in 1:n){
bi.bmi[i]~ dbern(p[i])
logit(p[i])<- a0 + a1[agegp[i]]+a2[gen[i]]+a3[race[i]]
+ a12[agegp[i], gen[i]]
+ gam[stra[i]]+ u[psu[i],stra[i]]		}
# constraints for a1, a2, a3, a12
a1[1]<-0.0
a2[1]<-0.0
a3[1]<-0.0
a12[1,1]<-0.0
#
for(k in 2:Lgen){ a12[1,k]<-0.0}
for(j in 2:13){ a12[j,1]<-0.0}

# priors
a0~ dnorm(0.0, 1.0E-4)
for(i in 2:13){a1[i]~dnorm(0.0, 1.0E-4)}
for(j in 2:Lgen){ a2[j]~ dnorm(0.0, 1.0E-4)}
for(k in 2:Lrace){ a3[k]~ dnorm(0.0, 1.0E-4)}

for(i in 2:Lagegp){
for(j in 2:Lgen){
a12[i,j]~ dnorm(0.0, 1.0E-4)
}}
for(i in 1:Lstra){gam[i]~dunif(0, 1000)}
for( i in 1:Lpsu){
for(j in 1:Lstra){
u[i,j]~ dnorm(0.0, tau.u)
}}
tau.u<-pow(sigma.u, -2)
sigma.u~ dunif(0.0,100)
}

library(BRugs)
writeModel(bi.bmi.model, con='bi.bmi.model2.txt')
bi.bmi.model.data=list('n', 'Lagegp','Lgen', 'Lrace', 'Lstra', 'Lpsu',
'stra', 'psu','bi.bmi','agegp', 'gen', 'race')
bi.bmi.model.init=function(){
list( sigma.u=runif(1),
a0<-rnorm(1),
a1<-c(NA,rep(0, 12)),
a2<-c(NA, rep(0, Lgen-1)),
a3<-c(NA, rep(0, Lrace-1)),
a12<-matrix( c(rep(NA, 13), NA,rep(0, 12)), ncol=2),

gam<-rep(1,Lstra), u<-matrix(rep(0, 30), nrow=2)	)
}
bi.bmi.model.parameters=c( 'a0', 'a1', 'a2', 'a3',  'a12')
bi.bmi.model.bugs=BRugsFit(modelFile='bi.bmi.model2.txt',
data=bi.bmi.model.data,
inits=bi.bmi.model.init,
numChains=1,
para=bi.bmi.model.parameters,
nBurnin=20, nIter=40)

When I run this I get this message.
model is syntactically correct
array index is greater than array upper bound for a1
[1] "C:\\DOCUME~1\\Owner\\LOCALS~1\\Temp\\RtmpNvSdyb/inits1.txt"
Initializing chain 1: model must be compiled before initial values loaded
model must be initialized before updating
model must be initialized before DIC an be monitored
Error in samplesSet(parametersToSave) :
model must be initialized before monitors used

I checked the main effects alone, and it works fine, so I don't really
understand why it's saying, "array index is greater than array upper bound
for a1."
Anyone who could help me with this would be greatly appreciated.
Thanks.

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

```