Brandon Barry
Brandon Barry

Reputation: 61

Problem loading in data from R to OpenBUGS?

I am trying to construct a data set in R and then load that into OpenBUGS to perform some bayesian analysis but am having difficulties in loading the data in.

Here is my R code:

library(BRugs)
y <- c(16,9,10,13,19,20,18,17,35,55)
m <- c(74,99,58,70,122,77,104,129,308,119)
bugsData(list(y=y, n=m), file="Assignment1Q2.txt")

Which all works fine. Then I try to load this into OpenBUGS but when I click 'load data' after selecting the file I get an error saying that: "expected a number or an NA" at this point:

n=c(7.4...)

I'm confused by this, why would it be expecting a number there? I need to create a vector in R to store the information 'm' but then it tells me that is an error in OpenBUGS (but not an error for the y vector, which it accepts y=c(...) fine).

Can someone help?

Thanks!

Upvotes: 1

Views: 468

Answers (1)

Brandon Barry
Brandon Barry

Reputation: 61

Figured it out! The reason was that in my OpenBUGS code, I only told it that there was 1 value of n (so it wasn't expecting a vector of values of n) and just needed to fix that.

From:

for (i in 1:10){
  y[i] ~ dbin(p,n)
  }

To:

for (i in 1:10){
  y[i] ~ dbin(p,n[i])
  }

Upvotes: 1

Related Questions