Learn R Programming

mcmcsae (version 0.7.6)

read_draws: Read MCMC draws from a file

Description

Read draws written to file by MCMCsim used with argument to.file.

Usage

read_draws(name, filename = paste0("MCdraws_", name, ".dat"))

Value

An object of class dc containing MCMC draws for a (vector) parameter.

Arguments

name

name of the parameter to load the corresponding file with posterior draws for.

filename

name of the file in which the draws are stored.

Examples

Run this code
if (FALSE) {
# NB this example creates a file "MCdraws_e_.RData" in the working directory
n <- 100
dat <- data.frame(x=runif(n), f=as.factor(sample(1:5, n, replace=TRUE)))
gd <- generate_data(~ reg(~ x + f, prior=pr_normal(precision=1), name="beta"), data=dat)
dat$y <- gd$y
sampler <- create_sampler(y ~ reg(~ x + f, name="beta"), data=dat)
# run the MCMC simulation and write draws of residuals to file:
sim <- MCMCsim(sampler, n.iter=500, to.file="e_")
summary(sim)
mcres <- read_draws("e_")
summary(mcres)
}

Run the code above in your browser using DataLab