# Clear previous work rm(list = ls()) # Enter O-ring Data y=c(1,1,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,1,0,0,0,0,0) tau=c(53,57,58,63,66,67,67,67,68,69,70,70,70,70,72, 73,75,75,76,76,78,79,81) # Call the R2OpenBUGS library. # Set paths so that R2OpenBUGS can find and store # the files it needs, including the model file Oring.txt # and where you have stored OpenBUGS on your computer. library(R2OpenBUGS) BUGS_path <- "c:\\Program Files (x86)\\OpenBUGS\\OpenBUGS323\\OpenBUGS.exe" setwd("c:\\E-drive\\Books\\LOGLIN3\\BAYES\\") myworking_dir <- "c:\\E-drive\\Books\\LOGLIN3\\BAYES\\" # Define the McMC sample characteristics. # This code gives (we hope) 10,000 nonindependent # observations from the posterior distribution. iterates <- 10000 burn_in <- 1000 # Identify the data data <- list( "y", "tau") # Identify the parameters parameters <- list("beta") # Identify parameter initial values in a list of lists. inits <- list(list(beta=c(0,0))) # The program is designed to run more than one McMC chain. # This is a list of lists to allow different initial # values for different chains. # Easier than the list of lists is to generate # initial values via a function. inits <- function () { list(beta = c(0,0)) } # It would be redundant to run both inits <- commands # Putting all the pieces together: Oring <- bugs( data, inits, parameters, model.file= "c:\\E-drive\\Books\\LOGLIN3\\BAYES\\Oring.txt", n.chains=1, n.iter=iterates+burn_in, n.thin=1, n.burnin=burn_in, OpenBUGS.pgm=BUGS_path, working.directory=myworking_dir, debug=F ) Oring$summary # The following command tells you what info # is contained in Oring summary(Oring) # For example Oring$mean Oring$sd Oring$median \end{verbatim} Rather than defining \texttt{y} and \texttt{tau} separately you could also write the \texttt{data} statement as \begin{verbatim} data <- list( y=c(1,1,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,1,0,0,0,0,0), tau=c(53,57,58,63,66,67,67,67,68,69,70,70,70,70,72, 73,75,75,76,76,78,79,81) )