Learn R Programming

posterior (version 1.6.0)

subset_draws: Subset draws objects

Description

Subset draws objects by variables, iterations, chains, and draws indices.

Usage

subset_draws(x, ...)

# S3 method for draws_matrix subset_draws( x, variable = NULL, iteration = NULL, chain = NULL, draw = NULL, regex = FALSE, unique = TRUE, exclude = FALSE, scalar = FALSE, ... )

# S3 method for draws_array subset_draws( x, variable = NULL, iteration = NULL, chain = NULL, draw = NULL, regex = FALSE, unique = TRUE, exclude = FALSE, scalar = FALSE, ... )

# S3 method for draws_df subset_draws( x, variable = NULL, iteration = NULL, chain = NULL, draw = NULL, regex = FALSE, unique = TRUE, exclude = FALSE, scalar = FALSE, ... )

# S3 method for draws_list subset_draws( x, variable = NULL, iteration = NULL, chain = NULL, draw = NULL, regex = FALSE, unique = TRUE, exclude = FALSE, scalar = FALSE, ... )

# S3 method for draws_rvars subset_draws( x, variable = NULL, iteration = NULL, chain = NULL, draw = NULL, regex = FALSE, unique = TRUE, exclude = FALSE, scalar = FALSE, ... )

# S3 method for rvar subset_draws(x, variable = NULL, ...)

# S3 method for draws subset(x, ...)

Value

A draws object of the same class as x.

Arguments

x

(draws) A draws object or another R object for which the method is defined.

...

Arguments passed to individual methods (if applicable).

variable

(character vector) The variables to select. All elements of non-scalar variables can be selected at once.

iteration

(integer vector) The iteration indices to select.

chain

(integer vector) The chain indices to select.

draw

(integer vector) The draw indices to be select. Subsetting draw indices will lead to an automatic merging of chains via merge_chains.

regex

(logical) Should variable should be treated as a (vector of) regular expressions? Any variable in x matching at least one of the regular expressions will be selected. Defaults to FALSE.

unique

(logical) Should duplicated selection of chains, iterations, or draws be allowed? If TRUE (the default) only unique chains, iterations, and draws are selected regardless of how often they appear in the respective selecting arguments.

exclude

(logical) Should the selected subset be excluded? If FALSE (the default) only the selected subset will be returned. If TRUE everything but the selected subset will be returned.

scalar

(logical) Should only scalar variables be selected? If FALSE (the default), all variables with matching names and arbitrary indices will be selected (see examples).

Details

To ensure that multiple consecutive subsetting operations work correctly, subset() repairs the draws object before and after subsetting.

Examples

Run this code
x <- example_draws()
subset_draws(x, variable = c("mu", "tau"))
subset_draws(x, chain = 2)
subset_draws(x, iteration = 5:10, chain = 3:4)

# extract the first chain twice
subset_draws(x, chain = c(1, 1), unique = FALSE)

# extract all elements of 'theta'
subset_draws(x, variable = "theta")

# trying to extract only a scalar 'theta' will fail
# subset_draws(x, variable = "theta", scalar = TRUE)

Run the code above in your browser using DataLab