Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)

I want to build a data set in R and after that 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...)

1 Answer

0 votes
by (108k points)

I think in your OpenBUGS code, 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])

  }

If you are a beginner and want to know more about R then do check out the R programming tutorial that will help you in learning R from scratch. 

Browse Categories

...