0

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.

coolsv
  • 781
  • 5
  • 16
  • I'm unclear about your statement that you have "10250 iterations, where each iteration is a vector of labels with different length". Is this a chain where each step has a different dimensionality, as in a reversible-jump MCMC? In my experience MCMC doesn't **typically** have a different set of values/labels at each step ... ?? – Ben Bolker Jan 03 '21 at 22:55
  • Yes exactly. It's a variable selection procedure. My chain has 10250 iterations/steps. I have 100 variables. At step 1, I have the vector (1,5,10,50), for example, meaning that the variables 1, 5, 10 and 50 were chosen. At step 2, I have the vector (1,5,10,50,55), meaning that the variables 1, 5, 10, 50 and 55 were chosen, and so on. The procedure is repeated 10250 times. My output is a list of 10250 elements where each element is the stored vector of variables. – coolsv Jan 03 '21 at 23:02
  • My goal is to do a convergence diagnostic with this output list. – coolsv Jan 03 '21 at 23:05
  • 1
    I'm not sure how you're doing this, but variable selection in MCMC is **significantly** more theoretically complex https://en.wikipedia.org/wiki/Reversible-jump_Markov_chain_Monte_Carlo . I've always been scared to try it ... If you've implemented this naively there's a fairly good chance that you've left something out (if you are an expert on MCMC in varying dimensions, ignore that comment ...) https://cran.r-project.org/web/packages/rjmcmc/index.html – Ben Bolker Jan 03 '21 at 23:24
  • 1
    yes I'm an expert :-) Thank you anyway :-) I'll try to figure out how I can solve my code problem :-/ – coolsv Jan 03 '21 at 23:27
  • Furthermore, I suspect that RJMCMC convergence diagnostics are a special case that aren't handled by coda ... https://www.jstor.org/stable/1390654 Maybe try `library(sos); findFn("reversible jump MCMC convergence")` ? – Ben Bolker Jan 03 '21 at 23:27
  • Yes, perhaps that's why I'm having this error... – coolsv Jan 03 '21 at 23:33
  • Google Scholar search suggests "Reversible jump MCMC Y Fan, SA Sisson - Handbook of Markov Chain Monte Carlo, 2011 "; there seems to be enough on Google Books that you can get a sense of what the issues are. Seems like Castelloe and Zimmerman 2002 is the latest thing, don't know if there's an existing R implementation? – Ben Bolker Jan 03 '21 at 23:33
  • What a pity..... :-( I'll check your suggestion – coolsv Jan 03 '21 at 23:35

0 Answers0