Read in data from a set of MCMC runs

Share:

Description

Read in data from a set of MCMC runs and create an mcmc.list object.

Usage

1
2
3
4
read.mcmc( nc, sourcepattern, ...,
               col.names, start = 1, 
               end = nrow(tmp)/numComponents*thin, 
               thin = 1, numComponents=1)

Arguments

nc

Number of MCMC sampler files to read

sourcepattern

MCMC data file name pattern.

...

Arguments to be passed to read.table when loading MCMC sampler data.

col.names

Data file column names (optional)

start, end, thin

See documentation for mcmc

numComponents

Number of component samplers.

Details

This function reads in the states output from one or more MCMC samplers and creates a single mcmc.list object. sourcepattern will be used as a filename pattern with # replaced by the sampler number. EG, sourcepattern="MCMC.#.csv" will be converted to "MCMC.1.csv", "MCMC.2.csv", etc.

The function read.table is used to read in the data. Options for read.table may be included as part of the call to read.mcmc.

The start, end, and thin arguments can be used to annotate the MCMC samplers with additional information.

Value

An mcmc.list object containing nc component mcmc objects.

Author(s)

Gregory R. Warnes greg@warnes.net

See Also

mcmc, mcmc.list, read.table

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# this is a totally useless example, but it does exercise the code
for(i in 1:20){
  x <- matrix(rnorm(1000),ncol=4)
  x[,4] <- x[,4] + 1/3 * (x[,1] + x[,2] + x[,3])
  colnames(x) <- c("alpha","beta","gamma", "nu")
  write.table(x, file=paste("mcmc",i,"csv",sep="."), sep=",",
                 row.names=FALSE)
}

data <- read.mcmc(20, "mcmc.#.csv", sep=",")

# a pedantic example
write.table(cbind(rnorm(700,10,2),rnorm(700,3,1),rnorm(700,8,1),
      rnorm(700,11,2)),file="dnzcY3e.1",row.names=FALSE)
write.table(cbind(rnorm(700,10,2),rnorm(700,3,1),rnorm(700,8,1),
      rnorm(700,11,2)),file="dnzcY3e.2",row.names=FALSE)
write.table(cbind(rnorm(700,10,2),rnorm(700,3,1),rnorm(700,8,1),
      rnorm(700,11,2)),file="dnzcY3e.3",row.names=FALSE)

output<-read.mcmc(3,"dnzcY3e.#") 
mcgibbsit(output)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.