Search code examples
rjags

jags: coda package, how to select multiple parameters


I used r2jags to run jags and do the sampling. Then, I used coda package to check convergence. As I have many subjects and many parameters, I would need to manually type them as the codes below. Are there any easier approaches that I can for example, choose gamma for every subject? Or, just select gamma from subject 1 to 10 without typing them manually?

codaSamples = as.mcmc.list(samples$BUGSoutput)

acfplot(codaSamples[,c('gamma[1]','gamma[2]','gamma[3]','gamma[4]','gamma[5]','gamma[6]',
                         'gamma[7]','gamma[8]','gamma[9]','gamma[10]','gamma[11]','gamma[12]',
                         'gamma[13]','gamma[14]','gamma[15]')],lag.max=1000)

Solution

  • A reproducible example would be nice but presumably

    cols <- sprintf("gamma[%d]",1:15); codaSamples[,cols]
    

    would do what you need? Or

    cols <- grep("^gamma",colnames(codaSamples)); codaSamples[,cols]