0

I used R dump() to create a data.txt file as specified by the latest JAGS manual, but I keep running into this error:

Reading data file data.txt
syntax error, unexpected LIST, expecting DOUBLE or NA or ASINTEGER or 'c'

The data.txt produced by dump(), from which I have removed the "L" assigned by R:

M <- 4
N <- 2
x <- structure(list(Var1 = c(0, 1, 0, 1), Var2 = c(0, 0, 1, 1)), .Names = c("Var1",
"Var2"), out.attrs = structure(list(dim = c(2, 2), dimnames = structure(list(
    Var1 = c("Var1=0", "Var1=1"), Var2 = c("Var2=0", "Var2=1"
    )), .Names = c("Var1", "Var2"))), .Names = c("dim", "dimnames"
)), class = "data.frame", row.names = c(NA, -4))
counts <- c(377558, 1001, 2000, 2000)
total <- 382559

If I remove x, the data will import correctly, but obviously that is not what I want. The strangest part is that if using the RJAGS and R2JAGS packages instead, the whole thing works fine. Does anyone know how to format this data to work in JAGS?

oiiio
  • 179
  • 1
  • 1
  • 8

2 Answers2

1

As Martyn said over on the JAGS forum, a list (or data.frame) is not allowed in JAGS. You need to convert this to an array or matrix before using dump.

By the way, if you need to call JAGS externally then you might also want to check out the runjags package (on CRAN) which does a lot of the automation of creating files to call JAGS (try run.jags(..., method='interruptible', keep.jags.files='my_folder') for example). You will still need to convert your data frame to a matrix first though.

Matt

Matt Denwood
  • 2,537
  • 1
  • 12
  • 16
  • I'm actually trying to make a system call to JAGS instead of using R2JAGS in my Rscript (this sounds really strange I know). I'll take a look at runjags for this – oiiio Jan 20 '16 at 19:11
  • Not strange at all - there are some situations where an external JAGS call is preferable to using the direct rjags interface (which R2JAGS is one wrapper for). The runjags package has the ability to switch between both. – Matt Denwood Jan 21 '16 at 15:03
1

What seemed to fix this issue for me was a simple command per Martyn's suggestion on the JAGS board:

x <- as.matrix(x)
oiiio
  • 179
  • 1
  • 1
  • 8