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.
Not an answer, but this blog post has the following wrapper function for converting coda output (.txt) to BUGS using R2WinBUGS:::bugs.sims:
This is not a solution to your question, but in response to your comment on @andybega's answer, here's a way to convert an
mcmc.list
object to typical coda text files.I do not know whether this will give you what you want. Note that the
model
code came from using your code and then typingLINE
at 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 = 1
used as an initial value. Perhaps that would be better.In effect, I created an
rjags
object using the samemodel
code you were using and added ajags
statement to run it. I admit that is not the same thing as converting coda output to abugs
object, but it might result in you getting the desiredplot
.If all you have is an
mcmc.list
and nomodel
code 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.