Learn R Programming

statnet.common (version 4.10.0)

mcmc-utilities: Utility operations for mcmc.list objects

Description

colMeans.mcmc.list is a "method" for (non-generic) colMeans() applicable to mcmc.list objects.

var.mcmc.list is a "method" for (non-generic) var() applicable to mcmc.list objects. Since MCMC chains are assumed to all be sampling from the same underlying distribution, their pooled mean is used.

sweep.mcmc.list is a "method" for (non-generic) sweep() applicable to mcmc.list objects.

lapply.mcmc.list is a "method" for (non-generic) lapply() applicable to mcmc.list objects.

Usage

colMeans.mcmc.list(x, ...)

var.mcmc.list(x, ...)

sweep.mcmc.list(x, STATS, FUN = "-", check.margin = TRUE, ...)

lapply.mcmc.list(X, FUN, ...)

Value

colMeans.mcmc returns a vector with length equal to the number of mcmc chains in x with the mean value for each chain.

sweep.mcmc.list returns an appropriately modified version of x

lapply.mcmc.list returns an mcmc.list each of whose chains had been passed through FUN.

Arguments

x

a mcmc.list object.

...

additional arguments to the functions evaluated on each chain.

STATS, FUN, check.margin

See help for sweep().

X

An mcmc.list object.

Details

These implementations should be equivalent (within numerical error) to the same function being called on as.matrix(x), while avoiding construction of the large matrix.

See Also

Examples

Run this code
data(line, package="coda")
colMeans(as.matrix(line)) # also coda
colMeans.mcmc.list(line) # "Method"
# \dontshow{
stopifnot(isTRUE(all.equal(colMeans(as.matrix(line)),colMeans.mcmc.list(line))))
# }
data(line, package="coda")
var(as.matrix(line)) # coda
var.mcmc.list(line) # "Method"
# \dontshow{
stopifnot(isTRUE(all.equal(var.mcmc.list(line), var(as.matrix(line)))))
# }
data(line, package="coda")
colMeans.mcmc.list(line)-1:3
colMeans.mcmc.list(sweep.mcmc.list(line, 1:3))
# \dontshow{
stopifnot(isTRUE(all.equal(colMeans.mcmc.list(sweep.mcmc.list(line, 1:3)), colMeans.mcmc.list(line)-1:3)))
# }
data(line, package="coda")
colMeans.mcmc.list(line)[c(2,3,1)]
colMeans.mcmc.list(lapply.mcmc.list(line, `[`,,c(2,3,1)))
# \dontshow{
stopifnot(isTRUE(all.equal(colMeans.mcmc.list(line)[c(2,3,1)],colMeans.mcmc.list(lapply.mcmc.list(line, `[`,,c(2,3,1))))))
# }

Run the code above in your browser using DataLab