Learn R Programming

tidybayes (version 0.12.1.9000)

combine_chains: Combine the chain and iteration columns of tidy samples

Description

Combines the chain and iteration columns of a tidy data frame of samples from a Bayesian model fit by renumbering iterations to ensure that the iteration column alone can uniquely identify each draw. Can be useful for making plots showing multiple iterations where you do not care about differences among chains.

Usage

combine_chains(samples, chain = .chain, iteration = .iteration,
  into = NULL)

Arguments

samples

Tidy data frame of samples with columns representing the chain and iteration of each sample, such as returned by as_sample_tibble, spread_samples, or gather_samples.

chain

Bare name of column in samples indicating the chain of each row. The default (.chain) is the same as returned by other functions in tidybayes.

iteration

Bare name of column in samples indicating the iteration of each row. The default (.iteration) is the same as returned by other functions in tidybayes.

into

Name (as a character vector) of the column to combine chains into. The default, NULL, replaces the chain column with NAs and writes the combined chain iteration numbers into iteration. If provided, chain and iteration will not be modified, and the combined iteration number will be written into a new column named into.

Value

A data frame of tidy samples with a combined iteration column

See Also

emmeans

Examples

Run this code
# NOT RUN {
library(magrittr)
library(coda)

data(line, package = "coda")

# The `line` posterior has two chains with 200 iterations each:
line %>%
  as_sample_tibble() %>%
  summary()

# combine_chains combines the chains, giving 400 iterations with
# `.chain = NA` (to indicate that the chains were combined, as opposed to
# this being 400 iterations from one chain).
line %>%
  as_sample_tibble() %>%
  combine_chains() %>%
  summary()

# }

Run the code above in your browser using DataLab