post_bind: Combine two objects containing posterior samples

View source: R/post_bind.R

post_bindR Documentation

Combine two objects containing posterior samples

Description

Intended for use when derived quantities are calculated from monitored posterior samples, and you wish to combine them into the master mcmc.list, as though they were calculated and monitored during MCMC sampling. It is not advised to combine samples from two MCMC runs, because covariance of MCMC sampling would be lost.

Usage

post_bind(post1, post2, dup_id = "_p2")

Arguments

post1

A mcmc.list or matrix object.

post2

A mcmc.list or matrix object.

dup_id

If any node names are duplicated in post2, what should be appended to the end of these node names in the output? If this occurs a warning will be returned. Defaults to "_p2"

Details

Some important things to note:

  • If the object passed to post1 is a matrix, post2 must be a mcmc.list, and vice versa.

  • That is, two mcmc.list objects are allowed, but not two matrix objects.

  • For matrix objects, nodes should be stored as columns and samples should be stored as rows. Column names should be present.

  • The objects passed to post1 and post2 must have the same number of chains, iterations, burnin, and thinning interval.

  • If the node names are empty (e.g., missing column names in a matrix), the node names will be coerced to "var1", "var2", etc. and a warning will be returned.

Value

A single mcmc.list object containing samples of the nodes from both post1 and post2.

Examples

# load example mcmc.list
data(cjs)

# create two subsets from cjs: one as mcmc.list and one as matrix
# also works if both are mcmc.list objects
p1 = post_subset(cjs, "b0")
p2 = post_subset(cjs, "b1", matrix = TRUE)

# combine them into one mcmc.list
head(post_bind(p1, p2))

postpack documentation built on Dec. 28, 2022, 1:23 a.m.