I am using the rjags R library. The function coda.samples produces an mcmc.list, for example (from example(coda.samples)):
library(rjags)
data(LINE)
LINE$recompile()
LINE.out <- coda.samples(LINE, c("alpha","beta","sigma"), n.iter=1000)
class(LINE.out)
[1] "mcmc.list"
However, I would like to use the plot.bugs function, which requires a bugs object as input.
Is it possible to convert an object from an mcmc.list to a bugs object, so that plot.bugs(LINE.out)?
Note that there is a similar question on stats.SE that has been unanswered for over a month. That question had a bounty that ended on 08/29/2012.
More hints:
I have discovered that the R2WinBUGS package has a function "as.bugs.array" function - but it is not clear how the function can be applied to an mcmc.list.
I do not know whether this will give you what you want. Note that the
modelcode came from using your code and then typingLINEat the cursor. The rest is just standard bugs code, except I usedtau = rgamma(1,1)for an initial value and do not know how standard that is. More than once I have seentau = 1used as an initial value. Perhaps that would be better.In effect, I created an
rjagsobject using the samemodelcode you were using and added ajagsstatement to run it. I admit that is not the same thing as converting coda output to abugsobject, but it might result in you getting the desiredplot.If all you have is an
mcmc.listand nomodelcode and you simply want to plot themcmc.list, then my answer will not help.EDIT:
Based on the comments perhaps something like this will help. The line
str(new.data)suggests that a large amount of data are available. If you are simply trying to create variations of default plots then doing so may only be a matter of extracting and subsetting the data as desired. Hereplot(new.data$sims.list$P1)is just one straight-forward example. Without knowing exactly what plot you want I will not attempt more specific data extractions. If you post a figure showing an example of the exact kind of plot you want perhaps someone can take it from here and post the code needed to create it.By the way, I recommend reducing the size of the example data set to perhaps three chains and perhaps no more than 30 iterations until you have the exact code you want for the exact plot you want:
EDIT:
Note also that:
whereas:
which is what the title of your post requests.