I have used JAGS called via rjags to produce the mcmc.list object foldD_samples, which contains trace monitors for a large number of stochastic nodes (>800 nodes).
I would now like to use R to compute a fairly complicated, scalar-valued function of these nodes, and write the output to an mcmc object so that I can use coda to summarize the posterior and run convergence diagnostics.
However, I haven't been able to figure out how get the posterior draws from foldD_samples into a dataframe. Any help much appreciated.
Here is the structure of the mcmc.list:
str(foldD_samples)
List of 3
$ : mcmc [1:5000, 1:821] -0.667 -0.197 -0.302 -0.204 -0.394 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : NULL
.. ..$ : chr [1:821] "beta0" "beta1" "beta2" "dtau" ...
..- attr(*, "mcpar")= num [1:3] 4100 504000 100
$ : mcmc [1:5000, 1:821] -0.686 -0.385 -0.53 -0.457 -0.519 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : NULL
.. ..$ : chr [1:821] "beta0" "beta1" "beta2" "dtau" ...
..- attr(*, "mcpar")= num [1:3] 4100 504000 100
$ : mcmc [1:5000, 1:821] -0.492 -0.679 -0.299 -0.429 -0.421 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : NULL
.. ..$ : chr [1:821] "beta0" "beta1" "beta2" "dtau" ...
..- attr(*, "mcpar")= num [1:3] 4100 504000 100
- attr(*, "class")= chr "mcmc.list"
Cheers, Jacob
do.call(rbind.data.frame, foldD_samples)
. Perhaps fatser more efficient to usedata.table::rbindlist
– Synchroscopecode.samples
on the list, without coercing to a dataframe – Synchroscopedo.call(rbind.data.frame, foldD_samples)
worked well. I'd be happy to accept this as an answer if posted as such.data.table::rbindlist
doesn't accept mcmc.list objects as input. Also note the presumed typo "code" for "coda" in the postscript. – Sidewardrbindlist(lapply(foldD_samples,as.data.frame))
might work ... if the efficiency matters to you. – Belief