Skip to content

importing data from BUGS format to R?

4 messages · Jeffrey Moore, Gabor Grothendieck, Uwe Ligges +1 more

#
Just source the file:

source("mywinbugsfile.R")
head(y)
On 2/23/06, Jeffrey Moore <jemoore at duke.edu> wrote:
#
Gabor Grothendieck wrote:
... and don't forget to transpose the matrix afterwards, if this was 
BUGS code.

Uwe Ligges
#
On Fri, 2006-02-24 at 08:48 +0100, Uwe Ligges wrote:
If this were a WinBUGS data file (or initial values file), the whole
expression would be wrapped in a call to list(). In this case, you would
need to assign the output from source(), or use the dget() function,
e.g. for the EPILEPSY example:
[1] "N"    "T"    "y"    "Trt"  "Base" "Age"  "V4"
[1] 4

But, as Uwe points out, arrays will need to be reorganized, as WinBUGS
fills matrices by row rather than column.
[,1] [,2] [,3] [,4]
[1,]    5    9    9    7
[2,]    3   11    4    6
[3,]    3    0    0    7
[4,]    3    0    4    1
[5,]    3    5    3    1
[6,]    5    0    0    2

I wrote a function called "bugs2jags", which you will find in the coda
package, for converting WinBUGS data files into the data format used by
JAGS which is, by no coincidence, the format used by the R function
dump().
Loading required package: lattice
[1] "Age"  "Base" "N"    "T"    "Trt"  "V4"   "y"

This creates objects in your work space, and sorts out the arrays
[,1] [,2] [,3] [,4]
[1,]    5    3    3    3
[2,]    3    5    3    3
[3,]    2    4    0    5
[4,]    4    4    1    4
[5,]    7   18    9   21
[6,]    5    2    8    7

Martyn
-----------------------------------------------------------------------
This message and its attachments are strictly confidential. ...{{dropped}}