I have a Markov chain consisting of 10250 iterations, where each iteration is a vector of labels with different length. I stored the chain in a list, because I don't have the same number of columns at each iteration to make it as a data.frame
, say
chain<-rep(list(0),10250)
for (i in 1:length(chain)) {
n<-sample(1:100)
chain[[i]]<-sample(1:100,n)
}
I'd like to perform the diagnostics of chain
with the coda
package in R. I have a R code for a chain consisting of a single value at each iteration. This code works and the chain is stored in an object I called Lambdas
:
library(coda)
head(Lambdas)
Lambda.Penalty
1 0.349101
2 0.349101
3 0.349101
4 0.349101
5 0.349101
6 0.349101
obj.mcmc<-as.mcmc(Lambdas)
head(obj.mcmc )
Markov Chain Monte Carlo (MCMC) output:
Start = 1
End = 7
Thinning interval = 1
Lambda.Penalty
1 0.349101
2 0.349101
3 0.349101
4 0.349101
5 0.349101
6 0.349101
7 0.349101
obj.trace <- mcmc(obj.mcmc)
summary(obj.trace)
plot(obj.trace)
autocorr.plot(obj.trace)
How can I apply this code to my chain
object, so that it is recognized as a chain with 10250 iterations? When I try the first command obj.mcmc<-as.mcmc(chain)
, I get the following error: Error in mcmc.list(x) : Arguments must be mcmc objects
. I do not have this error with the object Lambdas
.