| read.mcmc | R Documentation |
Read in data from a set of MCMC runs and create an mcmc.list object.
read.mcmc(
nc,
sourcepattern,
...,
col.names,
start = 1,
end = nrow(tmp)/numComponents * thin,
thin = 1,
numComponents = 1
)
nc |
Number of MCMC sampler files to read |
sourcepattern |
MCMC data file name pattern. |
... |
Arguments to be passed to |
col.names |
Data file column names (optional) |
start, end, thin |
See documentation for |
numComponents |
Number of component samplers. |
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.
An mcmc.list object containing nc component mcmc
objects.
Gregory R. Warnes greg@warnes.net
mcmc, mcmc.list,
read.table
###
# Create example data files for 20 independent chains
# with serial correlation of 0.
###
set.seed(42)
tmpdir <- tempdir()
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 = file.path(
tmpdir,
paste("mcmc", i, "csv", sep=".")
),
sep = ",",
row.names=FALSE
)
}
# Read them back in as an mcmc.list object
data <- read.mcmc(20, file.path(tmpdir, "mcmc.#.csv"), sep=",")
summary(data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.