Learn R Programming

posterior (version 1.7.0)

extract_list_of_variable_arrays: Extract arrays of multiple variables

Description

Extract arrays of draws for multiple variables, returning them as a named list of arrays. Each array has the same structure as returned by extract_variable_array.

Usage

extract_list_of_variable_arrays(x, variables = NULL, ...)

# S3 method for default extract_list_of_variable_arrays(x, variables = NULL, ...)

# S3 method for draws extract_list_of_variable_arrays(x, variables = NULL, ...)

Value

A named list of arrays, where each array has dimension niterations(x) x nchains(x) x any remaining dimensions determined by the indices of the variable x

(if with_chains = TRUE) or dimension niterations(x) * nchains(x) x any remaining dimensions (if with_chains = FALSE).

Arguments

x

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

variables

A character vector of variable names to extract, or NULL to extract all variables. To extract all dimensions from variables with indices (e.g. "x[1]"), provide the base variable names (e.g. "x").

...

Arguments passed to individual methods (if applicable).

See Also

Other variable extraction methods: extract_variable(), extract_variable_array(), extract_variable_matrix()

Examples

Run this code
x <- example_draws(example = "multi_normal")

# Extract multiple variables at once
vars <- extract_list_of_variable_arrays(x, c("mu", "Sigma"))
str(vars)

# Extract all variables (uses base variable names)
all_vars <- extract_list_of_variable_arrays(x)
str(all_vars)

# Extract specific indexed variables
vars2 <- extract_list_of_variable_arrays(x, c("mu[1]", "mu[2]"))
str(vars2)

Run the code above in your browser using DataLab