I have been struggling to figure out how to identify which output the parameter came from. For e.g. in the following code I run the model for 2 iterations. At the end of it I obtain 2 outputs named bugs.output[[1]], bugs.output[[2]]
. Now when I type mean (p[,2])
it gives me the mean for p[2]
from the second output. How do I specify that I need the mean for p[2]
for the 1st
or the ith
output?
Here is how my output looks:
mean sd 2.5% 25% 50% 75% 97.5%
alpha 4.20338 1.14447 2.44975 3.39950 4.01550 4.82925 7.05405
p[1] 0.16691 0.04036 0.09974 0.13720 0.16445 0.19222 0.25308
p[2] 0.14286 0.03812 0.07665 0.11670 0.14020 0.16702 0.22630
p[3] 0.21238 0.04240 0.13740 0.18295 0.21050 0.23845 0.30360.......
And here is my code:
library("R2WinBUGS")
trial.data <- read.table("simuldatBB_6_30.csv", header=T)
p_true<- read.table("p_BB_6_30.csv",header=F)
bugs.output <- list()
for(i in 1:2){
nausea <- as.integer(trial.data[i,])
bugs.output[[i]] <- bugs(
data=list(nausea=nausea, N=63),
inits=list(
list(theta=.300,mu=3),
list(theta=.350, mu=3)
),
model.file="conj_nausea_script_2.txt",
parameters.to.save = c("alpha","p"),
n.chains=2, n.iter=12000, n.burnin=5000,
bugs.directory="E://AChaudhuri/winbugs14/WinBUGS14",
working.directory=NULL)
attach.bugs(bugs.output[[i]],overwrite=NA)}