[R-sig-eco] Bayesian Methods for Ecology: inits working with WinBUGS not working with R & R2WinBUGS

Guillaume Chapron carnivorescience at gmail.com
Mon Dec 29 18:11:15 CET 2008


Hello,

The issue raised in my yesterday email is now solved. Philip Dixon  
emailed a suggestion to me first and I tested it and it works.  
Hereafter, you will find explanations, they are probably of interest  
to people switching between R and WinBUGS.

-- 

Remember that R and (Win)BUGS store matrices (and arrays) in
different order.  In BUGS, you specify values going across the rows.
In R, you specify values going down the columns.  If you have a
reasonable matrix in R format, R2WinBUGS takes care of the ordering by
transposing the matrix before passing it to WinBUGS.

I suggest you print out your data and init matrices in R and check
that they are in the order you intend.  If they are in the wrong
order, your NA's will NOT be where you intended, which explains the
'some variables uninitialized' message.

--

So when pasting into R some WinBUGS code, it is important to remember  
this ordering issue. What I did is replacing this

N = structure(.Data = c(32, 28, 29, 39, 20, 24, 22, 35, 20, 36, 34,  
40, 25, 25, 24, 24, 28, 15, 30, 36, 27, 31, 20, NA,7, 11, 8, 14, 11,  
5, 12, 6, 10, 12, 19, NA, 12, 16, 8, 8, 16, 11, 10, 6, 4, 10, 12,  
NA),.Dim = c(4, 12))

with this

N = matrix(c(32, 28, 29, 39, 20, 24, 22, 35, 20, 36, 34, 40, 25, 25,  
24, 24, 28, 15, 30, 36, 27, 31, 20, NA,7, 11, 8, 14, 11, 5, 12, 6, 10,  
12, 19, NA, 12, 16, 8, 8, 16, 11, 10, 6, 4, 10, 12, NA), nrow = 4,  
ncol = 12, byrow = T)

Cheers

Guillaume



More information about the R-sig-ecology mailing list